forked from rdmorganiser/rdmo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rdmorganiser#1066 from rdmorganiser/dev-2.2.0-vali…
…dators Dev 2.2.0 validators
- Loading branch information
Showing
18 changed files
with
1,701 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.8 on 2024-07-18 14:41 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('projects', '0060_alter_issue_options'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='value', | ||
name='value_type', | ||
field=models.CharField(choices=[('text', 'Text'), ('url', 'URL'), ('integer', 'Integer'), ('float', 'Float'), ('boolean', 'Boolean'), ('date', 'Date'), ('datetime', 'Datetime'), ('email', 'E-mail'), ('phone', 'Phone'), ('option', 'Option'), ('file', 'File')], default='text', help_text='Type of this value.', max_length=8, verbose_name='Value type'), | ||
), | ||
] |
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,8 +6,8 @@ | |
projects = [1, 11] | ||
|
||
results_map = { | ||
1: (58, 81), | ||
11: (0, 29) | ||
1: (58, 88), | ||
11: (0, 36) | ||
} | ||
|
||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import pytest | ||
|
||
from rest_framework.exceptions import ValidationError as RestFameworkValidationError | ||
|
||
from ..validators import ValueTypeValidator | ||
|
||
data = ( | ||
('url', 'https://example.com'), | ||
('url', 'http://example.com'), | ||
('integer', '1'), | ||
('integer', '-1'), | ||
('integer', '+1'), | ||
('integer', '12345'), | ||
('float', '1'), | ||
('float', '1.0'), | ||
('float', '+1.0'), | ||
('float', '-1.0'), | ||
('float', '1,000,000.12345'), | ||
('float', '1,0'), | ||
('float', '1.000.000,12345'), | ||
('float', '1.0e20'), | ||
('float', '1.0E20'), | ||
('float', '1.0e-20'), | ||
('float', '1.0e+20'), | ||
('boolean', '0'), | ||
('boolean', '1'), | ||
('boolean', 'f'), | ||
('boolean', 't'), | ||
('boolean', 'TrUe'), # spellchecker:disable-line | ||
('boolean', 'FaLsE'), # spellchecker:disable-line | ||
('boolean', 'true'), | ||
('boolean', 'false'), | ||
('date', '01.02.2024'), | ||
('date', '1.2.2024'), | ||
('date', '13.01.1337'), | ||
('date', '2/1/2024'), | ||
('date', '2024-01-02'), | ||
('date', '1. 2. 2024'), | ||
('datetime', '2024-01-02'), | ||
('datetime', '2024-01-02T10:00'), | ||
('datetime', '2024-01-02T10:00:00'), | ||
('datetime', '2024-01-02T10:00:00.123'), | ||
('datetime', '2024-01-02T10:00:00+02:00'), | ||
('email', '[email protected]'), | ||
('email', '[email protected]'), | ||
('email', '[email protected]'), | ||
('email', '[email protected]'), | ||
('email', '[email protected]'), | ||
('phone', '123456'), | ||
('phone', '123 456'), | ||
('phone', '362 123456'), | ||
('phone', '(362) 123456'), | ||
('phone', '+49 (0) 362123456'), | ||
('phone', '+49 (0) 362 123456'), | ||
) | ||
data_error = ( | ||
('url', 'wrong'), | ||
('url', 'example.com'), | ||
('integer', 'wrong'), | ||
('integer', '1.0'), | ||
('integer', '1b'), | ||
('float', 'wrong'), | ||
('float', '1,0000.12456'), | ||
('float', '1.0000,12456'), | ||
('float', '1.0a20'), | ||
('boolean', 'wrong'), | ||
('boolean', '2'), | ||
('boolean', '-1'), | ||
('boolean', 'tr'), | ||
('boolean', 'truee'), | ||
('boolean', 'falze'), | ||
('date', 'wrong'), | ||
('date', '001.02.2024'), | ||
('date', '01.02.20240'), | ||
('date', '1,2.2024'), | ||
('date', '2-1-2024'), | ||
('date', '2024-001-02'), | ||
('date', '20240-01-02'), | ||
('date', '2024-1-2'), | ||
('datetime', 'wrong'), | ||
('datetime', '2024-13-02'), | ||
('datetime', '2024-13-02Y10:00:00'), | ||
('datetime', '2024-01-02T10:00:00ZZ+02:00'), | ||
('datetime', '2024-01-02T25:00'), | ||
('datetime', '2024-01-02T10:60:00'), | ||
('email', 'wrong'), | ||
('email', 'example.com'), | ||
('email', 'ü[email protected]'), | ||
('email', 'user@[email protected]'), | ||
('email', 'user@com'), | ||
('email', '[email protected]'), | ||
('phone', 'wrong'), | ||
('phone', '123456a'), | ||
('phone', '123 456 a'), | ||
('phone', '362s 123456'), | ||
('phone', '(3 62) 123456'), | ||
('phone', '-49 (0) 362123456'), | ||
('phone', '49 (0) 362 123456'), | ||
('phone', '1234 (0) 123456'), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('value_type,text', data) | ||
def test_serializer(db, value_type, text): | ||
validator = ValueTypeValidator() | ||
validator({'value_type': value_type, 'text': text}) | ||
|
||
|
||
@pytest.mark.parametrize('value_type,text', data_error) | ||
def test_serializer_error(db, value_type, text): | ||
validator = ValueTypeValidator() | ||
with pytest.raises(RestFameworkValidationError): | ||
validator({'value_type': value_type, 'text': text}) |
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from django.conf import settings | ||
from django.urls import reverse | ||
|
||
from rdmo.core.constants import VALUE_TYPE_CHOICES, VALUE_TYPE_FILE, VALUE_TYPE_TEXT | ||
from rdmo.core.constants import VALUE_TYPE_FILE, VALUE_TYPE_TEXT | ||
|
||
from ..models import Value | ||
|
||
|
@@ -56,6 +56,16 @@ | |
] | ||
set_questionsets = [42, 43] | ||
|
||
value_texts = ( | ||
('text', 'Lorem ipsum'), | ||
('url', 'https://lorem.ipsum'), | ||
('integer', '1337'), | ||
('float', '13.37'), | ||
('boolean', '1'), | ||
('datetime', '1337-01-13T13:37+13:37'), | ||
('email', '[email protected]'), | ||
('phone', '+49 (0) 1337 12345678') | ||
) | ||
|
||
@pytest.mark.parametrize('username,password', users) | ||
@pytest.mark.parametrize('project_id', projects) | ||
|
@@ -101,23 +111,23 @@ def test_detail(db, client, username, password, project_id, value_id): | |
|
||
@pytest.mark.parametrize('username,password', users) | ||
@pytest.mark.parametrize('project_id', projects) | ||
@pytest.mark.parametrize('value_type,value_type_label', VALUE_TYPE_CHOICES) | ||
def test_create_text(db, client, username, password, project_id, value_type, value_type_label): | ||
@pytest.mark.parametrize('value_type,value_text', value_texts) | ||
def test_create_text(db, client, username, password, project_id, value_type, value_text): | ||
client.login(username=username, password=password) | ||
|
||
url = reverse(urlnames['list'], args=[project_id]) | ||
data = { | ||
'attribute': attribute_id, | ||
'set_index': 0, | ||
'collection_index': 0, | ||
'text': 'Lorem ipsum', | ||
'text': value_text, | ||
'value_type': value_type, | ||
'unit': '' | ||
} | ||
response = client.post(url, data) | ||
|
||
if project_id in add_value_permission_map.get(username, []): | ||
assert response.status_code == 201 | ||
assert response.status_code == 201, response.content | ||
assert isinstance(response.json(), dict) | ||
assert response.json().get('id') in Value.objects.filter(project_id=project_id).values_list('id', flat=True) | ||
elif project_id in view_value_permission_map.get(username, []): | ||
|
@@ -128,15 +138,16 @@ def test_create_text(db, client, username, password, project_id, value_type, val | |
|
||
@pytest.mark.parametrize('username,password', users) | ||
@pytest.mark.parametrize('project_id', projects) | ||
@pytest.mark.parametrize('value_type,value_type_label', VALUE_TYPE_CHOICES) | ||
def test_create_option(db, client, username, password, project_id, value_type, value_type_label): | ||
@pytest.mark.parametrize('value_type,value_text', value_texts) | ||
def test_create_option(db, client, username, password, project_id, value_type, value_text): | ||
client.login(username=username, password=password) | ||
|
||
url = reverse(urlnames['list'], args=[project_id]) | ||
data = { | ||
'attribute': attribute_id, | ||
'set_index': 0, | ||
'collection_index': 0, | ||
'text': value_text, | ||
'option': option_id, | ||
'value_type': value_type, | ||
'unit': '' | ||
|
@@ -155,16 +166,16 @@ def test_create_option(db, client, username, password, project_id, value_type, v | |
|
||
@pytest.mark.parametrize('username,password', users) | ||
@pytest.mark.parametrize('project_id', projects) | ||
@pytest.mark.parametrize('value_type,value_type_label', VALUE_TYPE_CHOICES) | ||
def test_create_external(db, client, username, password, project_id, value_type, value_type_label): | ||
@pytest.mark.parametrize('value_type,value_text', value_texts) | ||
def test_create_external(db, client, username, password, project_id, value_type, value_text): | ||
client.login(username=username, password=password) | ||
|
||
url = reverse(urlnames['list'], args=[project_id]) | ||
data = { | ||
'attribute': attribute_id, | ||
'set_index': 0, | ||
'collection_index': 0, | ||
'text': 'Lorem ipsum', | ||
'text': value_text, | ||
'external_id': '1', | ||
'value_type': value_type, | ||
'unit': '' | ||
|
Oops, something went wrong.