File: test_vps.py

package info (click to toggle)
transip 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 256 kB
  • sloc: python: 1,280; makefile: 18; sh: 4
file content (55 lines) | stat: -rw-r--r-- 1,807 bytes parent folder | download
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
import unittest

from transip.service import VpsService
from transip.client import MODE_RO, MODE_RW

try:
    from unittest.mock import Mock, patch
except ImportError:
    from mock import patch, Mock

class TestVPSService(unittest.TestCase):

    def testConstructor(self):
        # CALL
        vs = VpsService(login='sundayafternoon')
        # VERIFY
        self.assertEqual(vs.url, 'https://api.transip.nl/wsdl/?service=VpsService')

    @patch('transip.client.SudsClient')
    def testGetVpses(self, mock_client):
        # SETUP
        vs = VpsService(login='sundayafternoon')
        vs.build_cookie = Mock(return_value={"cookie":"value"})
        vs.update_cookie = Mock()

        i = mock_client.return_value
        i.service.getVpses.return_value = ['vps1', 'vps2']

        # CALL
        result = vs.get_vpses()

        # VERIFY
        vs.build_cookie.assert_called_with(mode=MODE_RO, method='getVpses')
        vs.update_cookie.assert_called_with({"cookie": "value"})
        i.service.getVpses.assert_called_with()
        self.assertEqual(result, [ 'vps1', 'vps2' ])

    @patch('transip.client.SudsClient')
    def testSetCustomerLock(self, mock_client):
        # SETUP
        vs = VpsService(login='sundayafternoon')
        vs.build_cookie = Mock(return_value={"cookie":"value"})
        vs.update_cookie = Mock()

        i = mock_client.return_value
        i.service.setCustomerLock.return_value = None

        # CALL
        result = vs.set_customer_lock(vps_name='test',enabled=1)

        # VERIFY
        vs.build_cookie.assert_called_with(mode=MODE_RW, method='setCustomerLock', parameters=['test',1])
        vs.update_cookie.assert_called_with({"cookie": "value"})
        i.service.setCustomerLock.assert_called_with('test', 1)
        self.assertEqual(result, None)