Passed
Push — master ( 272d30...b93c80 )
by Steffen
01:01
created

TestSearchResponse.test_response()   A

Complexity

Conditions 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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