Code Duplication    Length = 50-50 lines in 2 locations

django-data/image/crbanim/tests/test_helpers.py 1 location

@@ 28-77 (lines=50) @@
25
from .common import BaseTestCase
26
27
28
class WebSocketMixin(object):
29
    """Override setUp to mock websocket objects"""
30
31
    def setUp(self):
32
        # calling my base class setup
33
        super().setUp()
34
35
        # setting channels methods
36
        self.asyncio_mock_patcher = patch(
37
            'asyncio.get_event_loop')
38
        self.asyncio_mock = self.asyncio_mock_patcher.start()
39
40
        # mocking asyncio return value
41
        self.run_until = self.asyncio_mock.return_value
42
        self.run_until.run_until_complete = Mock()
43
44
        # another patch
45
        self.send_msg_ws_patcher = patch(
46
            'crbanim.helpers.send_message_to_websocket')
47
        self.send_msg_ws = self.send_msg_ws_patcher.start()
48
49
    def tearDown(self):
50
        # stopping mock objects
51
        self.asyncio_mock_patcher.stop()
52
        self.send_msg_ws_patcher.stop()
53
54
        # calling base methods
55
        super().tearDown()
56
57
    def check_message(
58
            self, message, notification_message, validation_message=None,
59
            pk=1):
60
        """assert message to websocket called with parameters"""
61
62
        # construct message according parameters
63
        message = {
64
            'message': message,
65
            'notification_message': notification_message
66
        }
67
68
        # in case of successful data upload, a validation message is sent
69
        if validation_message:
70
            message['validation_message'] = validation_message
71
72
        self.assertEqual(self.asyncio_mock.call_count, 1)
73
        self.assertEqual(self.run_until.run_until_complete.call_count, 1)
74
        self.assertEqual(self.send_msg_ws.call_count, 1)
75
        self.send_msg_ws.assert_called_with(
76
            message,
77
            pk)
78
79
80
class CRBAnimMixin(WebSocketMixin):

django-data/image/cryoweb/tests/test_helpers.py 1 location

@@ 85-134 (lines=50) @@
82
        super().tearDownClass()
83
84
85
class WebSocketMixin(object):
86
    """Override setUp to mock websocket objects"""
87
88
    def setUp(self):
89
        # calling my base class setup
90
        super().setUp()
91
92
        # setting channels methods
93
        self.asyncio_mock_patcher = patch(
94
            'asyncio.get_event_loop')
95
        self.asyncio_mock = self.asyncio_mock_patcher.start()
96
97
        # mocking asyncio return value
98
        self.run_until = self.asyncio_mock.return_value
99
        self.run_until.run_until_complete = Mock()
100
101
        # another patch
102
        self.send_msg_ws_patcher = patch(
103
            'cryoweb.helpers.send_message_to_websocket')
104
        self.send_msg_ws = self.send_msg_ws_patcher.start()
105
106
    def tearDown(self):
107
        # stopping mock objects
108
        self.asyncio_mock_patcher.stop()
109
        self.send_msg_ws_patcher.stop()
110
111
        # calling base methods
112
        super().tearDown()
113
114
    def check_message(
115
            self, message, notification_message, validation_message=None,
116
            pk=1):
117
        """assert message to websocket called with parameters"""
118
119
        # construct message according parameters
120
        message = {
121
            'message': message,
122
            'notification_message': notification_message
123
        }
124
125
        # in case of successful data upload, a validation message is sent
126
        if validation_message:
127
            message['validation_message'] = validation_message
128
129
        self.assertEqual(self.asyncio_mock.call_count, 1)
130
        self.assertEqual(self.run_until.run_until_complete.call_count, 1)
131
        self.assertEqual(self.send_msg_ws.call_count, 1)
132
        self.send_msg_ws.assert_called_with(
133
            message,
134
            pk)
135
136
137
class ImportMixin(WebSocketMixin, CryoWebMixin):