1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
""" |
4
|
|
|
Created on Tue Sep 24 16:25:51 2019 |
5
|
|
|
|
6
|
|
|
@author: Paolo Cozzi <[email protected]> |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
from unittest.mock import patch |
10
|
|
|
|
11
|
|
|
from django.core.management import call_command |
12
|
|
|
from django.test import TestCase |
13
|
|
|
|
14
|
|
|
from image_app.models import DictBreed, DictCountry, DictSpecie, DictUberon |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class CommandsTestCase(TestCase): |
18
|
|
|
fixtures = [ |
19
|
|
|
'image_app/dictbreed', |
20
|
|
|
'image_app/dictcountry', |
21
|
|
|
'image_app/dictrole', |
22
|
|
|
'image_app/dictsex', |
23
|
|
|
'image_app/dictspecie', |
24
|
|
|
'image_app/dictstage', |
25
|
|
|
'image_app/dictuberon', |
26
|
|
|
] |
27
|
|
|
|
28
|
|
|
@classmethod |
29
|
|
|
def setUpClass(cls): |
30
|
|
|
"""Purging terms from database""" |
31
|
|
|
|
32
|
|
|
super().setUpClass() |
33
|
|
|
|
34
|
|
|
DictBreed.objects.update(mapped_breed_term=None) |
35
|
|
|
DictCountry.objects.update(term=None) |
36
|
|
|
DictSpecie.objects.update(term=None) |
37
|
|
|
DictUberon.objects.update(term=None) |
38
|
|
|
|
39
|
|
|
@patch('zooma.helpers.annotate_breed') |
40
|
|
|
def test_annotate_breeds(self, my_func): |
41
|
|
|
"Test annotate_breeds command" |
42
|
|
|
|
43
|
|
|
# mocking objects |
44
|
|
|
args = [] |
45
|
|
|
opts = {} |
46
|
|
|
call_command('annotate_breeds', *args, **opts) |
47
|
|
|
|
48
|
|
|
self.assertTrue(my_func.called) |
49
|
|
|
|
50
|
|
|
@patch('zooma.helpers.annotate_country') |
51
|
|
|
def test_annotate_countries(self, my_func): |
52
|
|
|
"Test annotate_countries command" |
53
|
|
|
|
54
|
|
|
# mocking objects |
55
|
|
|
args = [] |
56
|
|
|
opts = {} |
57
|
|
|
call_command('annotate_countries', *args, **opts) |
58
|
|
|
|
59
|
|
|
self.assertTrue(my_func.called) |
60
|
|
|
|
61
|
|
|
@patch('zooma.helpers.annotate_specie') |
62
|
|
|
def test_annotate_species(self, my_func): |
63
|
|
|
"Test annotate_species command" |
64
|
|
|
|
65
|
|
|
# mocking objects |
66
|
|
|
args = [] |
67
|
|
|
opts = {} |
68
|
|
|
call_command('annotate_species', *args, **opts) |
69
|
|
|
|
70
|
|
|
self.assertTrue(my_func.called) |
71
|
|
|
|
72
|
|
|
@patch('zooma.helpers.annotate_uberon') |
73
|
|
|
def test_annotate_uberon(self, my_func): |
74
|
|
|
"Test annotate_uberon command" |
75
|
|
|
|
76
|
|
|
# mocking objects |
77
|
|
|
args = [] |
78
|
|
|
opts = {} |
79
|
|
|
call_command('annotate_uberon', *args, **opts) |
80
|
|
|
|
81
|
|
|
self.assertTrue(my_func.called) |
82
|
|
|
|