Example #1
0
 def test_fetch_by_code_no_data(self):
     mc_mock = Mock(spec=["get"])
     mc_mock.get.return_value = None
     
     store = MemcacheTokenStore(mc=mc_mock, prefix=self.cache_prefix)
     
     with self.assertRaises(AuthCodeNotFound):
         store.fetch_by_code("abc")
Example #2
0
 def test_save_token(self):
     access_token = AccessToken(client_id="myclient", token="xyz",
                                data={"name": "test"},
                                scopes=["foo_read", "foo_write"],)
     
     cache_key = self._generate_test_cache_key(access_token.token)
     
     mc_mock = Mock(spec=["set"])
     
     store = MemcacheTokenStore(mc=mc_mock, prefix=self.cache_prefix)
     
     store.save_token(access_token)
     
     mc_mock.set.assert_called_with(cache_key, access_token)
Example #3
0
 def test_save_code(self):
     data = {"client_id": "myclient", "code": "abc", "expires_at": 100,
              "redirect_uri": "http://localhost",
              "scopes": ["foo_read", "foo_write"],
              "data": {"name": "test"}}
     
     auth_code = AuthorizationCode(**data)
     
     cache_key = self._generate_test_cache_key(data["code"])
     
     mc_mock = Mock(spec=["set"])
     
     store = MemcacheTokenStore(mc=mc_mock, prefix=self.cache_prefix)
     
     store.save_code(auth_code)
     
     mc_mock.set.assert_called_with(cache_key, auth_code)
Example #4
0
 def test_fetch_by_code(self):
     code = "abc"
     saved_data = {"client_id": "myclient", "code": code,
                   "expires_at": 100, "redirect_uri": "http://localhost",
                   "scopes": ["foo_read", "foo_write"],
                   "data": {"name": "test"}}
     
     mc_mock = Mock(spec=["get"])
     mc_mock.get.return_value = saved_data
     
     store = MemcacheTokenStore(mc=mc_mock, prefix=self.cache_prefix)
     
     auth_code = store.fetch_by_code(code)
     
     mc_mock.get.assert_called_with(self._generate_test_cache_key(code))
     self.assertEqual(auth_code.client_id, saved_data["client_id"])
     self.assertEqual(auth_code.code, saved_data["code"])
     self.assertEqual(auth_code.expires_at, saved_data["expires_at"])
     self.assertEqual(auth_code.redirect_uri, saved_data["redirect_uri"])
     self.assertEqual(auth_code.scopes, saved_data["scopes"])
     self.assertEqual(auth_code.data, saved_data["data"])