* Fix test base classes

* Fix copy product page test

* Fix test names

* Run python tests in parallel by default

* Run CI tests in parallel

* Remove dead code

* Rename test and lint
This commit is contained in:
Jhonatan Lopes 2023-12-13 21:23:37 -03:00 коммит произвёл GitHub
Родитель 808447f7d7
Коммит 1cc4318cf0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 33 добавлений и 17 удалений

2
.github/workflows/continous-integration.yml поставляемый
Просмотреть файл

@ -107,7 +107,7 @@ jobs:
- name: Run type checks
run: mypy network-api
- name: Run Tests
run: cd network-api && pytest --ds=networkapi.settings -cov=network-api/networkapi --cov-report=term-missing
run: cd network-api && pytest -n auto -v --ds=networkapi.settings -cov=network-api/networkapi --cov-report=term-missing
- name: Coveralls
run: coveralls
continue-on-error: true

Просмотреть файл

@ -37,6 +37,7 @@ class WagtailpagesTestCase(wagtail_test.WagtailPageTestCase):
assert cls.fr_locale != cls.default_locale
def setUp(self):
super().setUp()
self.activate_locale(self.default_locale)
def synchronize_tree(self):

Просмотреть файл

@ -1,4 +1,4 @@
from unittest import expectedFailure
from unittest.mock import MagicMock, patch
from django.urls import reverse
from django.utils.translation import gettext
@ -8,6 +8,7 @@ from wagtail import hooks
from networkapi.wagtailpages.factory import buyersguide as buyersguide_factories
from networkapi.wagtailpages.pagemodels.buyersguide.homepage import BuyersGuidePage
from networkapi.wagtailpages.pagemodels.buyersguide.products import (
ProductPage,
ProductPageEvaluation,
reset_product_page_votes,
)
@ -377,14 +378,6 @@ class TestProductPageEvaluationPrefetching(BuyersGuideTestCase):
class CreateEvaluationPostSaveSignalTests(BuyersGuideTestCase):
@classmethod
def setUpTestData(cls):
# Override BuyersGuidePage.subpage_types to include ProductPage
# If we don't, the copy page action will fail with a Permission Error
# since we can't add a ProductPage as a child of BuyersGuidePage
BuyersGuidePage.subpage_types += ["wagtailpages.ProductPage"]
super().setUpTestData()
def setUp(self):
super().setUp()
self.user = self.login()
@ -435,8 +428,29 @@ class CreateEvaluationPostSaveSignalTests(BuyersGuideTestCase):
product_page.refresh_from_db()
self.assertEqual(product_page.evaluation, evaluation)
@expectedFailure
# This is a bit weird, but somewhere along the copy page action
# the GeneralProductPage.specific_class is being resolved
# to ProductPage, which is not allowed as a child of BuyersGuidePage.
# Thus, we need to mock the subpage_types and allowed_subpage_models to allow for
# ProductPage to be added as a child of BuyersGuidePage. If we don't, the
# copy page action will fail with a Permission Error since we can't add a
# ProductPage as a child of BuyersGuidePage.
MOCK_BG_SUBPAGE_TYPES = BuyersGuidePage.subpage_types + ["wagtailpages.ProductPage"]
MOCK_BG_ALLOWED_SUBPAGE_MODELS = BuyersGuidePage.allowed_subpage_models() + [ProductPage]
class AfterCopyProductPageHookTests(BuyersGuideTestCase):
def setUp(self):
super().setUp()
self.user = self.login()
@hooks.register_temporarily("after_copy_page", reset_product_page_votes)
@patch.multiple(
BuyersGuidePage,
subpage_types=MagicMock(return_value=MOCK_BG_SUBPAGE_TYPES),
allowed_subpage_models=MagicMock(return_value=MOCK_BG_ALLOWED_SUBPAGE_MODELS),
)
def test_that_copied_page_gets_evaluation(self):
product_page = buyersguide_factories.GeneralProductPageFactory(
parent=self.bg, title="My Product", slug="my-product"

Просмотреть файл

@ -55,4 +55,5 @@ class RCCTestCase(test_base.WagtailpagesTestCase):
)
def setUp(self):
super().setUp()
self.synchronize_tree()

Просмотреть файл

@ -24,7 +24,7 @@ class TestRCCLibraryPage(rcc_test_base.RCCTestCase):
with open(os.devnull, "w") as f:
management.call_command("update_index", verbosity=0, stdout=f)
def testget_sorted_filtered_detail_pages(self):
def test_get_sorted_filtered_detail_pages(self):
detail_page_1 = detail_page_factory.RCCDetailPageFactory(
parent=self.library_page,
)
@ -38,7 +38,7 @@ class TestRCCLibraryPage(rcc_test_base.RCCTestCase):
self.assertIn(detail_page_1, rcc_detail_pages)
self.assertIn(detail_page_2, rcc_detail_pages)
def testget_sorted_filtered_detail_pages_with_translation_aliases(self):
def test_get_sorted_filtered_detail_pages_with_translation_aliases(self):
detail_page_1 = detail_page_factory.RCCDetailPageFactory(
parent=self.library_page,
)

Просмотреть файл

@ -54,5 +54,6 @@ class ResearchHubTestCase(test_base.WagtailpagesTestCase):
)
def setUp(self):
super().setUp()
self.synchronize_tree()
self.activate_locale(self.default_locale)

Просмотреть файл

@ -308,11 +308,13 @@ def makemigrations_dryrun(ctx, args=""):
@task(aliases=["docker-test"])
def test(ctx):
"""Run tests."""
djcheck(ctx)
makemigrations_dryrun(ctx, args="--check")
test_python(ctx)
@task(aliases=["docker-test-python"])
def test_python(ctx, file="", n="1", verbose=False):
def test_python(ctx, file="", n="auto", verbose=False):
"""
Run python tests.
@ -328,9 +330,6 @@ def test_python(ctx, file="", n="1", verbose=False):
Default is 'auto' which allows pytest to automatically determine the optimal number.
- verbose: Optional boolean flag indicating whether to print verbose output during testing. Default is False.
"""
djcheck(ctx)
makemigrations_dryrun(ctx, args="--check")
parallel = f"-n {n}" if n != "1" else ""
v = "-v" if verbose else ""
# Don't run coverage if a file is specified