1
+ from fastapi .testclient import TestClient
2
+ from main import app
3
+ from suite import *
4
+
5
+ """
6
+ Created a TestClient instance and define a dictionary run_dic with test data for the make_run_name function,
7
+ then called the function with the test data and assert that the result matches the expected output
8
+ """
9
+
10
+ def test_make_run_name ():
11
+ client = TestClient (app )
12
+ run_dic = {
13
+ "user" : "testuser" ,
14
+ "timestamp" : "2022-03-21_14:30:00" ,
15
+ "suite" : "rados" ,
16
+ "ceph_branch" : "ceph1" ,
17
+ "kernel_branch" : "kernel1" ,
18
+ "flavor" : "test-flavor" ,
19
+ "machine_type" : "test-machine"
20
+ }
21
+ expected_result = "testuser-2022-03-21_14:30:00-rados-ceph1-kernel1-test-flavor-test-machine"
22
+ assert make_run_name (run_dic ) == expected_result
23
+
24
+ """
25
+ Test the `make_run_name` function with an input dictionary containing a single worker machine type.
26
+ """
27
+ def test_make_run_name_with_single_worker ():
28
+ run_dic = {
29
+ "user" : "test_user" ,
30
+ "timestamp" : "2022-03-21_14:30:00" ,
31
+ "suite" : "rados" ,
32
+ "ceph_branch" : "ceph1" ,
33
+ "kernel_branch" : "kernel1" ,
34
+ "flavor" : "test-flavor" ,
35
+ "machine_type" : "worker1"
36
+ }
37
+ expected_run_name = "test_user-2022-03-21_14:30:00-rados-ceph1-kernel1-test-flavor-worker1"
38
+ assert make_run_name (run_dic ) == expected_run_name
39
+
40
+ """
41
+ Test the `make_run_name` function with a multi-machine type input dictionary.
42
+ """
43
+
44
+ def test_make_run_name_with_multi_worker ():
45
+ run_dic = {
46
+ "user" : "test_user" ,
47
+ "timestamp" : "2022-03-21_14:30:00" ,
48
+ "suite" : "rados" ,
49
+ "ceph_branch" : "ceph1" ,
50
+ "kernel_branch" : "kernel1" ,
51
+ "flavor" : "test-flavor" ,
52
+ "machine_type" : "worker1,worker2,worker3"
53
+ }
54
+ expected_run_name = "test_user-2022-03-21_14:30:00-rados-ceph1-kernel1-test-flavor-multi"
55
+ assert make_run_name (run_dic ) == expected_run_name
56
+
57
+ """
58
+ Test the function for no kernel branch
59
+ """
60
+ def test_make_run_name_with_no_kernel_branch ():
61
+ run_dic = {
62
+ "user" : "teuthology" ,
63
+ "timestamp" : "2022-03-21_14:30:00" ,
64
+ "suite" : "rados" ,
65
+ "ceph_branch" : "ceph1" ,
66
+ "kernel_branch" : None ,
67
+ "flavor" : "test-flavor" ,
68
+ "machine_type" : "test-machine"
69
+ }
70
+ expected_run_name = "teuthology-2022-03-21_14:30:00-rados-ceph1-distro-test-flavor-test-machine"
71
+ assert make_run_name (run_dic ) == expected_run_name
0 commit comments