Skip to content

Commit

Permalink
Merge pull request #580 from edx/hammad/ENT-2322
Browse files Browse the repository at this point in the history
ENT-2322 | added startswith filter in enterprise customer basic list endpoint.
  • Loading branch information
HammadAhmadWaqas authored Oct 9, 2019
2 parents bb5a5c7 + db38f6b commit 61fad2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions enterprise/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ def basic_list(self, request, *arg, **kwargs):
"""
Enterprise Customer's Basic data list without pagination
"""
startswith = request.GET.get('startswith')
queryset = self.get_queryset().order_by('name')
if startswith:
queryset = queryset.filter(name__istartswith=startswith)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)

Expand Down
17 changes: 14 additions & 3 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ def test_enterprise_customer_basic_list(self):
"""
Test basic list endpoint of enterprise_customers
"""
url = urljoin(settings.TEST_SERVER, ENTERPRISE_CUSTOMER_BASIC_LIST_ENDPOINT)
enterprise_customers = [
{
'name': FAKER.company(), # pylint: disable=no-member
Expand All @@ -556,11 +557,21 @@ def test_enterprise_customer_basic_list(self):
for _ in range(15)
]
self.create_items(factories.EnterpriseCustomerFactory, enterprise_customers)
response = self.client.get(urljoin(settings.TEST_SERVER, ENTERPRISE_CUSTOMER_BASIC_LIST_ENDPOINT))
response = self.load_json(response.content)
# now replace 'uuid' key with 'id' to match with response.
for enterprise_customer in enterprise_customers:
enterprise_customer['id'] = enterprise_customer.pop("uuid")
assert sorted(enterprise_customers, key=itemgetter('name')) == response
sorted_enterprise_customers = sorted(enterprise_customers, key=itemgetter('name'))

response = self.client.get(url)
assert sorted_enterprise_customers == self.load_json(response.content)

# test startswith param
startswith = 'a'
startswith_enterprise_customers = [
customer for customer in sorted_enterprise_customers if customer['name'].lower().startswith(startswith)
]
response = self.client.get(url, {'startswith': startswith})
assert startswith_enterprise_customers == self.load_json(response.content)

@ddt.data(
# Request missing required permissions query param.
Expand Down

0 comments on commit 61fad2f

Please sign in to comment.