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")
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"])