-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
167 lines (136 loc) · 3.99 KB
/
tests.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import uuid
import pytest
from sheet2api import Sheet2APIClient
URL = (
'https://sheet2api.com/v1/FgI6zV8qT121/'
'testing-sheet-simple_python_client_read_write/'
)
URL_AUTH = (
'https://sheet2api.com/v1/FgI6zV8qT121/'
'testing-sheet-simple_python_client_read_auth/'
)
@pytest.fixture
def client():
return Sheet2APIClient(api_url=URL)
@pytest.fixture
def client_with_auth():
return Sheet2APIClient(
api_url=URL_AUTH, username='mruser', password='mrpassword'
)
class TestReadRows:
@pytest.mark.parametrize('client_fixture', ['client', 'client_with_auth'])
def test_returns_all_rows_in_spreadsheet(self, client_fixture, request):
client = request.getfixturevalue(client_fixture)
rows = client.get_rows()
assert rows == [{
'name': 'Bob',
'age': 22
}, {
'name': 'Richard',
'age': 19
}, {
'name': 'Bob Jones',
'age': 99
}]
def test_returns_all_rows_for_a_specific_sheet(self, client):
rows = client.get_rows(sheet='Address')
assert rows == [{
'name': 'Bob',
'address': 'Bob Street'
}, {
'name': 'Richard',
'address': 'Richard Street'
}]
def test_returns_filtered_rows_when_query_is_passed(self, client):
rows = client.get_rows(query={'name': 'Bob'})
assert rows == [{'name': 'Bob', 'age': 22}]
class TestCreateRow:
@pytest.mark.parametrize('sheet', [None, 'Age'])
def test_creates_a_new_row(self, client, request, sheet):
name = str(uuid.uuid4())
row = {
'name': name,
'age': 18,
}
def fin():
client.delete_rows(sheet=sheet, query={'name': name})
request.addfinalizer(fin)
added_row = client.create_row(sheet=sheet, row=row)
assert added_row == row
assert client.get_rows(sheet=sheet) == [row] + [{
'name': 'Bob',
'age': 22
}, {
'name': 'Richard',
'age': 19
}, {
'name': 'Bob Jones',
'age': 99
}]
class TestUpdateRows:
@pytest.mark.parametrize('sheet', [None, 'Age'])
def test_update_rows(self, client, sheet, request):
name = str(uuid.uuid4())
row = {
'name': name,
'age': 18,
}
def fin():
client.delete_rows(sheet=sheet, query={'name': name})
request.addfinalizer(fin)
client.create_row(sheet=sheet, row=row)
updates_made = client.update_rows(
sheet=sheet,
query={'name': name},
row={
'name': name,
'age': 99999
},
)
assert updates_made == [{'name': name, 'age': 99999}]
assert client.get_rows(sheet=sheet) == [{
'name': name,
'age': 99999
}, {
'name': 'Bob',
'age': 22
}, {
'name': 'Richard',
'age': 19
}, {
'name': 'Bob Jones',
'age': 99
}]
def test_update_rows_partially(self, client, request):
sheet = None
name = str(uuid.uuid4())
row = {
'name': name,
'age': 18,
}
def fin():
client.delete_rows(sheet=sheet, query={'name': name})
request.addfinalizer(fin)
client.create_row(sheet=sheet, row=row)
updates_made = client.update_rows(
sheet=sheet,
query={'name': name},
row={
'name': name,
},
partial_update=True,
)
assert updates_made == [{'name': name}]
assert client.get_rows(sheet=sheet) == [{
'name': name,
'age': 18
}, {
'name': 'Bob',
'age': 22
}, {
'name': 'Richard',
'age': 19
}, {
'name': 'Bob Jones',
'age': 99
}]