MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / TestContainerModel

Class TestContainerModel

class/btdockerModel/test/containerModelTest.py:58–246  ·  view source on GitHub ↗

创建测试用例

Source from the content-addressed store, hash-verified

56 return self.get_container_list()['container_list'][0]['id']
57
58class TestContainerModel(unittest.TestCase):
59 """
60 创建测试用例
61 """
62
63 def test_connect_client(self):
64 """
65 测试docker客户端连接,判断返回值是否是docker.client.DockerClient实例
66 :return:
67 """
68 self.assertIsInstance(dp.docker_client(), docker.client.DockerClient)
69
70 def test_get_list(self):
71 """
72 测试调用containerModel中的get_list方法,获取所有容器列表
73 @return:
74 """
75 get = TestParamManage().get_dict_obj()
76 self.assertIsInstance(dc.main().get_list(get), dict)
77
78 def test_run(self):
79 """
80 测试创建容器
81 @return:
82 """
83 get = TestParamManage().get_dict_obj()
84 get.image = 'nginx:latest'
85 get.name = 'test_{}'.format(random.randint(10000, 65535))
86 get.port = {"80/tcp": format(random.randint(10000, 65535))}
87 get.volumes = {"/www/wwwroot/test": {"bind": "/usr/share/nginx/html", "mode": "rw"}}
88 get.environment = ''
89 get.labels = ''
90 get.network = ''
91 get.cpu_quota = 0
92 self.assertEqual(dc.main().run(get), {"status": True, "msg": "容器创建成功!"})
93
94 def test_run_cmd(self):
95 '''
96 @name 测试命令创建容器
97 @author wzz <2023/11/30 下午 3:07>
98 @param get.cmd 包含docker run的命令,不能含有危险字符
99 @return {"status": bool, "msg": info}
100 ''&#x27;
101 get = TestParamManage().get_dict_obj()
102 get.cmd = 'docker run -d --name test_{} nginx:latest'.format(random.randint(10000, 65535))
103 self.assertEqual(dc.main().run_cmd(get), {"status": True, "msg": "命令已执行完毕!"})
104
105 def test_upgrade_container(self):
106 ''&#x27;
107 @name 测试更新容器
108 @author wzz <2023/12/1 上午 9:53>
109 @param 参数名<数据类型> 参数描述
110 @return 数据类型
111 ''&#x27;
112 get = TestParamManage().get_dict_obj()
113 get.image = 'latest'
114 container_list = dc.main().get_list(get)
115

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected