File: test_program.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 (100 lines) | stat: -rw-r--r-- 3,127 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
93
94
95
96
97
98
99
100
"""Program object test module"""

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

from rachiopy import Program
from tests.constants import VALVE_API_URL, AUTHTOKEN, RESPONSE200


class TestProgramMethods(unittest.TestCase):
    """Class containing the Program object tests."""

    def setUp(self):
        self.program = Program(AUTHTOKEN)

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

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

        valveid = str(uuid.uuid4())

        self.program.list_programs(valveid)

        args, kwargs = mock.call_args

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

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

        programid = str(uuid.uuid4())

        self.program.get_program(programid)

        args, kwargs = mock.call_args

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

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

        programid = str(uuid.uuid4())
        timestamp = 1414818000000

        self.program.create_skip_overrides(programid, timestamp)

        args, kwargs = mock.call_args

        # Check that the mock function is called with the rights args.
        self.assertEqual(
            args[1], f"{VALVE_API_URL}/program/createSkipOverrides"
        )
        self.assertEqual(args[0], "POST")
        self.assertEqual(
            kwargs["data"],
            json.dumps({"programId": programid, "timestamp": timestamp}),
        )

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

        programid = str(uuid.uuid4())
        timestamp = 1414818000000

        self.program.delete_skip_overrides(programid, timestamp)

        args, kwargs = mock.call_args

        # Check that the mock function is called with the rights args.
        self.assertEqual(
            args[1], f"{VALVE_API_URL}/program/deleteSkipOverrides"
        )
        self.assertEqual(args[0], "POST")
        self.assertEqual(
            kwargs["data"],
            json.dumps({"programId": programid, "timestamp": timestamp}),
        )