From: Bryan Date: Sat, 21 Dec 2013 00:02:42 +0000 (-0500) Subject: removing DriveAuth step 1 of 2: removing code X-Git-Tag: release-20150131~375 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=00419caa9fbf68ec5c84663aa8ed1cb44e70b4cc;p=oweals%2Fkarmaworld.git removing DriveAuth step 1 of 2: removing code --- diff --git a/karmaworld/apps/document_upload/tests.py b/karmaworld/apps/document_upload/tests.py index 0beba9f..cb4d13e 100644 --- a/karmaworld/apps/document_upload/tests.py +++ b/karmaworld/apps/document_upload/tests.py @@ -27,16 +27,6 @@ class ConversionTest(TestCase): self.course = Course(name='Intro to Advanced Study', school=self.school) self.course.save() self.client = Client() - self.setUpGDriveAuth() - - def setUpGDriveAuth(self): - try: - f = open(CREDENTIALS_PATH) - except IOError: - raise RuntimeError("Could not find {c}, did you create it? See docs/source/gdrive.rst".format(c=CREDENTIALS_PATH)) - creds_str = f.read() - f.close() - DriveAuth(credentials=creds_str).save() def doConversionForPost(self, post): self.assertEqual(Note.objects.count(), 0) diff --git a/karmaworld/apps/notes/admin.py b/karmaworld/apps/notes/admin.py index 91eab81..ff4c6ee 100644 --- a/karmaworld/apps/notes/admin.py +++ b/karmaworld/apps/notes/admin.py @@ -5,7 +5,6 @@ from django.contrib import admin -from karmaworld.apps.notes.models import DriveAuth from karmaworld.apps.notes.models import Note class NoteAdmin(admin.ModelAdmin): @@ -16,5 +15,4 @@ class NoteAdmin(admin.ModelAdmin): 'fk': ['course'] } -admin.site.register(DriveAuth) admin.site.register(Note, NoteAdmin) diff --git a/karmaworld/apps/notes/models.py b/karmaworld/apps/notes/models.py index 342defd..b56e719 100644 --- a/karmaworld/apps/notes/models.py +++ b/karmaworld/apps/notes/models.py @@ -233,36 +233,3 @@ def note_receiver(sender, **kwargs): @receiver(post_delete, sender=Note, weak=False) def note_receiver(sender, **kwargs): update_note_counts(kwargs['instance']) - - -class DriveAuth(models.Model): - """ stored google drive authentication and refresh token - used for interacting with google drive """ - - email = models.EmailField(default=GOOGLE_USER) - credentials = models.TextField() # JSON of Oauth2Credential object - stored_at = models.DateTimeField(auto_now=True) - - - @staticmethod - def get(email=GOOGLE_USER): - """ Staticmethod for getting the singleton DriveAuth object """ - # FIXME: this is untested - return DriveAuth.objects.filter(email=email).reverse()[0] - - - def store(self, creds): - """ Transform an existing credentials object to a db serialized """ - self.email = creds.id_token['email'] - self.credentials = creds.to_json() - self.save() - - - def transform_to_cred(self): - """ take stored credentials and produce a Credentials object """ - return Credentials.new_from_json(self.credentials) - - - def __unicode__(self): - return u'Gdrive auth for %s created/updated at %s' % \ - (self.email, self.stored_at) diff --git a/karmaworld/apps/notes/tests.py b/karmaworld/apps/notes/tests.py index e2b5bc9..0425f43 100644 --- a/karmaworld/apps/notes/tests.py +++ b/karmaworld/apps/notes/tests.py @@ -11,7 +11,6 @@ from nose.tools import ok_ from nose.tools import assert_is_none from karmaworld.apps.notes.models import Note -from karmaworld.apps.notes.models import DriveAuth from karmaworld.apps.courses.models import Course from karmaworld.apps.courses.models import School @@ -103,48 +102,3 @@ class TestNoteUrl(BaseNote): self.note.slug = None url = self.expected_url_prefix + str(self.note.id) eq_(self.note.get_absolute_url(), url) - - -class BaseDriveAuth(object): - google_user = u'foobie@blet.ch' - json_str = """ - {"_module": "oauth2client.client", "_class": "OAuth2Credentials", "access_token": "asdfasdfasdfasdfasdfasdfasdf", "token_uri": "https://accounts.google.com/o/oauth2/token", "invalid": false, "client_id": "9999999999999.apps.googleusercontent.com", "id_token": {"aud": "9999999999999.apps.googleusercontent.com", "cid": "9999999999999.apps.googleusercontent.com", "iss": "accounts.google.com", "email": "foobie@blet.ch", "exp": 1354832924, "iat": 1354829024, "token_hash": "xXxXxXyyYyYyYyYyYy", "id": "444444444444444444444", "hd": "karmanotes.org", "verified_email": "true"}, "client_secret": "7&7&&7&7&7&7&&&&&&&&&&&(", "token_expiry": "2013-02-04T23:46:47Z", "refresh_token": "qweasdzxcrtyfghvbnuiojklm,.", "user_agent": null} - """ - - def setup(self): - self.drive_auth = DriveAuth() - self.drive_auth.email = self.google_user - self.drive_auth.credentials = self.json_str - self.drive_auth.save() - - def teardown(self): - self.drive_auth.delete() - - - -class MockCred(object): - id_token = {'email': u'Mock@email.me'} - - def to_json(self): - return "Yo, this is the json you wanted, not really" - - -class TestDriveAuth(BaseDriveAuth): - - def test_drive_auth_get(self): - """ Test getting via DriveAuth.get() staticmethod """ - drive_auth = DriveAuth.get(email=self.google_user) - eq_(drive_auth, self.drive_auth) - -class TestDriveAuthStore(BaseDriveAuth): - - def test_drive_auth_store(self): - cred = MockCred() # create a mock credentials object - self.drive_auth.store(cred) # use that to override the drive auth object - # The drive auth email should have been reset based on the MockCred value - ok_(self.drive_auth.email != self.google_user, - "DriveAuth.email should have been reset based on the MockCred \ - passed to DriveAuth.store()") - eq_(self.drive_auth.email, u'Mock@email.me') - -