-
Notifications
You must be signed in to change notification settings - Fork 20
Django integration tests #47
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
Conversation
- Use parameterization in pytest to simplify many test cases by wrapping the input and expected values in tuples - No need for unittest or class wrappers - There is a legitimately failing test in parser/tests.py - code change needed in parser_classes to handle this I think - natlang/tests.py will need to be updated to match the new spec, as will the whole text_to_edtf() function
The max and min functions now use a generator expression to filter out infinite values unless they are directly relevant to the calculation; if inf or -inf are found, they are returned instead of doing a comparison.
In Django 3.0, "support for the context argument of Field.from_db_value() and Expression.convert_value() is removed": https://github.com/django/django/blob/91a4b9a8ec2237434f06866f39c7977e889aeae6/docs/releases/3.0.txt#L641-L642
Previously, the Django field could directly take an EDTF string, only a natural language string that was then parsed and turned into EDTF.
Django 4 test project for now
Ignore SQLlite local database
This basic Django app shows how a user could create a model using the EDTFField and store data in it. The integration tests check that the EDTFField and associated fields (date_edtf_direct and date_display, in this case) work correctly. There is a weird issue in test_date_display() where if we use an instance variable (self.event1, self.event2) the event.date_display property is available, but if we retrieve the object from the database it is not. I tried using TestEvent.objects.create() as well as the current method (make and then save an instance to no effect). CI is set up to run the Django integration tests after Pytest. We could move to using pytest/django-pytest for these tests as well
|
Thanks very much for this. I've been looking at your comment on fbf4262 about the failing test. I found that if I move the definition of In ImageField they do a similar thing to populate the width and height fields by attaching a signal handler to |
|
... oh, |
|
Something like this maybe? |
Ensure that `EDTFField` properly updates related fields whenever it changes inspired by ImageField. - Use EDTFFieldDescriptorClass as a descriptor for EDTFField. This inherits from DeferredAttribute and handles getting, setting, and updating values. Whenever the field value is set, additional logic is processed to potentially update the field again based on other fields. - update_values() replaces pre_save() to better handle updates/dependencies when EDTFField value changes - contribute_to_class() attaches update_values() to the `post_init` signal These changes should make the field updates more stable and (not reliant on definition order in models using EDTFField). Thanks for the suggestion @aweakley ixc#47 (comment) Co-Authored-By: aweakley <224316+aweakley@users.noreply.github.com>
|
Great, thanks very much. |
This PR sets up a test Django project implementing EDTFField and adding Django integration tests. It also adds an additional class attribute
direct_input_fieldto EDTFField so users have the option to provide an EDTF string directly instead of or in addition to usingnatural_field_text. If bothnatural_field_textanddirect_input_fieldare provided,direct_input_textsupersedes it for date generation;natural_field_textcan still be used as a label. If onlydirect_input_fieldis provided, thennatural_field_textis filled with the EDTF string.This PR should be merged after the
pytestPR.