Skip to content

Commit

Permalink
[DEV-11438] Get reviews (#296)
Browse files Browse the repository at this point in the history
* get reviews

* edits

* update docstring

---------

Co-authored-by: Nathanael Shim <[email protected]>
  • Loading branch information
nateshim-indico and Nathanael Shim authored Mar 7, 2024
1 parent 1547bd6 commit 699a0b9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
44 changes: 43 additions & 1 deletion indico/queries/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from indico.errors import IndicoInputError, IndicoTimeoutError
from indico.filters import SubmissionFilter
from indico.queries import JobStatus
from indico.types import Job, Submission
from indico.types import Job, Submission, SubmissionReviewFull
from indico.types.submission import VALID_SUBMISSION_STATUSES
from indico.types.utils import Timer

Expand Down Expand Up @@ -488,6 +488,48 @@ def process_response(self, response) -> Job:
return Job(id=response["jobId"])


class GetReviews(GraphQLRequest):
"""
Given a submission Id, return all the full Review objects back with changes
Args:
submission_id (int): Id of submission to submit reviewEnabled for
Options:
Returns:
A list of Review objects with changes
"""

query = """
query GetReview($submissionId: Int!)
{
submission(id: $submissionId) {
id
reviews {
id
submissionId
createdAt
createdBy
startedAt
completedAt
rejected
reviewType
notes
changes
}
}
}
"""

def __init__(self, submission_id: int):
super().__init__(self.query, variables={"submissionId": submission_id})

def process_response(self, response) -> List[SubmissionReviewFull]:
return [
SubmissionReviewFull(**review) for review in super().process_response(response)["submission"]["reviews"]
]


class RetrySubmission(GraphQLRequest):
"""
Given a list of submission ids, retry those failed submissions.
Expand Down
2 changes: 1 addition & 1 deletion indico/queries/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,4 @@ def __init__(self, workflow_id: int):
super().__init__(self.query, variables={"workflowId": workflow_id})

def process_response(self, response) -> bool:
return super().process_response(response)["deleteWorkflow"]["success"]
return super().process_response(response)["deleteWorkflow"]["success"]
25 changes: 25 additions & 0 deletions indico/types/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ class SubmissionReview(BaseType):
review_type: str
notes: str

class SubmissionReviewFull(BaseType):
f"""
Information about a submission's Reviews. Includes changes
Attributes:
id (int): The ID of the review.
submission_id (int): The ID of the submission that is being reviewed.
created_at (str): Timestamp of when the document was checked out
created_by (int): The ID of the User who submitted the review.
completed_at (str): Timestamp of when the review was submitted.
rejected (bool): Whether a submission has been rejected.
review_type (str): Type of review. One of {VALID_REVIEW_TYPES}
notes (str): Rejection reasons provided by user.
changes (dict): Changes for this review.
"""
id: int
submission_id: int
created_at: str
created_by: int
completed_at: str
rejected: bool
review_type: str
notes: str
changes: dict


class Submission(BaseType):
f"""
Expand Down
14 changes: 13 additions & 1 deletion tests/integration/queries/test_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from indico.client import IndicoClient, IndicoConfig
from indico.filters import DateRangeFilter, SubmissionFilter, SubmissionReviewFilter
from indico.queries import ListSubmissions
from indico.queries import ListSubmissions, GetReviews
from indico.types import SubmissionReviewFull


def test_list_submissions(indico):
Expand Down Expand Up @@ -64,3 +65,14 @@ def test_list_submissions_filter_created_at(indico):
assert len(subs) > 0
subs = client.call(ListSubmissions(filters=SubmissionFilter(updated_at=date_filter), limit=10))
assert len(subs) > 0


def test_get_reviews(indico):
client = IndicoClient()

subs = client.call(ListSubmissions(limit=10))
assert len(subs) > 0
for sub in subs:
reviews = client.call(GetReviews(sub.id))
for review in reviews:
assert (isinstance(review, SubmissionReviewFull))

0 comments on commit 699a0b9

Please sign in to comment.