Skip to content

Commit

Permalink
Merge pull request #553 from yilmazbekdemir/issue-547
Browse files Browse the repository at this point in the history
fill uid field of UserSocialAuth model
  • Loading branch information
Rafael Muñoz Cárdenas authored Sep 11, 2018
2 parents a0207ec + 31a996f commit cccdaa9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions silo/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions silo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from collections import OrderedDict
from requests.auth import HTTPDigestAuth
import tempfile
import uuid

from pymongo import MongoClient

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit cccdaa9

Please sign in to comment.