Skip to content
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

test_add and required form fields, usch as django-treebeard's _position #6

Open
jayvdb opened this issue Jun 20, 2020 · 0 comments
Open

Comments

@jayvdb
Copy link

jayvdb commented Jun 20, 2020

When trying to add tests to django-oscar, I am running into a problem with a model which uses https://github.com/django-treebeard/django-treebeard

First I need to map its slug field

from model_bakery import baker
from model_bakery.generators import default_mapping, SlugField

baker.generators.add('oscar.models.fields.slugfield.SlugField', default_mapping[SlugField])

Then the test_add fails

FAIL: test_add (oscar.apps.catalogue.tests.test_admin.CategoryAdminTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/admin_auto_tests/test_model.py", line 123, in test_add
    self.assertEqual(len(response.context_data['errors']), 0,
AssertionError: 1 != 0 : _position: This field is required.

The _position feel is a required ChoiceField on the form.

I see model-bakery (and mommy) doesnt mentions support for ChoiceField, so I add _position using the create_form_instance_data hook (nice!)

This is a forms field, not a db field, which might account for bakery not supporting it.
I'll also raise an issue there.

If there isnt opportunity to add support for form fields to bakery, perhaps django-admin-auto-tests should detect required form fields and mark the test as a skip or fail with a better explanation of how to implement create_form_instance_data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant