tests.integration.test_deploy_model_ssl_on_auth_on   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 75.31 %

Importance

Changes 0
Metric Value
wmc 8
eloc 46
dl 61
loc 81
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A TestDeployModelSSLOnAuthOn._get_transfer_protocol() 0 2 1
A TestDeployModelSSLOnAuthOn._get_key_file_name() 0 2 1
A TestDeployModelSSLOnAuthOn._get_pwd_file() 0 2 1
A TestDeployModelSSLOnAuthOn._get_certificate_file_name() 0 2 1
A TestDeployModelSSLOnAuthOn.test_deploy_ssl_on_auth_on() 29 29 2
A TestDeployModelSSLOnAuthOn.test_override_model_ssl_on_auth_on() 32 32 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
from . import integ_test_base
2
import base64
3
import requests
4
5
6
class TestDeployModelSSLOnAuthOn(integ_test_base.IntegTestBase):
7
    def _get_transfer_protocol(self) -> str:
8
        return "https"
9
10
    def _get_certificate_file_name(self) -> str:
11
        return "./tests/integration/resources/2019_04_24_to_3018_08_25.crt"
12
13
    def _get_key_file_name(self) -> str:
14
        return "./tests/integration/resources/2019_04_24_to_3018_08_25.key"
15
16
    def _get_pwd_file(self) -> str:
17
        return "./tests/integration/resources/pwdfile.txt"
18
19 View Code Duplication
    def test_deploy_ssl_on_auth_on(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
20
        # Uncomment the following line to preserve
21
        # test case output and other files (config, state, ect.)
22
        # in system temp folder.
23
        # self.set_delete_temp_folder(False)
24
25
        self.deploy_models(self._get_username(), self._get_password())
26
27
        headers = {
28
            "Content-Type": "application/json",
29
            "TabPy-Client": "Integration test for deploying models with auth",
30
            "Authorization": "Basic "
31
            + base64.b64encode("user1:P@ssw0rd".encode("utf-8")).decode("utf-8"),
32
        }
33
34
        session = requests.Session()
35
        # Do not verify servers' cert to be signed by trusted CA
36
        session.verify = False
37
        # Do not warn about insecure request
38
        requests.packages.urllib3.disable_warnings()
39
40
        models = ["PCA", "Sentiment%20Analysis", "ttest", "anova"]
41
        for m in models:
42
            m_response = session.get(
43
                url=f"{self._get_transfer_protocol()}://"
44
                f"localhost:9004/endpoints/{m}",
45
                headers=headers,
46
            )
47
            self.assertEqual(200, m_response.status_code)
48
49 View Code Duplication
    def test_override_model_ssl_on_auth_on(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
50
        # Uncomment the following line to preserve
51
        # test case output and other files (config, state, ect.)
52
        # in system temp folder.
53
        # self.set_delete_temp_folder(False)
54
55
        self.deploy_models(self._get_username(), self._get_password())
56
57
        # Override models
58
        self.deploy_models(self._get_username(), self._get_password())
59
60
        headers = {
61
            "Content-Type": "application/json",
62
            "TabPy-Client": "Integration test for deploying models with auth",
63
            "Authorization": "Basic "
64
            + base64.b64encode("user1:P@ssw0rd".encode("utf-8")).decode("utf-8"),
65
        }
66
67
        session = requests.Session()
68
        # Do not verify servers' cert to be signed by trusted CA
69
        session.verify = False
70
        # Do not warn about insecure request
71
        requests.packages.urllib3.disable_warnings()
72
73
        models = ["PCA", "Sentiment%20Analysis", "ttest", "anova"]
74
        for m in models:
75
            m_response = session.get(
76
                url=f"{self._get_transfer_protocol()}://"
77
                f"localhost:9004/endpoints/{m}",
78
                headers=headers,
79
            )
80
            self.assertEqual(200, m_response.status_code)
81