Ejemplo n.º 1
0
    def test_constructor_explicit(self):
        dictionary = {}
        key = 'test-key'
        storage = dictionary_storage.DictionaryStorage(dictionary, key)

        lock = object()
        storage = dictionary_storage.DictionaryStorage(
            dictionary, key, lock=lock)
        self.assertEqual(storage._lock, lock)
Ejemplo n.º 2
0
def get_storage(request):
    """ Gets a Credentials storage object provided by the Django OAuth2 Helper
    object.

    Args:
        request: Reference to the current request object.

    Returns:
       An :class:`oauth2.client.Storage` object.
    """
    oauth2_settings = get_oauth2_settings()
    storage_model = oauth2_settings.storage_model
    user_property = oauth2_settings.storage_model_user_property
    credentials_property = oauth2_settings.storage_model_credentials_property

    if storage_model:
        module_name, class_name = storage_model.rsplit('.', 1)
        module = importlib.import_module(module_name)
        storage_model_class = getattr(module, class_name)
        return storage.DjangoORMStorage(storage_model_class, user_property,
                                        request.user, credentials_property)
    else:
        # use session
        return dictionary_storage.DictionaryStorage(request.session,
                                                    key=_CREDENTIALS_KEY)
Ejemplo n.º 3
0
    def test_constructor_defaults(self):
        dictionary = {}
        key = 'test-key'
        storage = dictionary_storage.DictionaryStorage(dictionary, key)

        self.assertEqual(dictionary, storage._dictionary)
        self.assertEqual(key, storage._key)
        self.assertIsNone(storage._lock)
Ejemplo n.º 4
0
 def test_release_lock(self):
     dictionary = {}
     key = 'credentials'
     storage = dictionary_storage.DictionaryStorage(dictionary, key)
     storage._lock = lock = _FakeLock()
     self.assertEqual(lock._release_count, 0)
     storage.release_lock()
     self.assertEqual(lock._release_count, 1)
Ejemplo n.º 5
0
    def test_delete(self):
        credentials = _generate_credentials()
        dictionary = {}
        key = 'credentials'
        storage = dictionary_storage.DictionaryStorage(dictionary, key)

        storage.put(credentials)

        self.assertIn(key, dictionary)

        storage.delete()

        self.assertNotIn(key, dictionary)
        self.assertIsNone(storage.get())
Ejemplo n.º 6
0
    def test_put(self):
        credentials = _generate_credentials()
        dictionary = {}
        key = 'credentials'
        storage = dictionary_storage.DictionaryStorage(dictionary, key)

        storage.put(credentials)
        returned = storage.get()

        self.assertIn(key, dictionary)
        self.assertIsNotNone(returned)
        self.assertEqual(returned.token, credentials.token)
        self.assertEqual(returned.id_token, credentials.id_token)
        self.assertEqual(returned.refresh_token, credentials.refresh_token)
        self.assertEqual(returned.client_id, credentials.client_id)
Ejemplo n.º 7
0
    def test_get(self):
        credentials = _generate_credentials()
        dictionary = {}
        key = 'credentials'
        storage = dictionary_storage.DictionaryStorage(dictionary, key)

        self.assertIsNone(storage.get())

        dictionary[key] = jsonpickle.encode(credentials)
        returned = storage.get()

        self.assertIsNotNone(returned)
        self.assertEqual(returned.token, credentials.token)
        self.assertEqual(returned.id_token, credentials.id_token)
        self.assertEqual(returned.refresh_token, credentials.refresh_token)
        self.assertEqual(returned.client_id, credentials.client_id)