Skip to content

Commit 37c8496

Browse files
committed
replace assertNumQueries by assertMaxQueries
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 1904e0b commit 37c8496

9 files changed

Lines changed: 28 additions & 23 deletions

File tree

.github/workflows/run-unit-tests-docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
- name: Run tests
2929
run: |
3030
docker compose -f compose.yml -f compose.build.yml run web \
31-
python ./manage.py test --verbosity=2 --noinput --parallel 2
31+
python ./manage.py test --verbosity=2 --noinput --parallel auto

component_catalog/tests/test_importers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def test_importers_view_num_queries_view(self):
601601
with self.assertMaxQueries(9):
602602
self.client.get(reverse("admin:component_catalog_package_import"))
603603

604-
with self.assertNumQueries(4):
604+
with self.assertMaxQueries(4):
605605
self.client.get(reverse("admin:organization_owner_import"))
606606

607607
with self.assertMaxQueries(10):

component_catalog/tests/test_views.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from dje.models import ExternalReference
5353
from dje.models import ExternalSource
5454
from dje.models import History
55+
from dje.tests import MaxQueryMixin
5556
from dje.tests import add_perm
5657
from dje.tests import add_perms
5758
from dje.tests import create_superuser
@@ -77,7 +78,7 @@
7778
User = get_user_model()
7879

7980

80-
class ComponentUserViewsTestCase(TestCase):
81+
class ComponentUserViewsTestCase(MaxQueryMixin, TestCase):
8182
def setUp(self):
8283
self.nexb_dataspace = Dataspace.objects.create(name="nexB")
8384
self.nexb_user = User.objects.create_superuser(
@@ -980,7 +981,7 @@ def test_component_catalog_details_view_num_queries(self):
980981
History.log_change(self.basic_user, self.component1, "Changed version.")
981982
History.log_change(self.nexb_user, self.component1, "Changed notes.")
982983

983-
with self.assertNumQueries(32):
984+
with self.assertMaxQueries(33):
984985
self.client.get(url)
985986

986987
def test_component_catalog_details_view_package_tab_fields_visibility(self):
@@ -1095,7 +1096,7 @@ def test_component_catalog_component_create_ajax_view(self):
10951096
self.assertContains(response, expected, html=True)
10961097

10971098

1098-
class PackageUserViewsTestCase(TestCase):
1099+
class PackageUserViewsTestCase(MaxQueryMixin, TestCase):
10991100
testfiles_location = join(dirname(__file__), "testfiles")
11001101

11011102
def setUp(self):
@@ -1133,7 +1134,7 @@ def setUp(self):
11331134

11341135
def test_package_list_view_num_queries(self):
11351136
self.client.login(username=self.super_user.username, password="secret")
1136-
with self.assertNumQueries(16):
1137+
with self.assertMaxQueries(17):
11371138
self.client.get(reverse("component_catalog:package_list"))
11381139

11391140
def test_package_list_view_pagination(self):
@@ -1271,7 +1272,7 @@ def test_package_details_view_num_queries(self):
12711272
)
12721273

12731274
self.client.login(username=self.super_user.username, password="secret")
1274-
with self.assertNumQueries(30):
1275+
with self.assertMaxQueries(31):
12751276
self.client.get(self.package1.get_absolute_url())
12761277

12771278
def test_package_details_view_content(self):
@@ -3797,7 +3798,7 @@ def test_component_catalog_package_update_view_save_as_with_collect_data(
37973798
self.assertEqual(1, len(mock_collect_data.mock_calls))
37983799

37993800

3800-
class ComponentListViewTestCase(TestCase):
3801+
class ComponentListViewTestCase(MaxQueryMixin, TestCase):
38013802
def setUp(self):
38023803
self.dataspace = Dataspace.objects.create(
38033804
name="nexB",
@@ -3887,7 +3888,7 @@ def setUp(self):
38873888

38883889
def test_component_catalog_list_view_num_queries(self):
38893890
self.client.login(username="nexb_user", password="t3st")
3890-
with self.assertNumQueries(17):
3891+
with self.assertMaxQueries(18):
38913892
self.client.get(reverse("component_catalog:component_list"))
38923893

38933894
def test_component_catalog_list_view_default(self):

license_library/tests/test_views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from organization.models import Subowner
3232

3333

34-
class LicenseListViewTestCase(TestCase):
34+
class LicenseListViewTestCase(MaxQueryMixin, TestCase):
3535
def setUp(self):
3636
self.nexb_dataspace = Dataspace.objects.create(
3737
name="nexB",
@@ -286,7 +286,7 @@ def test_license_library_list_previous_next_license_link(self):
286286
def test_license_library_list_view_num_queries(self):
287287
self.client.login(username="nexb_user", password="t3st")
288288

289-
with self.assertNumQueries(16):
289+
with self.assertMaxQueries(17):
290290
self.client.get(reverse("license_library:license_list"))
291291

292292
def test_license_profile_column_availability_in_license_list_view(self):

organization/tests/test_views.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from django.urls import reverse
1414

1515
from dje.models import Dataspace
16+
from dje.tests import MaxQueryMixin
1617
from dje.tests import add_perm
1718
from dje.tests import create_superuser
1819
from dje.tests import create_user
@@ -24,7 +25,7 @@
2425
Component = apps.get_model("component_catalog", "Component")
2526

2627

27-
class OwnerUserViewsTestCase(TestCase):
28+
class OwnerUserViewsTestCase(MaxQueryMixin, TestCase):
2829
def setUp(self):
2930
self.dataspace = Dataspace.objects.create(name="Dataspace")
3031
self.super_user = create_superuser("super_user", self.dataspace)
@@ -94,12 +95,12 @@ def test_object_details_view_tab_owner(self):
9495

9596
def test_owner_list_view_num_queries(self):
9697
self.client.login(username=self.super_user.username, password="secret")
97-
with self.assertNumQueries(13):
98+
with self.assertMaxQueries(14):
9899
self.client.get(reverse("organization:owner_list"))
99100

100101
def test_owner_details_view_num_queries(self):
101102
self.client.login(username=self.super_user.username, password="secret")
102-
with self.assertNumQueries(18):
103+
with self.assertMaxQueries(19):
103104
self.client.get(self.owner1.get_absolute_url())
104105

105106
def test_owner_list_view_search_unicode_utf8_name_support(self):

product_portfolio/tests/test_views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_product_portfolio_detail_view_tab_inventory_and_hierarchy_availability(
136136
ProductComponent.objects.create(
137137
product=self.product1, component=self.component1, dataspace=self.dataspace
138138
)
139-
with self.assertNumQueries(27):
139+
with self.assertMaxQueries(28):
140140
response = self.client.get(url)
141141
self.assertContains(response, expected1)
142142
self.assertContains(response, expected2)
@@ -162,7 +162,7 @@ def test_product_portfolio_detail_view_tab_inventory_availability(self):
162162
ProductPackage.objects.create(
163163
product=self.product1, package=self.package1, dataspace=self.dataspace
164164
)
165-
with self.assertNumQueries(25):
165+
with self.assertMaxQueries(26):
166166
response = self.client.get(url)
167167
self.assertContains(response, expected)
168168

@@ -357,7 +357,7 @@ def test_product_portfolio_tab_vulnerability_view_queries(self):
357357
make_vulnerability_analysis(product_package2, vulnerability2)
358358

359359
url = product1.get_url("tab_vulnerabilities")
360-
with self.assertNumQueries(11):
360+
with self.assertMaxQueries(12):
361361
self.client.get(url)
362362

363363
def test_product_portfolio_tab_vulnerability_risk_threshold(self):

reporting/tests/test_views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from component_catalog.models import Component
2020
from dje.copier import copy_object
2121
from dje.models import Dataspace
22+
from dje.tests import MaxQueryMixin
2223
from license_library.models import License
2324
from license_library.models import LicenseCategory
2425
from organization.models import Owner
@@ -32,7 +33,7 @@
3233
from reporting.models import Report
3334

3435

35-
class ReportDetailsViewTestCase(TestCase):
36+
class ReportDetailsViewTestCase(MaxQueryMixin, TestCase):
3637
def setUp(self):
3738
self.dataspace = Dataspace.objects.create(name="nexB")
3839
self.owner = Owner.objects.create(dataspace=self.dataspace, name="My Fancy Owner Name")
@@ -1166,7 +1167,7 @@ def test_report_list_view_num_queries(self):
11661167
# Needed to clear the queries from the License batch creation in setUp
11671168
self.client.get(url)
11681169

1169-
with self.assertNumQueries(9):
1170+
with self.assertMaxQueries(10):
11701171
self.client.get(url)
11711172

11721173
def test_run_report_view_query_using_related_fields(self):

vulnerabilities/tests/test_views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
from component_catalog.tests import make_component
1313
from component_catalog.tests import make_package
1414
from dje.models import Dataspace
15+
from dje.tests import MaxQueryMixin
1516
from dje.tests import create_superuser
1617
from vulnerabilities.models import Vulnerability
1718
from vulnerabilities.tests import make_vulnerability
1819

1920

20-
class VulnerabilityViewsTestCase(TestCase):
21+
class VulnerabilityViewsTestCase(MaxQueryMixin, TestCase):
2122
def setUp(self):
2223
self.dataspace = Dataspace.objects.create(
2324
name="Dataspace",
@@ -35,7 +36,7 @@ def setUp(self):
3536

3637
def test_vulnerability_list_view_num_queries(self):
3738
self.client.login(username=self.super_user.username, password="secret")
38-
with self.assertNumQueries(7):
39+
with self.assertMaxQueries(8):
3940
response = self.client.get(reverse("vulnerabilities:vulnerability_list"))
4041

4142
vulnerability_count = Vulnerability.objects.count()

workflow/tests/test_views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from component_catalog.models import Subcomponent
2727
from dje.models import Dataspace
2828
from dje.models import History
29+
from dje.tests import MaxQueryMixin
2930
from dje.tests import add_perm
3031
from dje.tests import create_superuser
3132
from dje.tests import create_user
@@ -1643,7 +1644,7 @@ def test_workflow_notification_request_comment_slack_payload(self):
16431644
self.assertEqual(expected, payload)
16441645

16451646

1646-
class RequestInComponentCatalogTestCase(TestCase):
1647+
class RequestInComponentCatalogTestCase(MaxQueryMixin, TestCase):
16471648
def setUp(self):
16481649
self.nexb_dataspace = Dataspace.objects.create(name="nexB")
16491650
self.user = create_superuser("nexb_user", self.nexb_dataspace)
@@ -1810,7 +1811,7 @@ def test_component_catalog_details_view_with_requests_num_queries(self):
18101811

18111812
self.assertEqual(3, self.component1.get_requests(self.user).count())
18121813

1813-
with self.assertNumQueries(28):
1814+
with self.assertMaxQueries(29):
18141815
self.client.get(url)
18151816

18161817
@override_settings(ANONYMOUS_USERS_DATASPACE="nexB")

0 commit comments

Comments
 (0)