Code Duplication    Length = 45-49 lines in 2 locations

django-data/image/cryoweb/tests/test_helpers.py 2 locations

@@ 363-411 (lines=49) @@
360
        'language/speciesynonym'
361
    ]
362
363
    @patch('cryoweb.helpers.send_message_to_websocket')
364
    @patch('asyncio.get_event_loop')
365
    def test_cryoweb_import(
366
            self, asyncio_mock, send_message_to_websocket_mock):
367
        """Import from cryoweb staging database into UID, anche check that
368
        validationsummary is correct"""
369
370
        # stuff to simulating real time messages
371
        tmp = asyncio_mock.return_value
372
        tmp.run_until_complete = Mock()
373
374
        self.assertTrue(cryoweb_import(self.submission))
375
376
        # check breed upload
377
        queryset = DictBreed.objects.all()
378
379
        breeds = [(dictbreed.supplied_breed, dictbreed.country.label)
380
                  for dictbreed in queryset]
381
382
        self.assertEqual(len(queryset), 4)
383
        self.assertListEqual(
384
            breeds, [
385
                ('Bunte Bentheimer', 'United Kingdom'),
386
                ('Ostfriesisches Milchschaf', 'Italy'),
387
                ('Aberdeen Angus', 'Germany'),
388
                ('Ostfriesisches Milchschaf', 'Germany')],
389
            msg="Check breeds loaded")
390
391
        # check name upload (5 animal, 1 sample)
392
        queryset = Name.objects.filter(submission=self.submission)
393
        self.assertEqual(len(queryset), 6, msg='check name load')
394
395
        # check animal name
396
        queryset = Animal.objects.all()
397
        self.assertEqual(len(queryset), 3, msg="check animal load")
398
399
        queryset = Sample.objects.all()
400
        self.assertEqual(len(queryset), 1, msg="check sample load")
401
402
        self.assertEqual(asyncio_mock.call_count, 1)
403
        self.assertEqual(tmp.run_until_complete.call_count, 1)
404
        self.assertEqual(send_message_to_websocket_mock.call_count, 1)
405
        send_message_to_websocket_mock.assert_called_with(
406
            {'message': 'Loaded',
407
             'notification_message': 'Cryoweb import completed for '
408
                                     'submission: 1',
409
             'validation_message': {'animals': 3, 'samples': 1,
410
                                    'animal_unkn': 3, 'sample_unkn': 1,
411
                                    'animal_issues': 0, 'sample_issues': 0}}, 1)
412
@@ 273-317 (lines=45) @@
270
        self.assertEqual(
271
            settings.DATABASES['cryoweb']['NAME'], 'test_cryoweb')
272
273
    @patch('cryoweb.helpers.send_message_to_websocket')
274
    @patch('asyncio.get_event_loop')
275
    def test_cryoweb_import(self, asyncio_mock, send_message_to_websocket_mock):
276
        """Import from cryoweb staging database into UID"""
277
        tmp = asyncio_mock.return_value
278
        tmp.run_until_complete = Mock()
279
280
        self.assertTrue(cryoweb_import(self.submission))
281
282
        # check breed upload
283
        queryset = DictBreed.objects.all()
284
285
        breeds = [(dictbreed.supplied_breed, dictbreed.country.label)
286
                  for dictbreed in queryset]
287
288
        self.assertEqual(len(queryset), 4)
289
        self.assertListEqual(
290
            breeds, [
291
                ('Bunte Bentheimer', 'United Kingdom'),
292
                ('Ostfriesisches Milchschaf', 'Italy'),
293
                ('Aberdeen Angus', 'Germany'),
294
                ('Ostfriesisches Milchschaf', 'Germany')],
295
            msg="Check breeds loaded")
296
297
        # check name upload (5 animal, 1 sample)
298
        queryset = Name.objects.filter(submission=self.submission)
299
        self.assertEqual(len(queryset), 6, msg='check name load')
300
301
        # check animal name
302
        queryset = Animal.objects.all()
303
        self.assertEqual(len(queryset), 3, msg="check animal load")
304
305
        queryset = Sample.objects.all()
306
        self.assertEqual(len(queryset), 1, msg="check sample load")
307
308
        self.assertEqual(asyncio_mock.call_count, 1)
309
        self.assertEqual(tmp.run_until_complete.call_count, 1)
310
        self.assertEqual(send_message_to_websocket_mock.call_count, 1)
311
        send_message_to_websocket_mock.assert_called_with(
312
            {'message': 'Loaded',
313
             'notification_message': 'Cryoweb import completed for '
314
                                     'submission: 1',
315
             'validation_message': {'animals': 3, 'samples': 1,
316
                                    'animal_unkn': 3, 'sample_unkn': 1,
317
                                    'animal_issues': 0, 'sample_issues': 0}}, 1)
318
319
    @patch('cryoweb.helpers.send_message_to_websocket')
320
    @patch('asyncio.get_event_loop')