From b1ffdfcd5a6fdd9fe298cc94b88ffd0d620169d2 Mon Sep 17 00:00:00 2001 From: Oleg Kozlov Date: Sun, 9 Sep 2018 00:15:32 +0300 Subject: [PATCH] tests of items api --- tests/test_items_api.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/test_items_api.py diff --git a/tests/test_items_api.py b/tests/test_items_api.py new file mode 100644 index 0000000..5b92a23 --- /dev/null +++ b/tests/test_items_api.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- + +import os +import json +from unittest import mock + +import vcr + +from pyswrve import ItemsApi + + +class TestItemsApi: + """ Class for testing ItemsApi methods. + Before testing: + 1. Save `api_key` and `personal_key` to `$HOME/.pyswrve` + 2. Create and modify `tests/names.json` + """ + + cassette_path = 'tests/vcr_cassettes/%s.yml' + skip_lst = ['api_key', 'personal_key'] + + names_path = 'tests/names.json' + with open(names_path) as jf: + names_dct = json.load(jf) + + @vcr.use_cassette(cassette_path % 'item-lst', + filter_query_parameters=skip_lst) + def test_get_item_lst(self): + api = ItemsApi() + res = api.get_item_lst() + assert isinstance(res, list) + assert isinstance(res[0], dict) + + @mock.patch.dict(os.environ, names_dct['item']) + @vcr.use_cassette(cassette_path % 'item-attrs', + filter_query_parameters=skip_lst) + def test_get_item_attrs(self): + api = ItemsApi() + uid = os.environ['uid'] + res = api.get_item_attrs(uid) + assert isinstance(res, dict)