diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3a2a5d7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: python +python: + - "3.7" +install: + - pipenv install --dev +script: + - pipenv run pytest diff --git a/Pipfile b/Pipfile index ea46530..57a2a7c 100644 --- a/Pipfile +++ b/Pipfile @@ -5,10 +5,12 @@ verify_ssl = true [dev-packages] pytest = "*" +requests-mock = "*" [packages] requests = "*" structlog = "*" +attr = "*" [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index d8ff959..64fb70d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8f1c2617e2d35a7fba5feecc973dfb845aafbc0e16cbedddc3a50d7c23f768d9" + "sha256": "f0f4eb8bc3615617b266bbd7623ed39a1954441f310c8d9f28b4e3c25a8509fc" }, "pipfile-spec": 6, "requires": { @@ -16,6 +16,14 @@ ] }, "default": { + "attr": { + "hashes": [ + "sha256:0b1aaddb85bd9e9c4bd75092f4440d6616ff40b0df0437f00771871670f7c9fd", + "sha256:9091548058d17f132596e61fa7518e504f76b9a4c61ca7d86e1f96dbf7d4775d" + ], + "index": "pypi", + "version": "==0.3.1" + }, "certifi": { "hashes": [ "sha256:e4f3620cfea4f83eedc95b24abd9cd56f3c4b146dd0177e83a21b4eb49e21e50", @@ -45,6 +53,14 @@ "index": "pypi", "version": "==2.22.0" }, + "requests-mock": { + "hashes": [ + "sha256:510df890afe08d36eca5bb16b4aa6308a6f85e3159ad3013bac8b9de7bd5a010", + "sha256:88d3402dd8b3c69a9e4f9d3a73ad11b15920c6efd36bc27bf1f701cf4a8e4646" + ], + "index": "pypi", + "version": "==1.7.0" + }, "six": { "hashes": [ "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd", diff --git a/tests/test_models.py b/tests/test_models.py index d66fd1d..7b6cbaf 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,3 +1,4 @@ +import attr import pytest import requests_mock @@ -6,13 +7,25 @@ @pytest.fixture def client(): - pass + with requests_mock.Mocker() as m: + uri1 = 'mock://example.com/rest/login' + uri2 = 'mock://example.com/rest/status' + cookies = {'JSESSIONID': '11111111'} + json_object = {'fullname': 'User Name'} + m.post(uri1, cookies=cookies) + m.get(uri2, json=json_object) + client = models.Client('mock://example.com', 'test', 'test') + return client -# def test_get_record(client): -# """Test get_record function.""" -# rec_obj = client.get_record(uuid, rec_type) -# assert False +def test_get_record(client): + """Test get_record function.""" + with requests_mock.Mocker() as m: + uri = '/rest/items/123?expand=all' + json_object = {'metadata': {'title': 'Sample title'}, 'type': 'item'} + m.get(uri, json=json_object) + rec_obj = client.get_record('123', 'items') + assert attr.asdict(rec_obj)['metadata'] == json_object['metadata'] # def test_filtered_item_search(client):