Skip to content

Commit ef2be18

Browse files
committed
fix tests
1 parent 6258a48 commit ef2be18

File tree

4 files changed

+66
-20
lines changed

4 files changed

+66
-20
lines changed

src/quickbase_json/qb_response.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@ def __init__(self, response_type, **kwargs):
2222
self.update(kwargs.get('sample_data'))
2323
super().__init__()
2424

25-
def info(self):
25+
def info(self, prt=True):
2626
"""
2727
Prints information about the response.
28+
:prt: Set to False to only grab the return as a string.
2829
"""
2930
if self.response_type == 'records':
30-
31-
print(f'{Bcolors.OKBLUE}Sample Data:\n')
31+
info = []
32+
info.append(f'{Bcolors.OKBLUE}Sample Data:\n')
3233
try:
33-
print('\t', self.get('data')[0], '\n')
34+
info.append('\t' + str(self.get('data')[0]) + '\n\n')
3435
except KeyError as e:
35-
print('\t', self.get('data'), '\n')
36-
print(Bcolors.ENDC)
37-
print(f'{Bcolors.OKGREEN}Fields:\n')
36+
info.append('\t' + str(self.get('data')) + '\n')
37+
info.append(Bcolors.ENDC)
38+
info.append(f'{Bcolors.OKGREEN}Fields:\n')
3839

3940
fields_info = []
4041
for field in self.get('fields'):
@@ -46,13 +47,20 @@ def info(self):
4647

4748
# print field info
4849
for fi in fields_info:
49-
print('\t', '{:<16s} {:<32s} {:<16s}'.format(fi[0], fi[1], fi[2]))
50-
print(Bcolors.ENDC)
50+
info.append('\t' + '{:<16s} {:<32s} {:<16s}\n'.format(fi[0], fi[1], fi[2]))
51+
info.append(Bcolors.ENDC)
5152

52-
print(f'\n{Bcolors.OKCYAN}Metadata:\n')
53+
info.append(f'\n{Bcolors.OKCYAN}Metadata:\n')
5354
for k, v in self.get('metadata').items():
54-
print('\t{:<16s} {:<16s}'.format(k, str(v)))
55-
print(Bcolors.ENDC)
55+
info.append('\t{:<16s} {:<16s}\n'.format(k, str(v)))
56+
info.append(Bcolors.ENDC)
57+
58+
info_str = ''.join(info)
59+
60+
if prt:
61+
print(info_str)
62+
63+
return info_str
5664

5765
def fields(self, prop):
5866
"""

tests/sample_data.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,29 @@
3535
"numFields": 3,
3636
"skip": 0
3737
}
38-
}
38+
}
39+
40+
record_data_load = {'data': [{'6': {'value': 'Andre Harris'},
41+
'7': {'value': 10},
42+
'8': {'value': '2019-12-18T08:00:00.000Z'}}],
43+
'fields': [{'id': 6, 'label': 'Full Name', 'type': 'text'},
44+
{'id': 7, 'label': 'Amount', 'type': 'numeric'},
45+
{'id': 8, 'label': 'Date time', 'type': 'date time'}],
46+
'metadata': {'numFields': 3, 'numRecords': 1, 'skip': 0, 'totalRecords': 10}}
47+
48+
record_data_get_info = """
49+
Sample Data:
50+
{'6': {'value': 'Andre Harris'}, '7': {'value': 10}, '8': {'value': '2019-12-18T08:00:00.000Z'}}
51+
52+
Fields:
53+
id: 6 label: Full Name type: text
54+
id: 7 label: Amount type: numeric
55+
id: 8 label: Date time type: date time
56+

57+
Metadata:
58+
totalRecords 10
59+
numRecords 1
60+
numFields 3
61+
skip 0
62+

63+
"""

tests/test_client.py renamed to tests/test_helpers.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
2-
31
import pytest
42

5-
6-
7-
83
# test where
9-
from quickbase_json.helpers import Where, IncorrectParameters
4+
from src.quickbase_json.helpers import Where, IncorrectParameters
105

116

127
@pytest.mark.parametrize('fid, operator, value, expected', [
@@ -30,4 +25,3 @@ def test_where_join(fid, operator, value, expected):
3025
def test_invalid_params():
3126
with pytest.raises(IncorrectParameters):
3227
Where(3, 'EX', 12345).build(join='OR')
33-

tests/test_response.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
# test where
4+
from src.quickbase_json.qb_response import QBResponse
5+
from src.quickbase_json.helpers import Where, IncorrectParameters
6+
from tests import sample_data
7+
8+
9+
# test loading in data
10+
@pytest.mark.parametrize('data, expected', [
11+
(sample_data.record_data, sample_data.record_data_load)
12+
])
13+
def test_load(data, expected):
14+
assert QBResponse('records', sample_data=data) == expected
15+
16+
17+
# test getting info, basic tests, does not test formatting
18+
def test_get_info():
19+
assert "{'6': {'value': 'Andre Harris'}, '7': {'value': 10}, '8': {'value': '2019-12-18T08:00:00.000Z'}}" in QBResponse('records', sample_data=sample_data.record_data).info(prt=False)

0 commit comments

Comments
 (0)