Completed
Push — master ( 5644bc...b87258 )
by Paolo
17s queued 13s
created

GetModelObjectTestCase.test_get_model_object()   A

Complexity

Conditions 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 17
rs 9.75
c 0
b 0
f 0
cc 1
nop 1
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
4
Created on Wed Feb 14 10:34:44 2018
5
6
@author: Paolo Cozzi <[email protected]>
7
"""
8
9
from django.test import TestCase
10
11
from image_app.models import Animal, Sample
12
13
from ..helpers import get_model_object
14
15
16
class GetModelObjectTestCase(TestCase):
17
    fixtures = [
18
        'image_app/animal',
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
        'image_app/name',
27
        'image_app/organization',
28
        'image_app/publication',
29
        'image_app/sample',
30
        'image_app/submission',
31
        'image_app/user',
32
    ]
33
34
    def setUp(self):
35
        self.animal_id = 1
36
        self.sample_id = 1
37
38
    def test_get_model_object(self):
39
40
        test = get_model_object("Animal", 1)
41
        self.assertEqual(test.id, self.animal_id)
42
        self.assertIsInstance(test, Animal)
43
44
        test = get_model_object("Sample", 1)
45
        self.assertEqual(test.id, self.sample_id)
46
        self.assertIsInstance(test, Sample)
47
48
        # assert errors
49
        self.assertRaisesMessage(
50
            Exception,
51
            "Unknown table",
52
            get_model_object,
53
            "Name",
54
            1)
55