Skip to content

Commit

Permalink
add academy filter
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Sep 19, 2023
1 parent c3ca7ad commit 214b1ea
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
40 changes: 39 additions & 1 deletion breathecode/admissions/tests/urls/tests_syllabus_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_syllabus_slug_version(self):
}])

@patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW))
def test_syllabus_slug_version_with_filters(self):
def test_syllabus_slug_version_with_is_documentation_filter(self):
"""Test /certificate without auth"""
syllabus_kwargs = {'slug': 'they-killed-kenny', 'is_documentation': True}
model = self.generate_models(syllabus=True, syllabus_version=True, syllabus_kwargs=syllabus_kwargs)
Expand All @@ -78,3 +78,41 @@ def test_syllabus_slug_version_with_filters(self):
self.assertEqual(self.all_syllabus_version_dict(), [{
**self.model_to_dict(model, 'syllabus_version')
}])

@patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW))
def test_syllabus_slug_version_with_academy_filter(self):
"""Test /certificate without auth"""
syllabus_kwargs = {'slug': 'they-killed-kenny', 'is_documentation': True}
model = self.generate_models(syllabus=True, syllabus_version=True, syllabus_kwargs=syllabus_kwargs)
base_url = reverse_lazy('admissions:syllabus_version')
url = f'{base_url}?is_documentation=True&academy=1,2,3'
response = self.client.get(url)
json = response.json()
expected = [get_serializer(model['syllabus_version'], model['syllabus'])]

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)

self.assertEqual(self.all_syllabus_dict(), [{**self.model_to_dict(model, 'syllabus')}])
self.assertEqual(self.all_syllabus_version_dict(), [{
**self.model_to_dict(model, 'syllabus_version')
}])

@patch('django.utils.timezone.now', MagicMock(return_value=UTC_NOW))
def test_syllabus_slug_version_with_wrong_academy_filter(self):
"""Test /certificate without auth"""
syllabus_kwargs = {'slug': 'they-killed-kenny', 'is_documentation': True}
model = self.generate_models(syllabus=True, syllabus_version=True, syllabus_kwargs=syllabus_kwargs)
base_url = reverse_lazy('admissions:syllabus_version')
url = f'{base_url}?is_documentation=True&academy=2,3'
response = self.client.get(url)
json = response.json()
expected = []

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)

self.assertEqual(self.all_syllabus_dict(), [{**self.model_to_dict(model, 'syllabus')}])
self.assertEqual(self.all_syllabus_version_dict(), [{
**self.model_to_dict(model, 'syllabus_version')
}])
6 changes: 5 additions & 1 deletion breathecode/admissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,12 +1701,16 @@ def get(self, request):
param = self.request.GET.get('version')
lookup['version'] = param

if 'academy' in self.request.GET:
param = self.request.GET.get('academy')
lookup['syllabus__academy_owner__id__in'] = [p for p in param.split(',')]

if 'is_documentation' in self.request.GET:
param = self.request.GET.get('is_documentation')
if param == 'True':
lookup['syllabus__is_documentation'] = True

items = items.filter(Q(syllabus__private=False), **lookup).order_by('version')
items = items.filter(syllabus__private=False, **lookup).order_by('version')

serializer = GetSyllabusVersionSerializer(items, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
Expand Down

0 comments on commit 214b1ea

Please sign in to comment.