Debian Codegraph @

tests/test_summary.py

raw symbols SCIP
1 """Summary object test module"""
2
3 import unittest
4 import uuid
5 import json
6 from unittest.mock import patch
7
8 from rachiopy import SummaryServce
9 from tests.constants import VALVE_API_URL, AUTHTOKEN, RESPONSE200
10
11
12 class TestSummaryMethod(unittest.TestCase):
13 """Class containing the Summary object test."""
14
15 def setUp(self):
16 self.summary = SummaryServce(AUTHTOKEN)
17
18 def test_init(self):
19 """Test if the constructor works as expected."""
20 self.assertEqual(self.summary.authtoken, AUTHTOKEN)
21
22 @patch("requests.Session.request")
23 def test_get_valve_day_views(self, mock):
24 """Test if the get day views method works as expected."""
25 mock.return_value = RESPONSE200
26
27 deviceid = str(uuid.uuid4())
28 start = {"year": 2023, "month": 1, "day": 1}
29 end = {"year": 2023, "month": 1, "day": 30}
30
31 self.summary.get_valve_day_views(deviceid, start, end)
32
33 args, kwargs = mock.call_args
34
35 # Check that the mock function is called with the rights args.
36 self.assertEqual(args[1], f"{VALVE_API_URL}/summary/getValveDayViews")
37 self.assertEqual(args[0], "POST")
38 self.assertEqual(
39 kwargs["data"],
40 json.dumps(
41 {
42 "resourceId": {"baseStationId": deviceid},
43 "start": start,
44 "end": end,
45 }
46 ),
47 )