Code Duplication    Length = 50-50 lines in 2 locations

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

@@ 114-163 (lines=50) @@
111
        self.assertEqual(len(queryset), 1, msg="check sample load")
112
113
114
class WebSocketMixin(object):
115
    """Override setUp to mock websocket objects"""
116
117
    def setUp(self):
118
        # calling my base class setup
119
        super().setUp()
120
121
        # setting channels methods
122
        self.asyncio_mock_patcher = patch(
123
            'asyncio.get_event_loop')
124
        self.asyncio_mock = self.asyncio_mock_patcher.start()
125
126
        # mocking asyncio return value
127
        self.run_until = self.asyncio_mock.return_value
128
        self.run_until.run_until_complete = Mock()
129
130
        # another patch
131
        self.send_msg_ws_patcher = patch(
132
            'cryoweb.helpers.send_message_to_websocket')
133
        self.send_msg_ws = self.send_msg_ws_patcher.start()
134
135
    def tearDown(self):
136
        # stopping mock objects
137
        self.asyncio_mock_patcher.stop()
138
        self.send_msg_ws_patcher.stop()
139
140
        # calling base methods
141
        super().tearDown()
142
143
    def check_message(
144
            self, message, notification_message, validation_message=None,
145
            pk=1):
146
        """assert message to websocket called with parameters"""
147
148
        # construct message according parameters
149
        message = {
150
            'message': message,
151
            'notification_message': notification_message
152
        }
153
154
        # in case of successful data upload, a validation message is sent
155
        if validation_message:
156
            message['validation_message'] = validation_message
157
158
        self.assertEqual(self.asyncio_mock.call_count, 1)
159
        self.assertEqual(self.run_until.run_until_complete.call_count, 1)
160
        self.assertEqual(self.send_msg_ws.call_count, 1)
161
        self.send_msg_ws.assert_called_with(
162
            message,
163
            pk)
164
165
166
class CheckSpecie(CryoWebMixin, BaseTestCase, TestCase):

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 CRBAnimReaderTestCase(BaseTestCase, TestCase):