Skip to content

Commit

Permalink
[OSDEV-1474] Add contributor type to /api/contributors/ endpoint (#461)
Browse files Browse the repository at this point in the history
[OSDEV-1474](https://opensupplyhub.atlassian.net/browse/OSDEV-1474) Add
contributor type to /api/contributors/ endpoint

- Added contributor type value to response of `/api/contributors/`
endpoint
- Updated unit test

[OSDEV-1474]:
https://opensupplyhub.atlassian.net/browse/OSDEV-1474?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
roman-stolar authored Dec 17, 2024
1 parent c1bda26 commit d7859c4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
1 change: 1 addition & 0 deletions doc/release/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

### What's new
* [OSDEV-1383](https://opensupplyhub.atlassian.net/browse/OSDEV-1383) - Edited text of the automated email that notifies a contributor when one of their facilities has been claimed. The new text provides more information to the contributor to understand the claim process and how they can encourage more of their facilities to claim their profile.
* [OSDEV-1474](https://opensupplyhub.atlassian.net/browse/OSDEV-1474) - Added contributor type value to response of `/api/contributors/` endpoint.

### Release instructions:
* Ensure that the following commands are included in the `post_deployment` command:
Expand Down
32 changes: 26 additions & 6 deletions src/django/api/tests/test_contributors_list_api_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def setUp(self):
self.contrib_six_name = "contributor with one good and one error item"
self.contrib_seven_name = "contributor with create=False API source"

self.contrib_one_type = "Brand / Retailer"
self.contrib_two_type = "Multi-Stakeholder Initiative"
self.contrib_three_type = "Union"
self.contrib_four_type = "Brand / Retailer"
self.contrib_five_type = "Multi-Stakeholder Initiative"
self.contrib_six_type = "Test"
self.contrib_seven_type = "Union"

self.country_code = "US"
self.list_one_name = "one"
self.list_one_b_name = "one-b"
Expand All @@ -57,43 +65,44 @@ def setUp(self):
self.contrib_one = Contributor.objects.create(
admin=self.user_one,
name=self.contrib_one_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_one_type,
)

self.contrib_two = Contributor.objects.create(
admin=self.user_two,
name=self.contrib_two_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_two_type,
)

self.contrib_three = Contributor.objects.create(
admin=self.user_three,
name=self.contrib_three_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_three_type,
)

self.contrib_four = Contributor.objects.create(
admin=self.user_four,
name=self.contrib_four_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_four_type,
)

self.contrib_five = Contributor.objects.create(
admin=self.user_five,
name=self.contrib_five_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_five_type,
)

self.contrib_six = Contributor.objects.create(
admin=self.user_six,
name=self.contrib_six_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
other_contrib_type=self.contrib_six_type,
)

self.contrib_seven = Contributor.objects.create(
admin=self.user_seven,
name=self.contrib_seven_name,
contrib_type=Contributor.OTHER_CONTRIB_TYPE,
contrib_type=self.contrib_seven_type,
)

self.list_one = FacilityList.objects.create(
Expand Down Expand Up @@ -216,12 +225,18 @@ def test_contributors_list_has_only_contributors_with_active_lists(self):
response = self.client.get("/api/contributors/")
response_data = response.json()
contributor_names = list(zip(*response_data))[1]
contributor_types = list(zip(*response_data))[2]

self.assertIn(
self.contrib_one_name,
contributor_names,
)

self.assertIn(
self.contrib_one_type,
contributor_types,
)

self.assertNotIn(
self.contrib_two_name,
contributor_names,
Expand All @@ -247,6 +262,11 @@ def test_contributors_list_has_only_contributors_with_active_lists(self):
contributor_names,
)

self.assertIn(
self.contrib_six_type,
contributor_types,
)

self.assertEqual(
2,
len(contributor_names),
Expand Down
18 changes: 12 additions & 6 deletions src/django/api/views/contributor/all_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@
@throttle_classes([])
def all_contributors(_):
"""
Returns list contributors as a list of tuples of contributor IDs and names.
Returns list contributors as a list of tuples of
contributor IDs, names and types.
## Sample Response
[
[1, "Contributor One"]
[2, "Contributor Two"]
[1, "Contributor One", "Brand/Retailer"]
[2, "Contributor Two", "Service Provider"]
]
"""
response_data = [
(contributor.id, contributor.name)
for contributor
in active_contributors().order_by('name')
(
contributor.id,
contributor.name,
contributor.other_contrib_type
if contributor.contrib_type == "Other"
else contributor.contrib_type
)
for contributor in active_contributors().order_by('name')
]

return Response(response_data)

0 comments on commit d7859c4

Please sign in to comment.