1
|
|
|
import pytest |
2
|
|
|
from aiogremlin import Graph |
3
|
|
|
from gremlin_python.process.traversal import Cardinality |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
@pytest.mark.asyncio |
7
|
|
|
async def test_add_update_property(app, person): |
8
|
|
|
session = await app.session() |
9
|
|
|
person.birthplace = 'Iowa City' |
10
|
|
|
result = await session.save(person) |
11
|
|
|
assert result.birthplace.value == 'Iowa City' |
12
|
|
|
person.birthplace = 'unknown' |
13
|
|
|
result = await session.save(person) |
14
|
|
|
assert result.birthplace.value == 'unknown' |
15
|
|
|
person.birthplace = None |
16
|
|
|
result = await session.save(person) |
17
|
|
|
assert not result.birthplace |
18
|
|
|
await app.close() |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
@pytest.mark.skip(reason="Test not working on all backends") |
22
|
|
|
#@pytest.mark.xfail(pytest.config.getoption('provider') == 'dse', reason='temporary') |
23
|
|
|
@pytest.mark.asyncio |
24
|
|
|
async def test_add_update_list_card_property(app, person): |
25
|
|
|
session = await app.session() |
26
|
|
|
person.nicknames = ['db', 'dirtydb'] |
27
|
|
|
result = await session.save(person) |
28
|
|
|
assert [v.value for v in result.nicknames] == ['db', 'dirtydb'] |
29
|
|
|
person.nicknames.append('davebshow') |
30
|
|
|
result = await session.save(person) |
31
|
|
|
assert [v.value |
32
|
|
|
for v in result.nicknames] == ['db', 'dirtydb', 'davebshow'] |
33
|
|
|
person.nicknames = [] |
34
|
|
|
result = await session.save(person) |
35
|
|
|
assert not result.nicknames |
36
|
|
|
person.nicknames = ['none'] |
37
|
|
|
result = await session.save(person) |
38
|
|
|
assert result.nicknames('none').value == 'none' |
39
|
|
|
person.nicknames = None |
40
|
|
|
result = await session.save(person) |
41
|
|
|
assert not result.nicknames |
42
|
|
|
await app.close() |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
@pytest.mark.skip(reason="Test not working on all backends") |
46
|
|
|
#@pytest.mark.skipif(pytest.config.getoption('provider') == 'dse',reason='set cardinality unsupported') |
47
|
|
|
@pytest.mark.asyncio |
48
|
|
|
async def test_add_update_set_card_property(app, place): |
49
|
|
|
session = await app.session() |
50
|
|
|
place.important_numbers = set([1, 2]) |
51
|
|
|
result = await session.save(place) |
52
|
|
|
assert {v.value for v in result.important_numbers} == {1, 2} |
53
|
|
|
place.important_numbers = set([3, 4]) |
54
|
|
|
result = await session.save(place) |
55
|
|
|
assert {v.value for v in result.important_numbers} == {3, 4} |
56
|
|
|
place.important_numbers.add(5) |
57
|
|
|
result = await session.save(place) |
58
|
|
|
assert {v.value for v in result.important_numbers} == {3, 4, 5} |
59
|
|
|
place.important_numbers = set() |
60
|
|
|
result = await session.save(place) |
61
|
|
|
assert not result.important_numbers |
62
|
|
|
place.important_numbers = set([1, 2]) |
63
|
|
|
result = await session.save(place) |
64
|
|
|
assert place.important_numbers(1).value == 1 |
65
|
|
|
place.important_numbers = None |
66
|
|
|
result = await session.save(place) |
67
|
|
|
assert not result.important_numbers |
68
|
|
|
await app.close() |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
@pytest.mark.skip(reason="Test not working on all backends") |
72
|
|
|
@pytest.mark.asyncio |
73
|
|
|
async def test_metas(app, place, remote_connection): |
74
|
|
|
g = Graph().traversal().withRemote(remote_connection) |
75
|
|
|
session = await app.session() |
76
|
|
|
place.zipcode = 98402 |
77
|
|
|
place.historical_name = ['Detroit'] |
78
|
|
|
place.historical_name('Detroit').notes = 'rock city' |
79
|
|
|
place.historical_name('Detroit').year = 1900 |
80
|
|
|
place.historical_name.append('Other') |
81
|
|
|
place.historical_name[-1].notes = 'unknown' |
82
|
|
|
place.historical_name[-1].year = 1700 |
83
|
|
|
detroit = await session.save(place) |
84
|
|
|
|
85
|
|
|
dprops = await g.V(detroit.id).properties().toList() |
86
|
|
|
assert len(dprops) == 4 |
87
|
|
|
trav = g.V(detroit.id).properties('historical_name').valueMap(True) |
88
|
|
|
dmetas = await trav.toList() |
89
|
|
|
assert dmetas[0]['value'] == 'Detroit' |
90
|
|
|
assert dmetas[0]['notes'] == 'rock city' |
91
|
|
|
assert dmetas[0]['year'] == 1900 |
92
|
|
|
assert dmetas[1]['value'] == 'Other' |
93
|
|
|
assert dmetas[1]['notes'] == 'unknown' |
94
|
|
|
assert dmetas[1]['year'] == 1700 |
95
|
|
|
new_session = await app.session() |
96
|
|
|
new_detroit = await new_session.g.V(detroit.id).next() |
97
|
|
|
assert new_detroit.zipcode == detroit.zipcode |
98
|
|
|
assert new_detroit.historical_name[-1].value == detroit.historical_name[ |
99
|
|
|
-1].value |
100
|
|
|
assert new_detroit.historical_name[-1].notes == detroit.historical_name[ |
101
|
|
|
-1].notes |
102
|
|
|
assert new_detroit.historical_name[-1].year == detroit.historical_name[ |
103
|
|
|
-1].year |
104
|
|
|
assert new_detroit.historical_name[0].value == detroit.historical_name[ |
105
|
|
|
0].value |
106
|
|
|
assert new_detroit.historical_name[0].notes == detroit.historical_name[ |
107
|
|
|
0].notes |
108
|
|
|
assert new_detroit.historical_name[0].year == detroit.historical_name[ |
109
|
|
|
0].year |
110
|
|
|
await remote_connection.close() |
111
|
|
|
await app.close() |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
@pytest.mark.skip(reason="Test not working on all backends") |
115
|
|
|
#@pytest.mark.xfail(pytest.config.getoption('provider') == 'dse', reason='temporary') |
116
|
|
|
@pytest.mark.asyncio |
117
|
|
|
async def test_add_update_metas(app, place): |
118
|
|
|
session = await app.session() |
119
|
|
|
place.historical_name = ['Detroit'] |
120
|
|
|
place.historical_name('Detroit').notes = 'rock city' |
121
|
|
|
place.historical_name('Detroit').year = 1900 |
122
|
|
|
result = await session.save(place) |
123
|
|
|
assert result.historical_name('Detroit').notes == 'rock city' |
124
|
|
|
assert result.historical_name('Detroit').year == 1900 |
125
|
|
|
|
126
|
|
|
place.historical_name('Detroit').notes = 'comeback city' |
127
|
|
|
place.historical_name('Detroit').year = 2016 |
128
|
|
|
result = await session.save(place) |
129
|
|
|
assert result.historical_name('Detroit').notes == 'comeback city' |
130
|
|
|
assert result.historical_name('Detroit').year == 2016 |
131
|
|
|
|
132
|
|
|
new_session = await app.session() |
133
|
|
|
result = await new_session.g.V(place.id).next() |
134
|
|
|
assert result.historical_name('Detroit').notes == 'comeback city' |
135
|
|
|
assert result.historical_name('Detroit').year == 2016 |
136
|
|
|
|
137
|
|
|
place.historical_name('Detroit').notes = None |
138
|
|
|
place.historical_name('Detroit').year = None |
139
|
|
|
result = await session.save(place) |
140
|
|
|
assert not result.historical_name('Detroit').notes |
141
|
|
|
assert not result.historical_name('Detroit').year |
142
|
|
|
await app.close() |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
|
146
|
|
|
@pytest.mark.skip(reason="Test not working on all backends") |
147
|
|
|
#@pytest.mark.xfail(pytest.config.getoption('provider') == 'dse', reason='temporary') |
148
|
|
|
@pytest.mark.asyncio |
149
|
|
|
async def test_add_update_metas_list_card(app, place): |
150
|
|
|
session = await app.session() |
151
|
|
|
place.historical_name = ['Hispania', 'Al-Andalus'] |
152
|
|
|
place.historical_name('Hispania').notes = 'romans' |
153
|
|
|
place.historical_name('Hispania').year = 200 |
154
|
|
|
place.historical_name('Al-Andalus').notes = 'muslims' |
155
|
|
|
place.historical_name('Al-Andalus').year = 700 |
156
|
|
|
result = await session.save(place) |
157
|
|
|
assert result.historical_name('Hispania').notes == 'romans' |
158
|
|
|
assert result.historical_name('Hispania').year == 200 |
159
|
|
|
assert result.historical_name('Al-Andalus').notes == 'muslims' |
160
|
|
|
assert result.historical_name('Al-Andalus').year == 700 |
161
|
|
|
|
162
|
|
|
place.historical_name('Hispania').notes = 'really old' |
163
|
|
|
place.historical_name('Hispania').year = 200 |
164
|
|
|
place.historical_name('Al-Andalus').notes = 'less old' |
165
|
|
|
place.historical_name('Al-Andalus').year = 700 |
166
|
|
|
result = await session.save(place) |
167
|
|
|
assert result.historical_name('Hispania').notes == 'really old' |
168
|
|
|
assert result.historical_name('Hispania').year == 200 |
169
|
|
|
assert result.historical_name('Al-Andalus').notes == 'less old' |
170
|
|
|
assert result.historical_name('Al-Andalus').year == 700 |
171
|
|
|
|
172
|
|
|
place.historical_name('Hispania').notes = None |
173
|
|
|
place.historical_name('Hispania').year = None |
174
|
|
|
place.historical_name('Al-Andalus').notes = None |
175
|
|
|
place.historical_name('Al-Andalus').year = None |
176
|
|
|
result = await session.save(place) |
177
|
|
|
assert not result.historical_name('Hispania').notes |
178
|
|
|
assert not result.historical_name('Hispania').year |
179
|
|
|
assert not result.historical_name('Al-Andalus').notes |
180
|
|
|
assert not result.historical_name('Al-Andalus').year |
181
|
|
|
await app.close() |
182
|
|
|
|