Blame view

src/pyrosapp/tests.py 4.39 KB
64501c9d   Etienne Pallier   first full projec...
1
from django.test import TestCase
6d86da1b   haribo   fix #3400, #3401,...
2
3
4
from pyrosapp.models import *
from django.contrib.auth.models import User
from django.utils import timezone
64501c9d   Etienne Pallier   first full projec...
5

94336356   haribo   Added starting fi...
6

6d86da1b   haribo   fix #3400, #3401,...
7
class CountryTests(TestCase):
94336356   haribo   Added starting fi...
8

6d86da1b   haribo   fix #3400, #3401,...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    def test_creation(self):
        Country.objects.create(name="France", desc="Test", quota=1)
        france = Country.objects.get(name="France")
        self.assertEqual(france.name, "France")
        self.assertEqual(france.desc, "Test")
        self.assertEqual(france.quota, 1)
        france.quota = -1
        france.delete()
        france.save()
        Country.objects.create(name="Mexique")
        countries = Country.objects.all()
        self.assertEqual(countries.count(), 2)
        countries[0].name = "Toto"
        countries[0].save()

94336356   haribo   Added starting fi...
24

6d86da1b   haribo   fix #3400, #3401,...
25
class DeviceTests(TestCase):
94336356   haribo   Added starting fi...
26

6d86da1b   haribo   fix #3400, #3401,...
27
28
29
30
    def test_creation(self):
        device = Device.objects.create()
        countries = Country.objects.all()
        self.assertEqual(countries.count(), 0, "perdu !")
94336356   haribo   Added starting fi...
31
32


6d86da1b   haribo   fix #3400, #3401,...
33
class RequestTests(TestCase):
94336356   haribo   Added starting fi...
34

6d86da1b   haribo   fix #3400, #3401,...
35
36
37
38
39
    def setUp(self):
        strat1 = StrategyObs.objects.create(name="strat1")
        france = Country.objects.create(name="France")
        admin = UserLevel.objects.create(name="Admin")
        usr1 = User.objects.create(username="Haribo")
94336356   haribo   Added starting fi...
40
        haribo = PyrosUser.objects.create(
94082e77   haribo   Date: 03/06/2016
41
            user=usr1, country=france, user_level=admin)
6d86da1b   haribo   fix #3400, #3401,...
42
        sp1 = ScientificProgram.objects.create(name="sp1")
94336356   haribo   Added starting fi...
43
44
        req1 = Request.objects.create(
            name="req1", pyros_user=haribo, scientific_program=sp1)
6d86da1b   haribo   fix #3400, #3401,...
45
46
47
        Alert.objects.create(strategyobs=strat1, request=req1)

        sched = Schedule.objects.create()
94336356   haribo   Added starting fi...
48
        seq1 = Sequence.objects.create(
7a79e25b   haribo   Date: 19/05/2016
49
            name="seq1", request=req1)
94336356   haribo   Added starting fi...
50

6d86da1b   haribo   fix #3400, #3401,...
51
52
53
54
55
        dev_tel = Device.objects.create(name="telescope")
        dev_det = Device.objects.create(name="detector")
        tel = Telescope.objects.create(device=dev_tel)
        det = Detector.objects.create(device=dev_det, telescope=tel)
        alb1 = Album.objects.create(name="alb1", sequence=seq1, detector=det)
94336356   haribo   Added starting fi...
56

ad85da7c   haribo   Date: 28/06/2016
57
58
59
        dev_fw = Device.objects.create(name="fw")
        fw = FilterWheel.objects.create(device=dev_fw)

6d86da1b   haribo   fix #3400, #3401,...
60
        dev_fil = Device.objects.create(name="filter")
ad85da7c   haribo   Date: 28/06/2016
61
        fil = Filter.objects.create(device=dev_fil, filter_wheel=fw)
6d86da1b   haribo   fix #3400, #3401,...
62
63
64
        plan1 = Plan.objects.create(name="plan1", album=alb1, filter=fil)
        img1 = Image.objects.create(name="img1", plan=plan1)
        img2 = Image.objects.create(name="img2", plan=plan1)
94336356   haribo   Added starting fi...
65

6d86da1b   haribo   fix #3400, #3401,...
66
67
68
69
70
71
72
    def test_request_access(self):
        alert = Alert.objects.get()
        self.assertEqual(alert.request.name, "req1")

        req1 = Request.objects.get(name="req1")
        req1.name = "reqtiti"
        req1.save()
94336356   haribo   Added starting fi...
73
74
        # j'ai saved req1, pourtant alert1.request.name est toujours le même
        self.assertEqual(alert.request.name, "req1")
6d86da1b   haribo   fix #3400, #3401,...
75
76

        alert = Alert.objects.get()
94336356   haribo   Added starting fi...
77
78
79
        # j'ai refait un get de mon alert, donc c'est mis à jour
        self.assertEqual(alert.request.name, "reqtiti")

6d86da1b   haribo   fix #3400, #3401,...
80
81
82
83
        alert.request.name = "reqtoto"
        alert.save()
        self.assertEqual(req1.name, "reqtiti")
        self.assertEqual(alert.request.name, "reqtoto")
94336356   haribo   Added starting fi...
84

6d86da1b   haribo   fix #3400, #3401,...
85
86
87
88
89
90
91
92
93
94
        req1 = Request.objects.get()
        self.assertEqual(req1.name, "reqtiti")

        alert.request.save()
        req1 = Request.objects.get()
        self.assertEqual(req1.name, "reqtoto")

    def test_reinit_base(self):
        req1 = Request.objects.get()
        self.assertEqual(req1.name, "req1")
94336356   haribo   Added starting fi...
95

6d86da1b   haribo   fix #3400, #3401,...
96
97
98
99
100
101
102
103
104
    def test_full_request(self):
        req1 = Request.objects.get()
        self.assertEqual(req1.sequences.count(), 1)
        albums = req1.sequences.all()[0].albums
        self.assertEqual(albums.count(), 1)
        images = albums.all()[0].plans.all()[0].images
        self.assertEqual(images.count(), 2)
        img1 = images.get(name="img1")
        img1.name = "img1.1"
94336356   haribo   Added starting fi...
105
106
        img11 = req1.sequences.get().albums.get().plans.get().images.get(
            name="img1")  # j'ai toujours pas sauvegardé mon image
6d86da1b   haribo   fix #3400, #3401,...
107
        img1.save()
94336356   haribo   Added starting fi...
108
109
110
        img11 = req1.sequences.get().albums.get().plans.get().images.get(
            name="img1.1")  # j'ai sauvegardé mon image

6d86da1b   haribo   fix #3400, #3401,...
111
        req1 = Request.objects.get()
94336356   haribo   Added starting fi...
112
113
114
        img1 = req1.sequences.get().albums.get().plans.get().images.get(
            name="img1.1")

6d86da1b   haribo   fix #3400, #3401,...
115
116
117
        img11 = Image.objects.get(name="img1.1")
        img11.name = "img1.2"
        img11.save()
94336356   haribo   Added starting fi...
118
119
120
121

        self.assertEqual(img1.name, "img1.1")  # img1 et img11 sont différents
        img1 = req1.sequences.get().albums.get().plans.get().images.get(
            name="img1.2")