Exemplo n.º 1
0
    def test_get_scopes(self):
        # Test fetching scopes of a valid grant
        oauth_grant = db_oauth_grant.create(
            client_id=self.oauth_client["client_id"],
            code="Test Code",
            redirect_uri="https://example.com",
            expires=datetime.now() + timedelta(seconds=200),
            user_id=self.user.id,
            scopes="review user",
        )
        self.assertIn("review", db_oauth_grant.get_scopes(oauth_grant["id"]))

        # Test fetching scopes of a grant that does not exist
        db_oauth_grant.delete(client_id=self.oauth_client["client_id"], code=oauth_grant["code"])
        with self.assertRaises(db_exceptions.NoDataFoundException):
            db_oauth_grant.get_scopes(oauth_grant["id"])

        # Test fetching scopes of grant with no scopes
        oauth_grant = db_oauth_grant.create(
            client_id=self.oauth_client["client_id"],
            code="Test Code",
            redirect_uri="https://example.com",
            expires=datetime.now() + timedelta(seconds=200),
            user_id=self.user.id,
            scopes=None,
        )
        self.assertEqual([], db_oauth_grant.get_scopes(oauth_grant["id"]))
Exemplo n.º 2
0
 def test_create(self):
     self.assertEqual(len(db_oauth_grant.list_grants()), 0)
     db_oauth_grant.create(
         client_id=self.oauth_client["client_id"],
         code="Test Code",
         redirect_uri="https://example.com",
         expires=datetime.now() + timedelta(seconds=200),
         user_id=self.user.id,
         scopes=None,
     )
     self.assertEqual(len(db_oauth_grant.list_grants()), 1)
Exemplo n.º 3
0
 def persist_grant(client_id, code, scopes, expires, redirect_uri, user_id):
     return db_oauth_grant.create(
         client_id=client_id,
         code=code,
         scopes=scopes,
         expires=expires,
         redirect_uri=redirect_uri,
         user_id=user_id,
     )