|
1
|
|
|
import pytest |
|
2
|
|
|
|
|
3
|
|
|
from goblin import exception, properties |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
def test_property_mapping(person, lives_in): |
|
7
|
|
|
db_name, data_type = person.__mapping__._ogm_properties['name'] |
|
8
|
|
|
assert db_name == 'name' |
|
9
|
|
|
assert isinstance(data_type, properties.String) |
|
10
|
|
|
db_name, data_type = person.__mapping__._ogm_properties['age'] |
|
11
|
|
|
assert db_name == 'custom__person__age' |
|
12
|
|
|
assert isinstance(data_type, properties.Integer) |
|
13
|
|
|
db_name, data_type = lives_in.__mapping__._ogm_properties['notes'] |
|
14
|
|
|
assert db_name == 'notes' |
|
15
|
|
|
assert isinstance(data_type, properties.String) |
|
16
|
|
|
|
|
17
|
|
|
ogm_name, data_type = person.__mapping__._db_properties['name'] |
|
18
|
|
|
assert ogm_name == 'name' |
|
19
|
|
|
assert isinstance(data_type, properties.String) |
|
20
|
|
|
ogm_name, data_type = person.__mapping__._db_properties[ |
|
21
|
|
|
'custom__person__age'] |
|
22
|
|
|
assert ogm_name == 'age' |
|
23
|
|
|
assert isinstance(data_type, properties.Integer) |
|
24
|
|
|
ogm_name, data_type = lives_in.__mapping__._db_properties['notes'] |
|
25
|
|
|
assert ogm_name == 'notes' |
|
26
|
|
|
assert isinstance(data_type, properties.String) |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
def test_metaprop_mapping(place): |
|
30
|
|
|
place.historical_name = ['Iowa City'] |
|
31
|
|
|
db_name, data_type = place.historical_name( |
|
32
|
|
|
'Iowa City').__mapping__._ogm_properties['notes'] |
|
33
|
|
|
assert db_name == 'notes' |
|
34
|
|
|
assert isinstance(data_type, properties.String) |
|
35
|
|
|
db_name, data_type = place.historical_name( |
|
36
|
|
|
'Iowa City').__mapping__._ogm_properties['year'] |
|
37
|
|
|
assert db_name == 'year' |
|
38
|
|
|
assert isinstance(data_type, properties.Integer) |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
def test_label_creation(place, lives_in): |
|
42
|
|
|
assert place.__mapping__._label == 'place' |
|
43
|
|
|
assert lives_in.__mapping__._label == 'lives_in' |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
def test_mapper_func(place, knows): |
|
47
|
|
|
assert callable(place.__mapping__._mapper_func) |
|
48
|
|
|
assert callable(knows.__mapping__._mapper_func) |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
def test_getattr_getdbname(person, lives_in): |
|
52
|
|
|
db_name = person.__mapping__.name |
|
53
|
|
|
assert db_name == 'name' |
|
54
|
|
|
db_name = person.__mapping__.age |
|
55
|
|
|
assert db_name == 'custom__person__age' |
|
56
|
|
|
db_name = lives_in.__mapping__.notes |
|
57
|
|
|
assert db_name == 'notes' |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
def test_getattr_doesnt_exist(person): |
|
61
|
|
|
with pytest.raises(exception.MappingError): |
|
62
|
|
|
db_name = person.__mapping__.doesnt_exits |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
def test_db_name_factory(person, place): |
|
66
|
|
|
assert person.__mapping__.nicknames == 'person__nicknames' |
|
67
|
|
|
assert place.__mapping__.zipcode == 'place__zipcode' |
|
68
|
|
|
|