Blame view

src/core/pyros_django/obs_config/tests.py 4.01 KB
cc4e5a62   Alexis Koralewski   Add ConfigPyrosv2...
1
from django.test import TestCase
b95a693f   Alexis Koralewski   restructuration d...
2
from user_mgmt.models import PyrosUser
a2dbbde1   Alexis Koralewski   Adding new config...
3
from .obsconfig_class import OBSConfig
472cb08c   Alexis Koralewski   Add new tests of ...
4
from django.urls import reverse
0318e3c9   Alexis Koralewski   Add tests for F05...
5
6
7
8
import unittest
import os


987624c5   Alexis Koralewski   adding obs config...
9
10
class ObservatoryConfigurationTests(TestCase):
    fixtures = ['tests/common_test_TZ.json']
0318e3c9   Alexis Koralewski   Add tests for F05...
11

987624c5   Alexis Koralewski   adding obs config...
12
13
    @unittest.expectedFailure
    def test_OCF_view_config_ko(self):
b95a693f   Alexis Koralewski   restructuration d...
14
15
        if os.path.exists("obs_config/fixtures/obsconfig.p"):
            os.remove("obs_config/fixtures/obsconfig.p")
0318e3c9   Alexis Koralewski   Add tests for F05...
16

987624c5   Alexis Koralewski   adding obs config...
17
        u1 = PyrosUser.objects.get(username="haribo")
0318e3c9   Alexis Koralewski   Add tests for F05...
18
        config_ko = OBSConfig(
b95a693f   Alexis Koralewski   restructuration d...
19
20
21
            "obs_config/fixtures/observatory_configuration_ko.yml")
        if os.path.exists("obs_config/fixtures/obsconfig"):
            os.remove("obs_config/fixtures/obsconfig")
0318e3c9   Alexis Koralewski   Add tests for F05...
22

472cb08c   Alexis Koralewski   Add new tests of ...
23
    def test_OCF_read_config_get_content(self):
b95a693f   Alexis Koralewski   restructuration d...
24
        os.environ["PATH_TO_OBSCONF_FILE"] = "obs_config/fixtures/observatory_configuration_ok_simple.yml"
0318e3c9   Alexis Koralewski   Add tests for F05...
25
        config = OBSConfig(
b95a693f   Alexis Koralewski   restructuration d...
26
            "obs_config/fixtures/observatory_configuration_ok_simple.yml")
472cb08c   Alexis Koralewski   Add new tests of ...
27
        # get_devices, and get_computers are already tested in load
0318e3c9   Alexis Koralewski   Add tests for F05...
28
29
        self.assertEqual(config.get_obs_name(), "observatory_test")
        self.assertEqual(len(config.get_units()), 1)
b95a693f   Alexis Koralewski   restructuration d...
30
31
        first_unit = config.get_units()["tst"]
        self.assertEqual(first_unit["name"], "tst")
0318e3c9   Alexis Koralewski   Add tests for F05...
32
33
34
35
36
37
38
39
        self.assertEqual(len(config.get_channels(first_unit["name"])), 1)
        self.assertEqual(
            len(config.get_agents_per_device(first_unit["name"])), 4)
        self.assertIn("AstroMecCA", config.get_devices().keys())
        self.assertIn("MainComputer", config.get_computers().keys())
        self.assertEqual(config.get_device_capabilities(
            "AstroMecCA")[0]["component"], "MountPointing")
        self.assertEquals(len(config.devices_links), 0)
b95a693f   Alexis Koralewski   restructuration d...
40
41
        if os.path.exists("obs_config/fixtures/obsconfig"):
            os.remove("obs_config/fixtures/obsconfig")
472cb08c   Alexis Koralewski   Add new tests of ...
42
43

    def test_OCF_view_config_simple(self):
b95a693f   Alexis Koralewski   restructuration d...
44
        os.environ["PATH_TO_OBSCONF_FILE"] = "obs_config/fixtures/observatory_configuration_ok_simple.yml"
0318e3c9   Alexis Koralewski   Add tests for F05...
45
        config = OBSConfig(
b95a693f   Alexis Koralewski   restructuration d...
46
            "obs_config/fixtures/observatory_configuration_ok_simple.yml")
472cb08c   Alexis Koralewski   Add new tests of ...
47
48
49
        u1 = PyrosUser.objects.get(username="haribo")
        u1.set_password("password123")
        u1.save()
0318e3c9   Alexis Koralewski   Add tests for F05...
50
51
        self.client.post(reverse("login_validation"), {
                         "email": "haribo", "password": "password123"})
472cb08c   Alexis Koralewski   Add new tests of ...
52
53
54
        response = self.client.get(reverse('obs_astronomer_config'))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'base.html')
0318e3c9   Alexis Koralewski   Add tests for F05...
55
        self.assertTemplateUsed(
b95a693f   Alexis Koralewski   restructuration d...
56
            response, 'obs_config/obs_astronomer_config.html')
472cb08c   Alexis Koralewski   Add new tests of ...
57
        self.assertContains(response, 'AstroMecCA')
0318e3c9   Alexis Koralewski   Add tests for F05...
58
59
        self.assertContains(response, "PLC")
        self.assertContains(response, "OpticalChannel")
b95a693f   Alexis Koralewski   restructuration d...
60
61
        if os.path.exists("obs_config/fixtures/obsconfig"):
            os.remove("obs_config/fixtures/obsconfig")
472cb08c   Alexis Koralewski   Add new tests of ...
62
63

    def test_OCF_view_config_complex(self):
b95a693f   Alexis Koralewski   restructuration d...
64
        os.environ["PATH_TO_OBSCONF_FILE"] = "obs_config/fixtures/observatory_configuration_ok_complex.yml"
0318e3c9   Alexis Koralewski   Add tests for F05...
65
        config = OBSConfig(
b95a693f   Alexis Koralewski   restructuration d...
66
            "obs_config/fixtures/observatory_configuration_ok_complex.yml")
472cb08c   Alexis Koralewski   Add new tests of ...
67
68
69
        u1 = PyrosUser.objects.get(username="haribo")
        u1.set_password("password123")
        u1.save()
0318e3c9   Alexis Koralewski   Add tests for F05...
70
71
72
        # self.client.login(username="haribo",password="password123")
        self.client.post(reverse("login_validation"), {
                         "email": "haribo", "password": "password123"})
472cb08c   Alexis Koralewski   Add new tests of ...
73
74
75
        response = self.client.get(reverse('obs_astronomer_config'))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'base.html')
0318e3c9   Alexis Koralewski   Add tests for F05...
76
        self.assertTemplateUsed(
b95a693f   Alexis Koralewski   restructuration d...
77
            response, 'obs_config/obs_astronomer_config.html')
472cb08c   Alexis Koralewski   Add new tests of ...
78
        self.assertContains(response, 'AstroMecCA')
0318e3c9   Alexis Koralewski   Add tests for F05...
79
80
        self.assertContains(response, "PLC")
        self.assertContains(response, "OpticalChannel")
472cb08c   Alexis Koralewski   Add new tests of ...
81
        # testing if GPS capability is attached to Camera ZWO
b95a693f   Alexis Koralewski   restructuration d...
82
83
84
        self.assertContains(response, "")
        if os.path.exists("obs_config/fixtures/obsconfig"):
            os.remove("obs_config/fixtures/obsconfig")