From 31a996fcfe0cd0c99884dfa2171381eb9d7f9800 Mon Sep 17 00:00:00 2001 From: yilmazbekdemir Date: Tue, 11 Sep 2018 11:45:11 +0200 Subject: [PATCH] fill uid field of UserSocialAuth model --- silo/tests/test_views.py | 31 +++++++++++++++++++++++++++++++ silo/views.py | 2 ++ 2 files changed, 33 insertions(+) diff --git a/silo/tests/test_views.py b/silo/tests/test_views.py index 25b8253..46d08fe 100644 --- a/silo/tests/test_views.py +++ b/silo/tests/test_views.py @@ -1050,6 +1050,37 @@ def test_new_read_post_fails_no_file(self): self.assertIn('Invalid Form', messages) + def test_new_read_post_creates_uuid(self): + """ + POST for onedrive should create uuid for UserSocialAuth, otherwise + unique_together will not be unique. + """ + read_type = ReadType.objects.get(read_type="OneDrive") + + params = { + 'owner': self.tola_user.user.pk, + 'type': read_type.pk, + 'read_name': 'TEST READ ONEDRIVE', + 'description': 'TEST DESCRIPTION for test read source', + 'onedrive_file': 'TEST10000100', + 'onedrive_access_token': 'TEST_DUMMY_TOKEN', + 'create_date': '2018-01-26 12:33:00', + } + request = self.factory.post(self.new_read_url, data=params) + request.user = self.tola_user.user + + response = views.showRead(request, 0) + + self.assertEqual(response.status_code, 302) + self.assertEqual(response.url, '/import_onedrive/1/') + + # check for social auth updated + + social_auth = UserSocialAuth.objects.get(user=self.tola_user.user, + provider='microsoft-graph') + + self.assertNotEqual(social_auth.uid, '') + class SiloDetailViewTest(TestCase): def setUp(self): diff --git a/silo/views.py b/silo/views.py index e943389..76e4c8e 100644 --- a/silo/views.py +++ b/silo/views.py @@ -9,6 +9,7 @@ from collections import OrderedDict from requests.auth import HTTPDigestAuth import tempfile +import uuid from pymongo import MongoClient @@ -792,6 +793,7 @@ def showRead(request, id): social_auth, created = UserSocialAuth.objects.get_or_create( provider='microsoft-graph', user=request.user) social_auth.extra_data = extra_data + social_auth.uid = str(uuid.uuid4()) social_auth.save() return HttpResponseRedirect("/import_onedrive/" + str(