Skip to content

Commit

Permalink
add it
Browse files Browse the repository at this point in the history
  • Loading branch information
axiomofjoy committed Sep 12, 2024
1 parent c577fb5 commit 43699a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions integration_tests/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def create_api_key(
def delete_api_key(self, api_key: _ApiKey, /) -> None:
return _delete_api_key(api_key, self)

def export_embeddings(self, filename: str) -> None:
_export_embeddings(self, filename=filename)


_SYSTEM_USER_GID = _GqlId(GlobalID(type_name="User", node_id="1"))
_DEFAULT_ADMIN = _User(
Expand Down Expand Up @@ -828,6 +831,13 @@ def _log_out(
resp.raise_for_status()


def _export_embeddings(
auth: Optional[_SecurityArtifact] = None, /, *, filename: str
) -> httpx.Response:
resp = _httpx_client(auth).get("/exports", params={"filename": filename})
resp.raise_for_status()


def _json(
resp: httpx.Response,
) -> Dict[str, Any]:
Expand All @@ -853,3 +863,4 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None: ...

_EXPECTATION_401 = pytest.raises(HTTPStatusError, match="401 Unauthorized")
_EXPECTATION_403 = pytest.raises(HTTPStatusError, match="403 Forbidden")
_EXPECTATION_404 = pytest.raises(HTTPStatusError, match="404 Not Found")
19 changes: 19 additions & 0 deletions integration_tests/auth/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
_DEFAULT_ADMIN,
_DENIED,
_EXPECTATION_401,
_EXPECTATION_404,
_MEMBER,
_OK,
_OK_OR_DENIED,
Expand All @@ -45,6 +46,7 @@
_create_user,
_DefaultAdminTokenSequestration,
_Expectation,
_export_embeddings,
_GetUser,
_GqlId,
_Headers,
Expand Down Expand Up @@ -741,3 +743,20 @@ def test_api_key(
if api_key and expected is SpanExportResult.SUCCESS:
_DEFAULT_ADMIN.delete_api_key(api_key)
assert export(_spans) is SpanExportResult.FAILURE


class TestEmbeddingsRestApi:
@pytest.mark.parametrize("role_or_user", [_MEMBER, _ADMIN, _DEFAULT_ADMIN])
def test_authenticated_users_can_access_route(
self,
role_or_user: _RoleOrUser,
_get_user: _GetUser,
) -> None:
user = _get_user(role_or_user)
logged_in_user = user.log_in()
with _EXPECTATION_404: # no files have been exported
logged_in_user.export_embeddings("embeddings")

def test_unauthenticated_requests_receive_401(self) -> None:
with _EXPECTATION_401:
_export_embeddings(None, filename="embeddings")

0 comments on commit 43699a7

Please sign in to comment.