Passed
Push — master ( 684169...29f120 )
by Rafael S.
01:50
created

TestAccumulateExercise01   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
dl 0
loc 35
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A test_accumulator1_price() 0 3 1
A test_accumulator2_results() 0 3 1
A test_accumulator2_quantity() 0 3 1
A test_accumulator1_results() 0 3 1
A setUp() 0 8 1
A test_accumulator2_price() 0 3 1
A test_accumulator1_quantity() 0 3 1
1
"""Test the accumulation of Exercise operations."""
2
3
from __future__ import absolute_import
4
5
import unittest
6
import copy
7
from trade_app.trade.holder import Accumulator
8
9
from fixtures.assets import ASSET, OPTION1
10
from fixtures.operations import (
11
    OPTION_OPERATION3, EXERCISE_OPERATION5, OPERATION54,
12
    EXERCISE_OPERATION5
13
)
14
15
16
class TestAccumulateExercise(unittest.TestCase):
17
    """Base class for Exercise accumulation tests."""
18
19
    def setUp(self):
20
        self.option_accumulator = Accumulator(OPTION1)
21
        self.subject_accumulator = Accumulator(ASSET)
22
        self.exercise = copy.deepcopy(EXERCISE_OPERATION5)
23
24
    def fetch_and_accumulate(self):
25
        """Accumulate a exercise operation on the asset accumulator.
26
27
        and on the option accumulator When accumulating operations,
28
        the Operation object should be passed to the accumulator
29
        of all its assets.
30
        """
31
        self.exercise.fetch_operations()
32
        for operation in self.exercise.operations:
33
            self.subject_accumulator.accumulate(operation)
34
            self.option_accumulator.accumulate(operation)
35
36
37
class TestAccumulateExercise00(TestAccumulateExercise):
38
    """Accumulate a Option operation, and then its Exercise operation."""
39
40
    def setUp(self):
41
        super(TestAccumulateExercise00, self).setUp()
42
        self.option_accumulator.accumulate(
43
            copy.deepcopy(OPTION_OPERATION3)
44
        )
45
        self.fetch_and_accumulate()
46
47
    def test_accumulator1_price(self):
48
        """Check the cost of the asset on the accumulator."""
49
        self.assertEqual(self.subject_accumulator.state['price'], 10)
50
51
    def test_accumulator1_quantity(self):
52
        """Check the quantity of the asset on the accumulator."""
53
        self.assertEqual(self.subject_accumulator.state['quantity'], 100)
54
55
    def test_accumulator1_results(self):
56
        """Check the results of the asset on the accumulator."""
57
        self.assertEqual(self.subject_accumulator.state['results'], {})
58
59
    def test_accumulator2_price(self):
60
        """Check the cost of the option on the accumulator."""
61
        self.assertEqual(self.option_accumulator.state['price'], 0)
62
63
    def test_accumulator2_quantity(self):
64
        """Check the quantity of the option on the accumulator."""
65
        self.assertEqual(self.option_accumulator.state['quantity'], 0)
66
67
    def test_accumulator2_results(self):
68
        """Check the results of the option on the accumulator."""
69
        self.assertEqual(self.option_accumulator.state['results'], {})
70
71
72
class TestAccumulateExercise01(TestAccumulateExercise):
73
    """Accumulate a operation, an option and then the exericse."""
74
75
    def setUp(self):
76
        super(TestAccumulateExercise01, self).setUp()
77
        self.operation0 = copy.deepcopy(OPERATION54)
78
        self.subject_accumulator.accumulate(self.operation0)
79
        self.operation1 = copy.deepcopy(OPTION_OPERATION3)
80
        self.option_accumulator.accumulate(self.operation1)
81
        self.exercise = copy.deepcopy(EXERCISE_OPERATION5)
82
        self.fetch_and_accumulate()
83
84
    def test_accumulator1_price(self):
85
        """Check the cost of the asset on the accumulator."""
86
        self.assertEqual(self.subject_accumulator.state['price'], 7.5)
87
88
    def test_accumulator1_quantity(self):
89
        """Check the quantity of the asset on the accumulator."""
90
        self.assertEqual(self.subject_accumulator.state['quantity'], 200)
91
92
    def test_accumulator1_results(self):
93
        """Check the results of the asset on the accumulator."""
94
        self.assertEqual(self.subject_accumulator.state['results'], {})
95
96
    def test_accumulator2_price(self):
97
        """Check the cost of the option on the accumulator."""
98
        self.assertEqual(self.option_accumulator.state['price'], 0)
99
100
    def test_accumulator2_quantity(self):
101
        """Check the quantity of the option on the accumulator."""
102
        self.assertEqual(self.option_accumulator.state['quantity'], 0)
103
104
    def test_accumulator2_results(self):
105
        """Check the results of the option on the accumulator."""
106
        self.assertEqual(self.option_accumulator.state['results'], {})
107