-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create some test data with model_mommy #18
Conversation
…heck if it breaks something)
This is sort of covered with https://github.com/alsur/django-admin-auto-tests , but no objection to it being here. Could you update the PR to use model-bakery, as model-mommy is discontinued. |
I've tested this model-bakery jayvdb@2c9debe 👍 |
@PetrDlouhy , this is missing one case diff --git a/django_admin_smoke_tests/tests.py b/django_admin_smoke_tests/tests.py
index 718fbfb..cbd928f 100644
--- a/django_admin_smoke_tests/tests.py
+++ b/django_admin_smoke_tests/tests.py
@@ -167,7 +167,7 @@ class AdminSiteSmokeTestMixin(object):
form_field_names = frozenset(getattr(model_admin.form,
'base_fields', []))
- model_instance = model()
+ model_instance = mommy.make(model)
for attr in attr_set:
# for now we'll just check attributes, not strings This comes out in the following, where ======================================================================
ERROR: test_specified_fields (tests.test_admin_smoke.AdminSiteSmokeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "django_admin_smoke_tests/tests.py", line 31, in test_deco
fn(self, model, model_admin)
File "django_admin_smoke_tests/tests.py", line 188, in test_specified_fields
has_model_attr = hasattr(model_instance, attr)
File "djstripe/models/base.py", line 821, in is_expired
return timezone.now() > self.created + timedelta(hours=24)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'datetime.timedelta'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "django_admin_smoke_tests/tests.py", line 50, in test_deco
six.raise_from(ModelAdminCheckException(
File "<string>", line 3, in raise_from
django_admin_smoke_tests.tests.ModelAdminCheckException: Above exception occured while running test 'test_specified_fields' on modeladmin djstripe.IdempotencyKeyAdmin (IdempotencyKey) |
I have updated this to use model-bakery and also rebased to #17 (updates to newest Django) |
I've run the tests on a bunch of Pythons and Djangos, and all seem to have one failure. .................E......
======================================================================
ERROR: test_change_post (test_project.main.tests.ForbiddenAdminSiteSmokeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jayvdb/django/django-admin-smoke-tests/django_admin_smoke_tests/tests.py", line 29, in test_deco
fn(self, model, model_admin)
File "/home/jayvdb/django/django-admin-smoke-tests/django_admin_smoke_tests/tests.py", line 316, in test_change_post
response = model_admin.change_view(request, object_id=str(pk))
File "/home/jayvdb/django/django-admin-smoke-tests/.tox/py38-dj32/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1660, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "/home/jayvdb/django/django-admin-smoke-tests/.tox/py38-dj32/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/jayvdb/django/django-admin-smoke-tests/.tox/py38-dj32/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/jayvdb/django/django-admin-smoke-tests/.tox/py38-dj32/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1540, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/home/jayvdb/django/django-admin-smoke-tests/.tox/py38-dj32/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1565, in _changeform_view
raise PermissionDenied
django.core.exceptions.PermissionDenied
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/jayvdb/django/django-admin-smoke-tests/django_admin_smoke_tests/tests.py", line 55, in test_deco
six.raise_from(
File "<string>", line 3, in raise_from
django_admin_smoke_tests.tests.ModelAdminCheckException: Above exception occured while running test 'test_change_post' on modeladmin main.ForbiddenPostAdmin (ForbiddenPost) Really looking forward to this. |
@jayvdb I know about this (it is visible on automated tests running in GitHub actions for my repository: https://github.com/PetrDlouhy/django-admin-smoke-tests/). I tried to fix this with I am planing to change the whole workflow to run test for every model as separate test case. I already have working prototype. It might provide different solution to this problem, so I will return to this after I will finish that. |
Test change view with data created by model mommy
TODO: