kuon.watcher.adapters.models.sold_history   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
wmc 7
eloc 25
dl 0
loc 65
ccs 12
cts 21
cp 0.5714
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A SoldHistory.__init__() 0 12 2
A SoldHistory.add_sale() 0 8 2
A SoldHistory.value() 0 10 1
A SoldHistory.sold_items() 0 8 1
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4 1
from typing import List
5
6 1
from kuon.watcher.adapters.models import AbstractEntity
7 1
from kuon.watcher.adapters.models.sold_item import SoldItem
8
9
10 1
class SoldHistory(AbstractEntity):
11
    """General Sold History Response from the APIs"""
12
13 1
    def __init__(self, success: bool, sold_items: List[SoldItem] = None) -> None:
14
        """Initializing function
15
16
        :type success: bool
17
        :type sold_items: List[SoldItem]
18
        """
19
        self._success = success
20
21
        if sold_items:
22
            self._sold_items = sold_items
23
        else:
24
            self._sold_items = []
25
26 1
    @property
27 1
    def value(self) -> dict:
28
        """Return all important information from the API response like success and sold items
29
30
        :return:
31
        """
32
        return {
33
            'data': {
34
                'success': self._success,
35
                'sales': self.sold_items
36
            }
37
        }
38
39 1
    @property
40 1
    def sold_items(self) -> list:
41
        """Property for sold items which returns __dict__ of the sold item objects
42
        to allow JSON dump the search response without custom JSONEncoder objects
43
44
        :return:
45
        """
46
        return [i.__dict__ for i in self._sold_items]
47
48 1
    @sold_items.setter
49 1
    def sold_items(self, sold_items: List[SoldItem]) -> None:
50
        """Setter for sold items
51
52
        :type sold_items: List[SoldItem]
53
        :return:
54
        """
55
        self._sold_items = sold_items
56
57 1
    def add_sale(self, sold_item: SoldItem) -> None:
58
        """Adder for sold items
59
60
        :type sold_item: SoldItem
61
        :return:
62
        """
63
        if sold_item not in self._sold_items:
64
            self._sold_items.append(sold_item)
65