| Total Complexity | 2 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # !/usr/bin/python |
||
| 2 | # -*- coding: utf-8 -*- |
||
| 3 | import json |
||
| 4 | import unittest |
||
| 5 | from time import time |
||
| 6 | |||
| 7 | from kuon.api_response import APIResponse |
||
| 8 | from kuon.watcher.adapters.models.item import Item |
||
| 9 | from kuon.watcher.adapters.models.search_response import SearchResponse |
||
| 10 | from kuon.watcher.adapters.models.sticker import Sticker |
||
| 11 | |||
| 12 | |||
| 13 | class TestSearchResponse(unittest.TestCase): |
||
| 14 | """Test cases for the search response model like proper JSON dump and ability to parse to APIResponse object""" |
||
| 15 | |||
| 16 | def setUp(self) -> None: |
||
| 17 | """Set up the item to add |
||
| 18 | |||
| 19 | :return: |
||
| 20 | """ |
||
| 21 | sticker = Sticker( |
||
| 22 | name="Howling Dawn", |
||
| 23 | image="some_sticker_image_link", |
||
| 24 | wear_value=0.43092 |
||
| 25 | ) |
||
| 26 | |||
| 27 | self._item = Item( |
||
| 28 | market_name='some_market_name', |
||
| 29 | item_id='abc123', |
||
| 30 | app_id=730, |
||
| 31 | class_id=12345, |
||
| 32 | context_id=2, |
||
| 33 | instance_id=54321, |
||
| 34 | price=109999, |
||
| 35 | wear_value=0.14305446, |
||
| 36 | image="some_item_image_link", |
||
| 37 | inspect_link="some_steam_inspect_link", |
||
| 38 | stickers=[sticker] |
||
| 39 | ) |
||
| 40 | |||
| 41 | def test_response(self) -> None: |
||
| 42 | """Test the conversion to the APIResponse object and the json.dumps |
||
| 43 | |||
| 44 | :return: |
||
| 45 | """ |
||
| 46 | response = SearchResponse(success=True, checked_time=time()) |
||
| 47 | response.add_item(self._item) |
||
| 48 | json_response_dump = json.dumps(response.__dict__) |
||
| 49 | api_response = APIResponse(json_response_dump) |
||
| 50 | self.assertEqual(api_response.data.success, True) |
||
| 51 | |||
| 52 | |||
| 53 | if __name__ == '__main__': |
||
| 54 | suite = unittest.TestLoader().loadTestsFromTestCase(TestSearchResponse) |
||
| 55 | unittest.TextTestRunner(verbosity=2).run(suite) |
||
| 56 |