Blame view

src/core/pyros_django/obsconfig/tests.py 4.03 KB
cc4e5a62   Alexis Koralewski   Add ConfigPyrosv2...
1
from django.test import TestCase
987624c5   Alexis Koralewski   adding obs config...
2
from common.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):
eaffd837   Alexis Koralewski   fixing tests of o...
14
15
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/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
19
        config_ko = OBSConfig(
            "obsconfig/fixtures/observatory_configuration_ko.yml")
eaffd837   Alexis Koralewski   fixing tests of o...
20
21
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/fixtures/obsconfig.p")
0318e3c9   Alexis Koralewski   Add tests for F05...
22

472cb08c   Alexis Koralewski   Add new tests of ...
23
    def test_OCF_read_config_get_content(self):
eaffd837   Alexis Koralewski   fixing tests of o...
24
        os.environ["PATH_TO_OBSCONF_FILE"] = "obsconfig/fixtures/observatory_configuration_ok_simple.yml"
0318e3c9   Alexis Koralewski   Add tests for F05...
25
26
        config = OBSConfig(
            "obsconfig/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)
472cb08c   Alexis Koralewski   Add new tests of ...
30
        first_unit = config.get_units()["test-unit"]
0318e3c9   Alexis Koralewski   Add tests for F05...
31
32
33
34
35
36
37
38
39
        self.assertEqual(first_unit["name"], "test-unit")
        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)
eaffd837   Alexis Koralewski   fixing tests of o...
40
41
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/fixtures/obsconfig.p")
472cb08c   Alexis Koralewski   Add new tests of ...
42
43

    def test_OCF_view_config_simple(self):
eaffd837   Alexis Koralewski   fixing tests of o...
44
        os.environ["PATH_TO_OBSCONF_FILE"] = "obsconfig/fixtures/observatory_configuration_ok_simple.yml"
0318e3c9   Alexis Koralewski   Add tests for F05...
45
46
        config = OBSConfig(
            "obsconfig/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
56
        self.assertTemplateUsed(
            response, 'obsconfig/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")
eaffd837   Alexis Koralewski   fixing tests of o...
60
61
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/fixtures/obsconfig.p")
472cb08c   Alexis Koralewski   Add new tests of ...
62
63

    def test_OCF_view_config_complex(self):
eaffd837   Alexis Koralewski   fixing tests of o...
64
        os.environ["PATH_TO_OBSCONF_FILE"] = "obsconfig/fixtures/observatory_configuration_ok_complex.yml"
0318e3c9   Alexis Koralewski   Add tests for F05...
65
66
        config = OBSConfig(
            "obsconfig/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
77
        self.assertTemplateUsed(
            response, 'obsconfig/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
0318e3c9   Alexis Koralewski   Add tests for F05...
82
        self.assertContains(response, "DetectorTimer")
eaffd837   Alexis Koralewski   fixing tests of o...
83
84
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/fixtures/obsconfig.p")