Debian Codegraph @

tests/test_schedulerule.py

raw symbols SCIP
1 """ScheduleRule object test module"""
2
3 import unittest
4 from unittest.mock import patch
5 import uuid
6 import json
7
8 from rachiopy import Schedulerule
9 from tests.constants import BASE_API_URL, AUTHTOKEN, RESPONSE200, RESPONSE204
10
11
12 class TestScheduleRuleMethods(unittest.TestCase):
13 """Class containing the ScheduleRule object test cases."""
14
15 def setUp(self):
16 self.schedulerule = Schedulerule(AUTHTOKEN)
17
18 def test_init(self):
19 """Test if the constructor works as expected."""
20 self.assertEqual(self.schedulerule.authtoken, AUTHTOKEN)
21
22 @patch("requests.Session.request")
23 def test_get(self, mock):
24 """Test if the get method works as expected."""
25 mock.return_value = RESPONSE200
26
27 scheduleruleid = str(uuid.uuid4())
28
29 self.schedulerule.get(scheduleruleid)
30
31 args, kwargs = mock.call_args
32
33 # Check that the mock function is called with the rights args.
34 self.assertEqual(
35 args[1], f"{BASE_API_URL}/schedulerule/{scheduleruleid}"
36 )
37 self.assertEqual(args[0], "GET")
38 self.assertEqual(kwargs["data"], None)
39
40 @patch("requests.Session.request")
41 def test_skip(self, mock):
42 """Test if the skip method works as expected."""
43 mock.return_value = RESPONSE204
44
45 scheduleruleid = str(uuid.uuid4())
46
47 self.schedulerule.skip(scheduleruleid)
48
49 args, kwargs = mock.call_args
50
51 # Check that the mock function is called with the rights args.
52 self.assertEqual(args[1], f"{BASE_API_URL}/schedulerule/skip")
53 self.assertEqual(args[0], "PUT")
54 self.assertEqual(kwargs["data"], json.dumps({"id": scheduleruleid}))
55
56 @patch("requests.Session.request")
57 def test_start(self, mock):
58 """Test if the start method works as expected."""
59 mock.return_value = RESPONSE204
60
61 scheduleruleid = str(uuid.uuid4())
62
63 self.schedulerule.start(scheduleruleid)
64
65 args, kwargs = mock.call_args
66
67 # Check that the mock function is called with the rights args.
68 self.assertEqual(args[1], f"{BASE_API_URL}/schedulerule/start")
69 self.assertEqual(args[0], "PUT")
70 self.assertEqual(kwargs["data"], json.dumps({"id": scheduleruleid}))
71
72 @patch("requests.Session.request")
73 def test_seasonal_adjustment(self, mock):
74 """Test if the seasonal adjustment method works as expected."""
75 mock.return_value = RESPONSE200
76
77 scheduleruleid = str(uuid.uuid4())
78 adjustment = 0.2
79
80 self.schedulerule.seasonal_adjustment(scheduleruleid, adjustment)
81
82 args, kwargs = mock.call_args
83
84 # Check that the mock function is called with the rights args.
85 self.assertEqual(
86 args[1], f"{BASE_API_URL}/schedulerule/seasonal_adjustment"
87 )
88 self.assertEqual(args[0], "PUT")
89 self.assertEqual(
90 kwargs["data"],
91 json.dumps({"id": scheduleruleid, "adjustment": adjustment}),
92 )