Code Duplication    Length = 43-48 lines in 3 locations

tests/unit/server_tests/test_endpoint_handler.py 1 location

@@ 13-56 (lines=44) @@
10
11
12
class TestEndpointHandlerWithAuth(AsyncHTTPTestCase):
13
    @classmethod
14
    def setUpClass(cls):
15
        _init_asyncio_patch()
16
        prefix = "__TestEndpointHandlerWithAuth_"
17
        # create password file
18
        cls.pwd_file = tempfile.NamedTemporaryFile(
19
            mode="w+t", prefix=prefix, suffix=".txt", delete=False
20
        )
21
        username = "username"
22
        password = "password"
23
        cls.pwd_file.write(f"{username} {hash_password(username, password)}")
24
        cls.pwd_file.close()
25
26
        # create state.ini dir and file
27
        cls.state_dir = tempfile.mkdtemp(prefix=prefix)
28
        cls.state_file = open(os.path.join(cls.state_dir, "state.ini"), "w+")
29
        cls.state_file.write(
30
            "[Service Info]\n"
31
            "Name = TabPy Serve\n"
32
            "Description = \n"
33
            "Creation Time = 0\n"
34
            "Access-Control-Allow-Origin = \n"
35
            "Access-Control-Allow-Headers = \n"
36
            "Access-Control-Allow-Methods = \n"
37
            "\n"
38
            "[Query Objects Service Versions]\n"
39
            "\n"
40
            "[Query Objects Docstrings]\n"
41
            "\n"
42
            "[Meta]\n"
43
            "Revision Number = 1\n"
44
        )
45
        cls.state_file.close()
46
47
        # create config file
48
        cls.config_file = tempfile.NamedTemporaryFile(
49
            mode="w+t", prefix=prefix, suffix=".conf", delete=False
50
        )
51
        cls.config_file.write(
52
            "[TabPy]\n"
53
            f"TABPY_PWD_FILE = {cls.pwd_file.name}\n"
54
            f"TABPY_STATE_PATH = {cls.state_dir}"
55
        )
56
        cls.config_file.close()
57
58
    @classmethod
59
    def tearDownClass(cls):

tests/unit/server_tests/test_endpoints_handler.py 1 location

@@ 11-53 (lines=43) @@
8
9
10
class TestEndpointsHandlerWithAuth(AsyncHTTPTestCase):
11
    @classmethod
12
    def setUpClass(cls):
13
        prefix = "__TestEndpointsHandlerWithAuth_"
14
        # create password file
15
        cls.pwd_file = tempfile.NamedTemporaryFile(
16
            mode="w+t", prefix=prefix, suffix=".txt", delete=False
17
        )
18
        username = "username"
19
        password = "password"
20
        cls.pwd_file.write(f"{username} {hash_password(username, password)}")
21
        cls.pwd_file.close()
22
23
        # create state.ini dir and file
24
        cls.state_dir = tempfile.mkdtemp(prefix=prefix)
25
        cls.state_file = open(os.path.join(cls.state_dir, "state.ini"), "w+")
26
        cls.state_file.write(
27
            "[Service Info]\n"
28
            "Name = TabPy Serve\n"
29
            "Description = \n"
30
            "Creation Time = 0\n"
31
            "Access-Control-Allow-Origin = \n"
32
            "Access-Control-Allow-Headers = \n"
33
            "Access-Control-Allow-Methods = \n"
34
            "\n"
35
            "[Query Objects Service Versions]\n"
36
            "\n"
37
            "[Query Objects Docstrings]\n"
38
            "\n"
39
            "[Meta]\n"
40
            "Revision Number = 1\n"
41
        )
42
        cls.state_file.close()
43
44
        # create config file
45
        cls.config_file = tempfile.NamedTemporaryFile(
46
            mode="w+t", prefix=prefix, suffix=".conf", delete=False
47
        )
48
        cls.config_file.write(
49
            "[TabPy]\n"
50
            f"TABPY_PWD_FILE = {cls.pwd_file.name}\n"
51
            f"TABPY_STATE_PATH = {cls.state_dir}"
52
        )
53
        cls.config_file.close()
54
55
    @classmethod
56
    def tearDownClass(cls):

tests/unit/server_tests/test_evaluation_plane_handler.py 1 location

@@ 332-379 (lines=48) @@
329
330
331
class TestEvaluationPlaneHandlerDisabledWithAuth(AsyncHTTPTestCase):
332
    @classmethod
333
    def setUpClass(cls):
334
        prefix = "__TestEvaluationPlaneHandlerDisabledWithAuth_"
335
336
        # create password file
337
        cls.pwd_file = tempfile.NamedTemporaryFile(
338
            mode="w+t", prefix=prefix, suffix=".txt", delete=False
339
        )
340
        username = "username"
341
        password = "password"
342
        cls.pwd_file.write(f"{username} {hash_password(username, password)}\n")
343
        cls.pwd_file.close()
344
345
        # create state.ini dir and file
346
        cls.state_dir = tempfile.mkdtemp(prefix=prefix)
347
        cls.state_file = open(os.path.join(cls.state_dir, "state.ini"), "w+")
348
        cls.state_file.write(
349
            "[Service Info]\n"
350
            "Name = TabPy Serve\n"
351
            "Description = \n"
352
            "Creation Time = 0\n"
353
            "Access-Control-Allow-Origin = \n"
354
            "Access-Control-Allow-Headers = \n"
355
            "Access-Control-Allow-Methods = \n"
356
            "\n"
357
            "[Query Objects Service Versions]\n"
358
            "\n"
359
            "[Query Objects Docstrings]\n"
360
            "\n"
361
            "[Meta]\n"
362
            "Revision Number = 1\n"
363
        )
364
        cls.state_file.close()
365
366
        # create config file
367
        cls.config_file = tempfile.NamedTemporaryFile(
368
            mode="w+t", prefix=prefix, suffix=".conf", delete=False
369
        )
370
        cls.config_file.write(
371
            "[TabPy]\n"
372
            f"TABPY_PWD_FILE = {cls.pwd_file.name}\n"
373
            f"TABPY_STATE_PATH = {cls.state_dir}\n"
374
            f"TABPY_EVALUATE_ENABLE = false"
375
        )
376
        cls.config_file.close()
377
378
        cls.script = (
379
            '{"data":{"_arg1":[2,3],"_arg2":[3,-1]},'
380
            '"script":"res=[]\\nfor i in range(len(_arg1)):\\n  '
381
            'res.append(_arg1[i] * _arg2[i])\\nreturn res"}'
382
        )