Debian Codegraph @

tests/test_program.py

raw symbols SCIP
1 """Program object test module"""
2
3 import unittest
4 import uuid
5 import json
6 from unittest.mock import patch
7
8 from rachiopy import Program
9 from tests.constants import VALVE_API_URL, AUTHTOKEN, RESPONSE200
10
11
12 class TestProgramMethods(unittest.TestCase):
13 """Class containing the Program object tests."""
14
15 def setUp(self):
16 self.program = Program(AUTHTOKEN)
17
18 def test_init(self):
19 """Test if the constructor works as expected."""
20 self.assertEqual(self.program.authtoken, AUTHTOKEN)
21
22 @patch("requests.Session.request")
23 def test_list_programs(self, mock):
24 """Test if the list programs method works as expected."""
25 mock.return_value = RESPONSE200
26
27 valveid = str(uuid.uuid4())
28
29 self.program.list_programs(valveid)
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"{VALVE_API_URL}/program/listPrograms/{valveid}"
36 )
37 self.assertEqual(args[0], "GET")
38 self.assertEqual(kwargs["data"], None)
39
40 @patch("requests.Session.request")
41 def test_get_program(self, mock):
42 """Test if the get program method works as expected."""
43 mock.return_value = RESPONSE200
44
45 programid = str(uuid.uuid4())
46
47 self.program.get_program(programid)
48
49 args, kwargs = mock.call_args
50
51 # Check that the mock function is called with the rights args.
52 self.assertEqual(
53 args[1], f"{VALVE_API_URL}/program/getProgram/{programid}"
54 )
55 self.assertEqual(args[0], "GET")
56 self.assertEqual(kwargs["data"], None)
57
58 @patch("requests.Session.request")
59 def test_create_skip_overrides(self, mock):
60 """Test if the create skip overrides method works as expected."""
61 mock.return_value = RESPONSE200
62
63 programid = str(uuid.uuid4())
64 timestamp = 1414818000000
65
66 self.program.create_skip_overrides(programid, timestamp)
67
68 args, kwargs = mock.call_args
69
70 # Check that the mock function is called with the rights args.
71 self.assertEqual(
72 args[1], f"{VALVE_API_URL}/program/createSkipOverrides"
73 )
74 self.assertEqual(args[0], "POST")
75 self.assertEqual(
76 kwargs["data"],
77 json.dumps({"programId": programid, "timestamp": timestamp}),
78 )
79
80 @patch("requests.Session.request")
81 def test_delete_skip_overrides(self, mock):
82 """Test if the delete skip overrides method works as expected."""
83 mock.return_value = RESPONSE200
84
85 programid = str(uuid.uuid4())
86 timestamp = 1414818000000
87
88 self.program.delete_skip_overrides(programid, timestamp)
89
90 args, kwargs = mock.call_args
91
92 # Check that the mock function is called with the rights args.
93 self.assertEqual(
94 args[1], f"{VALVE_API_URL}/program/deleteSkipOverrides"
95 )
96 self.assertEqual(args[0], "POST")
97 self.assertEqual(
98 kwargs["data"],
99 json.dumps({"programId": programid, "timestamp": timestamp}),
100 )