File: test_schedulerule.py

package info (click to toggle)
rachiopy 1.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 328 kB
  • sloc: python: 1,053; makefile: 14; sh: 5
file content (92 lines) | stat: -rw-r--r-- 2,986 bytes parent folder | download | duplicates (2)
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
85
86
87
88
89
90
91
92
"""ScheduleRule object test module"""

import unittest
from unittest.mock import patch
import uuid
import json

from rachiopy import Schedulerule
from tests.constants import BASE_API_URL, AUTHTOKEN, RESPONSE200, RESPONSE204


class TestScheduleRuleMethods(unittest.TestCase):
    """Class containing the ScheduleRule object test cases."""

    def setUp(self):
        self.schedulerule = Schedulerule(AUTHTOKEN)

    def test_init(self):
        """Test if the constructor works as expected."""
        self.assertEqual(self.schedulerule.authtoken, AUTHTOKEN)

    @patch("requests.Session.request")
    def test_get(self, mock):
        """Test if the get method works as expected."""
        mock.return_value = RESPONSE200

        scheduleruleid = str(uuid.uuid4())

        self.schedulerule.get(scheduleruleid)

        args, kwargs = mock.call_args

        # Check that the mock function is called with the rights args.
        self.assertEqual(
            args[1], f"{BASE_API_URL}/schedulerule/{scheduleruleid}"
        )
        self.assertEqual(args[0], "GET")
        self.assertEqual(kwargs["data"], None)

    @patch("requests.Session.request")
    def test_skip(self, mock):
        """Test if the skip method works as expected."""
        mock.return_value = RESPONSE204

        scheduleruleid = str(uuid.uuid4())

        self.schedulerule.skip(scheduleruleid)

        args, kwargs = mock.call_args

        # Check that the mock function is called with the rights args.
        self.assertEqual(args[1], f"{BASE_API_URL}/schedulerule/skip")
        self.assertEqual(args[0], "PUT")
        self.assertEqual(kwargs["data"], json.dumps({"id": scheduleruleid}))

    @patch("requests.Session.request")
    def test_start(self, mock):
        """Test if the start method works as expected."""
        mock.return_value = RESPONSE204

        scheduleruleid = str(uuid.uuid4())

        self.schedulerule.start(scheduleruleid)

        args, kwargs = mock.call_args

        # Check that the mock function is called with the rights args.
        self.assertEqual(args[1], f"{BASE_API_URL}/schedulerule/start")
        self.assertEqual(args[0], "PUT")
        self.assertEqual(kwargs["data"], json.dumps({"id": scheduleruleid}))

    @patch("requests.Session.request")
    def test_seasonal_adjustment(self, mock):
        """Test if the seasonal adjustment method works as expected."""
        mock.return_value = RESPONSE200

        scheduleruleid = str(uuid.uuid4())
        adjustment = 0.2

        self.schedulerule.seasonal_adjustment(scheduleruleid, adjustment)

        args, kwargs = mock.call_args

        # Check that the mock function is called with the rights args.
        self.assertEqual(
            args[1], f"{BASE_API_URL}/schedulerule/seasonal_adjustment"
        )
        self.assertEqual(args[0], "PUT")
        self.assertEqual(
            kwargs["data"],
            json.dumps({"id": scheduleruleid, "adjustment": adjustment}),
        )