forked from lk-geimfari/mimesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_schema.py
86 lines (62 loc) · 2.07 KB
/
test_schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from os.path import (
abspath,
dirname,
join,
)
import pytest
from mimesis import settings
from mimesis.exceptions import UndefinedSchema
from mimesis.schema import Schema
PATH = abspath(join(dirname(__file__), 'data_fixtures'))
@pytest.fixture(params=settings.LIST_OF_LOCALES)
def schema(request):
return Schema(request.param)
@pytest.fixture
def valid_schema():
return dict(
id='cryptographic.uuid',
name='text.word',
version='development.version',
owner=dict(
email='personal.email',
token='cryptographic.token',
creator='personal.full_name'),
sites=[{'home_page': 'internet.home_page'}],
)
@pytest.fixture
def invalid_schema():
return dict(
id='none.none',
name='text.none',
version='development.none',
owner=dict(
email='personal.none',
token='cryptographic.none',
creator='personal.none',
),
sites=[{'home_page': 'internet.home_page'}],
)
def test_valid_schema(schema, valid_schema):
result = schema.load(schema=valid_schema).create(iterations=1)
assert isinstance(result, dict) # check type_to decorator
result_2 = schema.load(schema=valid_schema).create(iterations=10)
assert isinstance(result_2, list)
assert len(result_2) == 10
def test_invalid_schema(schema, invalid_schema):
with pytest.raises(AttributeError):
schema.load(schema=invalid_schema).create()
def test_load_schema_by_path(schema):
valid_path = PATH + '/schema.json'
result = schema.load(path=valid_path)
assert isinstance(result.schema, dict)
def test_load_invalid_schema(schema):
invalid_json_file = PATH + '/invalid_schema.json'
with pytest.raises(ValueError):
schema.load(path=invalid_json_file)
def test_load_schema_by_invalid_path(schema):
invalid_path = PATH + '/schema.j'
with pytest.raises(FileNotFoundError):
schema.load(path=invalid_path)
def test_undefined_schema(schema):
with pytest.raises(UndefinedSchema):
schema.create()