API: filter extension versions by blender_version parameter #86

Merged
Oleg-Komarov merged 2 commits from api-filter-blender-version into main 2024-04-22 15:24:06 +02:00
Showing only changes of commit 75213d0b3e - Show all commits

View File

@ -1,3 +1,5 @@
from datetime import timedelta
from django.test import TestCase
from django.urls import reverse
@ -80,6 +82,64 @@ class PublicViewsTest(_BaseTestCase):
self.assertTemplateUsed(response, 'extensions/home.html')
class ApiViewsTest(_BaseTestCase):
def test_blender_version_filter(self):
create_approved_version(blender_version_min='4.0.1')
create_approved_version(blender_version_min='4.1.1')
create_approved_version(blender_version_min='4.2.1')
url = reverse('extensions:api')
json = self.client.get(
url + '?blender_version=4.1.1',
HTTP_ACCEPT='application/json',
).json()
self.assertEqual(len(json['data']), 2)
json2 = self.client.get(
url + '?blender_version=3.0.1',
HTTP_ACCEPT='application/json',
).json()
self.assertEqual(len(json2['data']), 0)
json3 = self.client.get(
url + '?blender_version=4.3.1',
HTTP_ACCEPT='application/json',
).json()
self.assertEqual(len(json3['data']), 3)
def test_blender_version_filter_latest_not_max_version(self):
version = create_approved_version(blender_version_min='4.0.1')
version.date_created
extension = version.extension
create_approved_version(
blender_version_min='4.2.1',
extension=extension,
date_created=version.date_created + timedelta(days=1),
version='2.0.0',
)
create_approved_version(
blender_version_min='3.0.0',
extension=extension,
date_created=version.date_created + timedelta(days=2),
version='1.0.1',
)
create_approved_version(
blender_version_min='4.2.1',
extension=extension,
date_created=version.date_created + timedelta(days=3),
version='2.0.1',
)
url = reverse('extensions:api')
json = self.client.get(
url + '?blender_version=4.1.1',
HTTP_ACCEPT='application/json',
).json()
self.assertEqual(len(json['data']), 1)
# we are expecting the latest matching, not the maximum version
self.assertEqual(json['data'][0]['version'], '1.0.1')
class ExtensionDetailViewTest(_BaseTestCase):
def test_cannot_view_unlisted_extension_anonymously(self):
extension = _create_extension()