Skip to content

Commit

Permalink
Merge pull request #25 from exonet/parser-decode
Browse files Browse the repository at this point in the history
Decode JSON content when parsing API results
  • Loading branch information
trizz authored Nov 8, 2021
2 parents e3bdc3c + e4c115f commit 4f4d551
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yaml]
indent_size = 2
35 changes: 35 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
run-tests:
name: 🪲 Run tests
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- name: 📥 Checkout repository
uses: actions/checkout@v2

- name: 🛠 Set up Python all python version
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: 📦 Install dependencies
run: pip install -r requirements.txt

- name: 🧰 Run unit tests
run: python -m unittest discover tests
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
Exonet API python package
=========================
Python 3 library for the Exonet API.

.. image:: https://img.shields.io/pypi/v/exonetapi.svg?style=flat-square
.. image:: https://img.shields.io/pypi/pyversions/exonetapi.svg?style=flat-square
.. image:: https://img.shields.io/pypi/l/exonetapi.svg?style=flat-square
.. image:: https://img.shields.io/lgtm/grade/python/g/exonet/exonet-api-python.svg
:target: https://lgtm.com/projects/g/exonet/exonet-api-python/context:python

Python 3 library for the Exonet API.
.. image:: https://img.shields.io/pypi/l/exonetapi.svg?style=flat-square

Conventions
-----------
Expand Down
2 changes: 1 addition & 1 deletion exonetapi/result/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Parser:

def __init__(self, data):
self.__data = data
self.__json = json.loads(self.__data)
self.__json = json.loads(self.__data.decode())
self.__json_data = self.__json.get('data')

def parse(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'Topic :: Software Development :: Libraries :: Python Modules',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.9',
],

packages=find_packages(exclude=['contrib', 'docs', 'tests']),
Expand Down
6 changes: 3 additions & 3 deletions tests/result/testParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_parse_list(self):
}
"""

result = Parser(json_data_list).parse().resources()
result = Parser(str.encode(json_data_list)).parse().resources()

self.assertEqual(result[0].id(), 'DV6axK4GwNEb')
self.assertEqual(result[0].type(), 'comments')
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_parse_single(self):
}
"""

result = Parser(json_data_list).parse()
result = Parser(str.encode(json_data_list)).parse()

self.assertEqual(result.id(), 'DV6axK4GwNEb')
self.assertEqual(result.type(), 'comments')
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_parse_single_with_multi_relation(self):
}
"""

result = Parser(json_data_list).parse().relationship('tags').get_resource_identifiers()
result = Parser(str.encode(json_data_list)).parse().relationship('tags').get_resource_identifiers()

self.assertEqual(len(result), 2)

Expand Down
8 changes: 4 additions & 4 deletions tests/testRequestBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,19 @@ def test_post_validation_error(self, mock_validation_exception, mock_requests_re
def test_get_recursive(self, mock_requests_request):
result_one = Response()
result_one.status_code = 200
result_one._content = '{"data": ' \
result_one._content = str.encode('{"data": ' \
'[{"type": "test", "id": "abc"}], ' \
'"meta": {"total": 2}, ' \
'"links": {"next": "https://api.exonet.nl/next_page"}' \
'}'
'}')

result_two = Response()
result_two.status_code = 200
result_two._content = '{"data": ' \
result_two._content = str.encode('{"data": ' \
'[{"type": "test", "id": "def"}], ' \
'"meta": {"total": 2}, ' \
'"links": {"next": null}' \
'}'
'}')

request_result = [result_one, result_two]
mock_requests_request.side_effect = request_result
Expand Down

0 comments on commit 4f4d551

Please sign in to comment.