forms: unpack all values from schema paths list (#40990)
This commit is contained in:
parent
cbb9380c80
commit
b024d9c92a
|
@ -1,13 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import pytest
|
||||
|
||||
from django.utils.timezone import now
|
||||
|
||||
from zoo.models import EntitySchema, Entity, Job
|
||||
|
||||
|
||||
def test_new_schema(db):
|
||||
|
||||
@pytest.fixture
|
||||
def person_schema(db):
|
||||
schema = EntitySchema.objects.create(
|
||||
name='person',
|
||||
schema={
|
||||
|
@ -26,11 +28,19 @@ def test_new_schema(db):
|
|||
'type': 'string',
|
||||
},
|
||||
}
|
||||
},
|
||||
'bad_type_property': {
|
||||
'type': 'not string type'
|
||||
}
|
||||
}
|
||||
})
|
||||
return schema
|
||||
|
||||
|
||||
def test_new_schema(db, person_schema):
|
||||
|
||||
Entity.objects.create(
|
||||
schema=schema,
|
||||
schema=person_schema,
|
||||
meta={},
|
||||
content={
|
||||
'first_name': 'Leon',
|
||||
|
@ -39,7 +49,7 @@ def test_new_schema(db):
|
|||
'street': 'Rue du Château',
|
||||
}
|
||||
})
|
||||
qs = Entity.objects.content_search(schema, address__street='chateau')
|
||||
qs = Entity.objects.content_search(person_schema, address__street='chateau')
|
||||
assert qs.count() == 1
|
||||
|
||||
|
||||
|
@ -89,3 +99,19 @@ def test_jobs(db):
|
|||
assert Job.objects.get().content['done'] is True
|
||||
assert Job.objects.get().content['tries'] == 0
|
||||
assert Job.objects.get().state == Job.STATE_SUCCESS
|
||||
|
||||
|
||||
def test_demo_schemas_view(app, person_schema):
|
||||
resp = app.get('/demo/schemas/', status=200)
|
||||
assert resp.html.find('a').text == 'person'
|
||||
assert resp.html.find('a')['href'] == '/demo/schemas/person/'
|
||||
|
||||
|
||||
def test_demo_schema_view(app, person_schema):
|
||||
resp = app.get('/demo/schemas/person/', {'page': 'not a number'}, status=200)
|
||||
assert resp.html.find('h1').text == 'person'
|
||||
assert resp.html.find('label', {'for': 'id_first_name'}).name
|
||||
assert resp.html.find('label', {'for': 'id_last_name'}).name
|
||||
assert resp.html.find('label', {'for': 'id_address__street'}).name
|
||||
assert not resp.html.find('label', {'for': 'bad_type_property'})
|
||||
assert resp.html.find('input', {'type': 'submit'})['value'] == 'Recherche'
|
||||
|
|
|
@ -31,7 +31,7 @@ class EntitySearchForm(Form):
|
|||
'step': '0.02',
|
||||
}),
|
||||
required=False)
|
||||
for path, _type in self.schema.paths():
|
||||
for path, _type, _format in self.schema.paths():
|
||||
if _type != 'string':
|
||||
continue
|
||||
key = '__'.join(path)
|
||||
|
|
Loading…
Reference in New Issue