Skip to content

Commit

Permalink
Add qa param
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit Vermeulen committed Feb 19, 2024
1 parent c7c61c7 commit 0da50b9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 53 deletions.
15 changes: 12 additions & 3 deletions home/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,19 @@ class OrderedContentSetViewSet(BaseAPIViewSet):
filter_backends = (SearchFilter,)

def get_queryset(self):
# TODO: Filter using the qa Param
# qa = self.request.query_params.get("qa")
qa = self.request.query_params.get("qa")

queryset = OrderedContentSet.objects.all()
if qa:
# return the latest revision for each OrderedContentSet
queryset = OrderedContentSet.objects.all()
for ocs in queryset:
latest_revision = ocs.revisions.order_by("-created_at").first()
if latest_revision:
latest_revision = latest_revision.as_object()
ocs.profile_fields = latest_revision.profile_fields

else:
queryset = OrderedContentSet.objects.all()
return queryset


Expand Down
97 changes: 47 additions & 50 deletions home/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,25 +612,24 @@ def test_orderedcontent_detail_endpoint_tags_flag(self, uclient):
}
assert content["pages"][0]["tags"] == [t.name for t in self.page1.tags.all()]

# TODO: Add this when we add support for qa param
# def test_orderedcontent_endpoint_with_drafts(self, uclient):
# """
# Unpublished ordered content sets are returned if the qa param is set.
# """
# self.ordered_content_set.unpublish()
# url = "/api/v2/orderedcontent/?qa=True"
# # it should return a list of ordered content sets with the unpublished one included
# response = uclient.get(url)
# content = json.loads(response.content)

# # the content set is not live but content is returned
# assert not self.ordered_content_set.live
# assert content["count"] == 2
# assert content["results"][0]["name"] == self.ordered_content_set.name
# assert content["results"][0]["profile_fields"][0] == {
# "profile_field": "gender",
# "value": "female",
# }
def test_orderedcontent_endpoint_with_drafts(self, uclient):
"""
Unpublished ordered content sets are returned if the qa param is set.
"""
self.ordered_content_set.unpublish()
url = "/api/v2/orderedcontent/?qa=True"
# it should return a list of ordered content sets with the unpublished one included
response = uclient.get(url)
content = json.loads(response.content)

# the content set is not live but content is returned
assert not self.ordered_content_set.live
assert content["count"] == 2
assert content["results"][0]["name"] == self.ordered_content_set.name
assert content["results"][0]["profile_fields"][0] == {
"profile_field": "gender",
"value": "female",
}

def test_orderedcontent_endpoint_without_drafts(self, uclient):
"""
Expand All @@ -646,31 +645,30 @@ def test_orderedcontent_endpoint_without_drafts(self, uclient):
assert not self.ordered_content_set.live
assert (
content["count"] == 2
) # TODO: Change this when we add support for qa param
)
assert content["results"][0]["name"] == self.ordered_content_set_timed.name
assert content["results"][0]["profile_fields"][0] == {
"profile_field": "gender",
"value": "female",
}

# TODO: Add this when we add support for qa param
# def test_orderedcontent_detail_endpoint_with_drafts(self, uclient):
# """
# Unpublished ordered content sets are returned if the qa param is set.
# """
# self.ordered_content_set.unpublish()
# url = f"/api/v2/orderedcontent/{self.ordered_content_set.id}/?qa=True"
# # it should return specific ordered content set that is in draft
# response = uclient.get(url)
# content = json.loads(response.content)

# # the content set is not live but content is returned
# assert not self.ordered_content_set.live
# assert content["name"] == self.ordered_content_set.name
# assert content["profile_fields"][0] == {
# "profile_field": "gender",
# "value": "female",
# }
def test_orderedcontent_detail_endpoint_with_drafts(self, uclient):
"""
Unpublished ordered content sets are returned if the qa param is set.
"""
self.ordered_content_set.unpublish()
url = f"/api/v2/orderedcontent/{self.ordered_content_set.id}/?qa=True"
# it should return specific ordered content set that is in draft
response = uclient.get(url)
content = json.loads(response.content)

# the content set is not live but content is returned
assert not self.ordered_content_set.live
assert content["name"] == self.ordered_content_set.name
assert content["profile_fields"][0] == {
"profile_field": "gender",
"value": "female",
}

def test_orderedcontent_detail_endpoint_without_drafts(self, uclient):
"""
Expand Down Expand Up @@ -706,18 +704,17 @@ def test_orderedcontent_new_draft(self, uclient):
"value": "female",
}

# TODO: When the qa param is introduced
# response = uclient.get("/api/v2/orderedcontent/?qa=True")
# content = json.loads(response.content)
# assert len(content["results"][0]["profile_fields"]) == 2
# assert content["results"][0]["profile_fields"][0] == {
# "profile_field": "gender",
# "value": "female",
# }
# assert content["results"][0]["profile_fields"][1] == {
# "profile_field": "relationship",
# "value": "in_a_relationship",
# }
response = uclient.get("/api/v2/orderedcontent/?qa=True")
content = json.loads(response.content)
assert len(content["results"][0]["profile_fields"]) == 2
assert content["results"][0]["profile_fields"][0] == {
"profile_field": "gender",
"value": "female",
}
assert content["results"][0]["profile_fields"][1] == {
"profile_field": "relationship",
"value": "in_a_relationship",
}


@pytest.mark.django_db
Expand Down

0 comments on commit 0da50b9

Please sign in to comment.