Skip to content

Commit 4f4d551

Browse files
authored
Merge pull request #25 from exonet/parser-decode
Decode JSON content when parsing API results
2 parents e3bdc3c + e4c115f commit 4f4d551

File tree

7 files changed

+49
-12
lines changed

7 files changed

+49
-12
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ end_of_line = lf
88
charset = utf-8
99
trim_trailing_whitespace = true
1010
insert_final_newline = true
11+
12+
[*.yaml]
13+
indent_size = 2

.github/workflows/ci.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: CI
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
branches:
10+
- master
11+
12+
jobs:
13+
run-tests:
14+
name: 🪲 Run tests
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
python-version: [3.6, 3.7, 3.8, 3.9]
20+
21+
steps:
22+
- name: 📥 Checkout repository
23+
uses: actions/checkout@v2
24+
25+
- name: 🛠 Set up Python all python version
26+
uses: actions/setup-python@v2
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
architecture: x64
30+
31+
- name: 📦 Install dependencies
32+
run: pip install -r requirements.txt
33+
34+
- name: 🧰 Run unit tests
35+
run: python -m unittest discover tests

README.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
Exonet API python package
22
=========================
3+
Python 3 library for the Exonet API.
34

45
.. image:: https://img.shields.io/pypi/v/exonetapi.svg?style=flat-square
56
.. image:: https://img.shields.io/pypi/pyversions/exonetapi.svg?style=flat-square
6-
.. image:: https://img.shields.io/pypi/l/exonetapi.svg?style=flat-square
77
.. image:: https://img.shields.io/lgtm/grade/python/g/exonet/exonet-api-python.svg
88
:target: https://lgtm.com/projects/g/exonet/exonet-api-python/context:python
9-
10-
Python 3 library for the Exonet API.
9+
.. image:: https://img.shields.io/pypi/l/exonetapi.svg?style=flat-square
1110

1211
Conventions
1312
-----------

exonetapi/result/Parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Parser:
1414

1515
def __init__(self, data):
1616
self.__data = data
17-
self.__json = json.loads(self.__data)
17+
self.__json = json.loads(self.__data.decode())
1818
self.__json_data = self.__json.get('data')
1919

2020
def parse(self):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'Topic :: Software Development :: Libraries :: Python Modules',
4141
'License :: OSI Approved :: MIT License',
4242
'Programming Language :: Python :: 3.4',
43-
'Programming Language :: Python :: 3.6',
43+
'Programming Language :: Python :: 3.9',
4444
],
4545

4646
packages=find_packages(exclude=['contrib', 'docs', 'tests']),

tests/result/testParser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_parse_list(self):
5151
}
5252
"""
5353

54-
result = Parser(json_data_list).parse().resources()
54+
result = Parser(str.encode(json_data_list)).parse().resources()
5555

5656
self.assertEqual(result[0].id(), 'DV6axK4GwNEb')
5757
self.assertEqual(result[0].type(), 'comments')
@@ -85,7 +85,7 @@ def test_parse_single(self):
8585
}
8686
"""
8787

88-
result = Parser(json_data_list).parse()
88+
result = Parser(str.encode(json_data_list)).parse()
8989

9090
self.assertEqual(result.id(), 'DV6axK4GwNEb')
9191
self.assertEqual(result.type(), 'comments')
@@ -121,7 +121,7 @@ def test_parse_single_with_multi_relation(self):
121121
}
122122
"""
123123

124-
result = Parser(json_data_list).parse().relationship('tags').get_resource_identifiers()
124+
result = Parser(str.encode(json_data_list)).parse().relationship('tags').get_resource_identifiers()
125125

126126
self.assertEqual(len(result), 2)
127127

tests/testRequestBuilder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,19 @@ def test_post_validation_error(self, mock_validation_exception, mock_requests_re
284284
def test_get_recursive(self, mock_requests_request):
285285
result_one = Response()
286286
result_one.status_code = 200
287-
result_one._content = '{"data": ' \
287+
result_one._content = str.encode('{"data": ' \
288288
'[{"type": "test", "id": "abc"}], ' \
289289
'"meta": {"total": 2}, ' \
290290
'"links": {"next": "https://api.exonet.nl/next_page"}' \
291-
'}'
291+
'}')
292292

293293
result_two = Response()
294294
result_two.status_code = 200
295-
result_two._content = '{"data": ' \
295+
result_two._content = str.encode('{"data": ' \
296296
'[{"type": "test", "id": "def"}], ' \
297297
'"meta": {"total": 2}, ' \
298298
'"links": {"next": null}' \
299-
'}'
299+
'}')
300300

301301
request_result = [result_one, result_two]
302302
mock_requests_request.side_effect = request_result

0 commit comments

Comments
 (0)