Blame view

src/core/pyros_django/obsconfig/tests.py 3.74 KB
cc4e5a62   Alexis Koralewski   Add ConfigPyrosv2...
1
from django.test import TestCase
987624c5   Alexis Koralewski   adding obs config...
2
3
from common.models import PyrosUser
from .configpyros import ConfigPyros
472cb08c   Alexis Koralewski   Add new tests of ...
4
from django.urls import reverse
eaffd837   Alexis Koralewski   fixing tests of o...
5
import unittest,os
987624c5   Alexis Koralewski   adding obs config...
6
7
8
9
class ObservatoryConfigurationTests(TestCase):
    fixtures = ['tests/common_test_TZ.json']
    @unittest.expectedFailure
    def test_OCF_view_config_ko(self):
eaffd837   Alexis Koralewski   fixing tests of o...
10
11
12
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/fixtures/obsconfig.p")
        
987624c5   Alexis Koralewski   adding obs config...
13
14
        u1 = PyrosUser.objects.get(username="haribo")
        config_ko = ConfigPyros("obsconfig/fixtures/observatory_configuration_ko.yml")
eaffd837   Alexis Koralewski   fixing tests of o...
15
16
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/fixtures/obsconfig.p")
472cb08c   Alexis Koralewski   Add new tests of ...
17
18
        
    def test_OCF_read_config_get_content(self):
eaffd837   Alexis Koralewski   fixing tests of o...
19
        os.environ["PATH_TO_OBSCONF_FILE"] = "obsconfig/fixtures/observatory_configuration_ok_simple.yml"
472cb08c   Alexis Koralewski   Add new tests of ...
20
21
22
23
24
25
26
27
28
29
30
31
        config = ConfigPyros("obsconfig/fixtures/observatory_configuration_ok_simple.yml")
        # get_devices, and get_computers are already tested in load
        self.assertEqual(config.get_obs_name(),"observatory_test")
        self.assertEqual(len(config.get_units()),1)
        first_unit = config.get_units()["test-unit"]
        self.assertEqual(first_unit["name"],"test-unit")
        self.assertEqual(len(config.get_channels(first_unit)),1)
        self.assertEqual(len(config.get_agents_per_device(first_unit)),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...
32
33
34
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/fixtures/obsconfig.p")
        
472cb08c   Alexis Koralewski   Add new tests of ...
35
36

    def test_OCF_view_config_simple(self):
eaffd837   Alexis Koralewski   fixing tests of o...
37
        os.environ["PATH_TO_OBSCONF_FILE"] = "obsconfig/fixtures/observatory_configuration_ok_simple.yml"
472cb08c   Alexis Koralewski   Add new tests of ...
38
39
40
41
42
43
44
45
46
47
48
49
        config = ConfigPyros("obsconfig/fixtures/observatory_configuration_ok_simple.yml")
        u1 = PyrosUser.objects.get(username="haribo")
        u1.set_password("password123")
        u1.save()
        self.client.login(username="haribo",password="password123")
        response = self.client.get(reverse('obs_astronomer_config'))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'base.html')
        self.assertTemplateUsed(response, 'obsconfig/obs_astronomer_config.html')
        self.assertContains(response, 'AstroMecCA')
        self.assertContains(response,"PLC")
        self.assertContains(response,"OpticalChannel")
eaffd837   Alexis Koralewski   fixing tests of o...
50
51
52
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/fixtures/obsconfig.p")
        
472cb08c   Alexis Koralewski   Add new tests of ...
53
54

    def test_OCF_view_config_complex(self):
eaffd837   Alexis Koralewski   fixing tests of o...
55
        os.environ["PATH_TO_OBSCONF_FILE"] = "obsconfig/fixtures/observatory_configuration_ok_complex.yml"
472cb08c   Alexis Koralewski   Add new tests of ...
56
57
58
59
60
61
62
63
64
65
66
67
68
        config = ConfigPyros("obsconfig/fixtures/observatory_configuration_ok_complex.yml")
        u1 = PyrosUser.objects.get(username="haribo")
        u1.set_password("password123")
        u1.save()
        self.client.login(username="haribo",password="password123")
        response = self.client.get(reverse('obs_astronomer_config'))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'base.html')
        self.assertTemplateUsed(response, 'obsconfig/obs_astronomer_config.html')
        self.assertContains(response, 'AstroMecCA')
        self.assertContains(response,"PLC")
        self.assertContains(response,"OpticalChannel")
        # testing if GPS capability is attached to Camera ZWO
eaffd837   Alexis Koralewski   fixing tests of o...
69
70
71
72
        self.assertContains(response,"DetectorTimer")
        if os.path.exists("obsconfig/fixtures/obsconfig.p"):
            os.remove("obsconfig/fixtures/obsconfig.p")