-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some issues in quick form when a field has been configured (Field…
…sConfig) as 'required'. The form raised an error at validation event if the field was filled A crash happened when the field an enumerable FK.
- Loading branch information
Showing
7 changed files
with
186 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
from creme.creme_core.models import ( | ||
CustomField, | ||
FakeCivility, | ||
FakeContact, | ||
FakeInvoice, | ||
FakeOrganisation, | ||
|
@@ -50,26 +51,26 @@ def test_create_contact(self): | |
count = FakeContact.objects.count() | ||
|
||
url = self._build_quickform_url(FakeContact) | ||
response = self.assertGET200(url) | ||
self.assertTemplateUsed(response, 'creme_core/generics/form/add-popup.html') | ||
self.assertEqual('SAMEORIGIN', response.get('X-Frame-Options')) # allows iframe | ||
response1 = self.assertGET200(url) | ||
self.assertTemplateUsed(response1, 'creme_core/generics/form/add-popup.html') | ||
self.assertEqual('SAMEORIGIN', response1.get('X-Frame-Options')) # allows iframe | ||
|
||
context = response.context | ||
context = response1.context | ||
self.assertEqual(FakeContact.creation_label, context.get('title')) | ||
self.assertEqual(FakeContact.save_label, context.get('submit_label')) | ||
|
||
# --- | ||
last_name = 'Kirika' | ||
email = '[email protected]' | ||
response = self.assertPOST200( | ||
response2 = self.assertPOST200( | ||
url, | ||
data={ | ||
'last_name': last_name, | ||
'email': email, | ||
'user': user.id, | ||
}, | ||
) | ||
self.assertEqual('SAMEORIGIN', response.get('X-Frame-Options')) # allows iframe | ||
self.assertEqual('SAMEORIGIN', response2.get('X-Frame-Options')) # allows iframe | ||
self.assertEqual(count + 1, FakeContact.objects.count()) | ||
|
||
contact = self.get_object_or_fail(FakeContact, last_name=last_name, email=email) | ||
|
@@ -78,7 +79,7 @@ def test_create_contact(self): | |
'added': [[contact.id, str(contact)]], | ||
'value': contact.id, | ||
}, | ||
response.json(), | ||
response2.json(), | ||
) | ||
|
||
def test_get_not_superuser(self): | ||
|
@@ -164,12 +165,64 @@ def test_fields_config_required(self): | |
) | ||
|
||
url = self._build_quickform_url(FakeContact) | ||
response = self.assertGET200(url) | ||
response1 = self.assertGET200(url) | ||
|
||
with self.assertNoException(): | ||
fields = response.context['form'].fields | ||
fields = response1.context['form'].fields | ||
|
||
self.assertNotIn(not_required, fields) | ||
self.assertIn(required, fields) | ||
|
||
# --- | ||
last_name = 'Kirika' | ||
required_value = '1594862' | ||
self.assertNoFormError(self.client.post( | ||
url, | ||
data={ | ||
'last_name': last_name, | ||
'user': user.id, | ||
required: required_value, | ||
not_required: 'whatever', | ||
}, | ||
)) | ||
|
||
contact = self.get_object_or_fail(FakeContact, last_name=last_name) | ||
self.assertEqual(required_value, getattr(contact, required)) | ||
self.assertFalse(getattr(contact, not_required)) | ||
|
||
def test_fields_config_required__enumerable_fk(self): | ||
user = self.login_as_root_and_get() | ||
required = 'civility' | ||
|
||
vanilla_fields = FakeContactQuickForm(user=user).fields | ||
self.assertNotIn(required, vanilla_fields) | ||
|
||
FieldsConfig.objects.create( | ||
content_type=FakeContact, | ||
descriptions=[(required, {FieldsConfig.REQUIRED: True})], | ||
) | ||
|
||
url = self._build_quickform_url(FakeContact) | ||
response1 = self.assertGET200(url) | ||
|
||
with self.assertNoException(): | ||
fields = response1.context['form'].fields | ||
|
||
self.assertIn(required, fields) | ||
|
||
# --- | ||
last_name = 'Kirika' | ||
required_value = FakeCivility.objects.first() | ||
self.assertNoFormError(self.client.post( | ||
url, | ||
data={ | ||
'last_name': last_name, | ||
'user': user.id, | ||
required: required_value.id, | ||
}, | ||
)) | ||
|
||
contact = self.get_object_or_fail(FakeContact, last_name=last_name) | ||
self.assertEqual(required_value, getattr(contact, required)) | ||
|
||
# TODO: test_quickform_with_custom_sync_data |