Skip to content

Commit

Permalink
QC CLoud API normalization (#438)
Browse files Browse the repository at this point in the history
- Remove old API response naming format
- File Create/Update/Delete will only return success with no payload
  • Loading branch information
Martin-Molinero authored Mar 28, 2024
1 parent 59cefbe commit 6c5dbb3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
9 changes: 2 additions & 7 deletions lean/components/api/file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,20 @@ def get_all(self, project_id: int) -> List[QCFullFile]:

return [QCFullFile(**file) for file in data["files"]]

def create(self, project_id: int, file_name: str, content: str) -> QCMinimalFile:
def create(self, project_id: int, file_name: str, content: str) -> None:
"""Creates a new file.
:param project_id: the id of the project to create a file for
:param file_name: the name of the file to create
:param content: the content of the file to create
:return: the created file
"""
data = self._api.post("files/create", {
"projectId": project_id,
"name": file_name,
"content": content
})

return QCMinimalFile(**data["files"][0])

def update(self, project_id: int, file_name: str, content: str) -> QCMinimalFile:
def update(self, project_id: int, file_name: str, content: str) -> None:
"""Updates an existing file.
:param project_id: the id of the project to update a file in
Expand All @@ -82,8 +79,6 @@ def update(self, project_id: int, file_name: str, content: str) -> QCMinimalFile
"content": content
})

return QCMinimalFile(**data["files"][0])

def delete(self, project_id: int, file_name: str) -> None:
"""Deletes an existing file.
Expand Down
7 changes: 3 additions & 4 deletions lean/models/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ class ProjectEncryptionKey(WrappedBaseModel):
name: str

class QCCollaborator(WrappedBaseModel):
id: int
uid: int
blivecontrol: bool
epermission: str
profileimage: str
liveControl: bool
permission: str
profileImage: str
name: str
owner: bool = False

Expand Down
5 changes: 1 addition & 4 deletions tests/components/api/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ def test_files_crud() -> None:

with create_project(api_client, "Test Project") as project:
# Test a file can be created
created_file = file_client.create(project.projectId, "file.py", "# This is a comment")

assert created_file.name == "file.py"
assert created_file.content == "# This is a comment"
file_client.create(project.projectId, "file.py", "# This is a comment")

# Test the file can be retrieved
retrieved_file = file_client.get(project.projectId, "file.py")
Expand Down

0 comments on commit 6c5dbb3

Please sign in to comment.