tests.py
4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from django.test import TestCase
from common.models import PyrosUser
from .obsconfig_class import OBSConfig
from django.urls import reverse
import unittest
import os
class ObservatoryConfigurationTests(TestCase):
fixtures = ['tests/common_test_TZ.json']
@unittest.expectedFailure
def test_OCF_view_config_ko(self):
if os.path.exists("obsconfig/fixtures/obsconfig.p"):
os.remove("obsconfig/fixtures/obsconfig.p")
u1 = PyrosUser.objects.get(username="haribo")
config_ko = OBSConfig(
"obsconfig/fixtures/observatory_configuration_ko.yml")
if os.path.exists("obsconfig/fixtures/obsconfig.p"):
os.remove("obsconfig/fixtures/obsconfig.p")
def test_OCF_read_config_get_content(self):
os.environ["PATH_TO_OBSCONF_FILE"] = "obsconfig/fixtures/observatory_configuration_ok_simple.yml"
config = OBSConfig(
"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["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)
if os.path.exists("obsconfig/fixtures/obsconfig.p"):
os.remove("obsconfig/fixtures/obsconfig.p")
def test_OCF_view_config_simple(self):
os.environ["PATH_TO_OBSCONF_FILE"] = "obsconfig/fixtures/observatory_configuration_ok_simple.yml"
config = OBSConfig(
"obsconfig/fixtures/observatory_configuration_ok_simple.yml")
u1 = PyrosUser.objects.get(username="haribo")
u1.set_password("password123")
u1.save()
self.client.post(reverse("login_validation"), {
"email": "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")
if os.path.exists("obsconfig/fixtures/obsconfig.p"):
os.remove("obsconfig/fixtures/obsconfig.p")
def test_OCF_view_config_complex(self):
os.environ["PATH_TO_OBSCONF_FILE"] = "obsconfig/fixtures/observatory_configuration_ok_complex.yml"
config = OBSConfig(
"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")
self.client.post(reverse("login_validation"), {
"email": "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
self.assertContains(response, "DetectorTimer")
if os.path.exists("obsconfig/fixtures/obsconfig.p"):
os.remove("obsconfig/fixtures/obsconfig.p")