Passed
Push — master ( b7ec87...174f4e )
by Alexander
02:09
created

APIPermissionsTestCase._fixture_setup()   A

Complexity

Conditions 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 17
rs 9.85
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
2
# pylint: disable=attribute-defined-outside-init
3
4
import tcms_api
5
from django import test
6
7
from tcms.tests import PermissionsTestMixin
8
from tcms.tests.factories import UserFactory
9
from tcms.utils.permissions import initiate_user_with_default_setups
10
11
12
class APITestCase(test.LiveServerTestCase):
13
    serialized_rollback = True
14
15
    # NOTE: we setup the required DB data and API objects here
16
    # because this method is executed *AFTER* setUpClass() and the
17
    # serialized rollback is not yet available during setUpClass()
18
    # execution
19
    def _fixture_setup(self):
20
        # restore the serialized data from initial migrations
21
        # this includes default groups and permissions
22
        super()._fixture_setup()
23
        self.api_user = UserFactory()
24
        self.api_user.set_password('api-testing')
25
        initiate_user_with_default_setups(self.api_user)
26
27
        # this is the XML-RPC ServerProxy with cookies support
28
        self.rpc_client = tcms_api.xmlrpc.TCMSXmlrpc(
29
            self.api_user.username,
30
            'api-testing',
31
            '%s/xml-rpc/' % self.live_server_url,
32
        ).server
33
34
35
class APIPermissionsTestCase(PermissionsTestMixin, test.LiveServerTestCase):
36
    http_method_names = ['api']
37
    permission_label = None
38
    serialized_rollback = True
39
40
    # NOTE: see comment in APITestCase._fixture_setup()
41
    def _fixture_setup(self):
42
        # restore the serialized data from initial migrations
43
        # this includes default groups and permissions
44
        super()._fixture_setup()
45
46
        self.check_mandatory_attributes()
47
48
        self.tester = UserFactory()
49
        self.tester.set_password('password')
50
        self.tester.save()
51
52
        # this is the XML-RPC ServerProxy with cookies support
53
        self.rpc_client = tcms_api.xmlrpc.TCMSXmlrpc(
54
            self.tester.username,
55
            'password',
56
            '%s/xml-rpc/' % self.live_server_url,
57
        ).server
58
59
    def verify_api_with_permission(self):
60
        """
61
            Call your RPC method under test here and assert the results
62
        """
63
        self.fail('Not implemented')
64
65
    def verify_api_without_permission(self):
66
        """
67
            Call your RPC method under test here and assert the results
68
        """
69
        self.fail('Not implemented')
70