class TestTag(): """ 请忽略这个类,很老了 """ # 由于参数化的代码比classmethod更早执行,所以需要放到最外层去执行 base_data=Tag().load_yaml("data/test_tag.yml") @classmethod # 做测试的初始化,只需要初始化一次 # 把tag标签都删除 def setup_class(cls): # 定义好Tag()对象,cls.a,其他def test都可以用self.a使用 cls.a=Tag() # 定义好要删除的的标签的名字 name_data=["aaa","bbb","tongtong","tongtong1"] # 获取标签的数据 data=cls.a.get_tag() # 对标签名字进行遍历 for name in name_data: # 通过name去找到对应的tag_id tag_id=cls.a.jsonpath(data,f'$..tag[?(@.name=="{name}")].id') # 删除标签的api需要传tag_id cls.a.delete_tag(tag_id) # 测试获取标签的用例 def test_get_tag(self): res=self.a.get_tag() assert res["errcode"] ==0 # print(json.dumps(res,indent=2)) # 使用参数化,数据都保存在yml文件,读取出来变成base_data @pytest.mark.parametrize(("oldname,newname"),base_data) # 测试一次增加标签,修改标签是否正常运行 def test_all(self,oldname,newname): # 增加成功,errcode就是0 assert self.a.add_tag(oldname)["errcode"] == 0 tag_id=self.a.jsonpath(self.a.get_tag(),f"$..tag[?(@.name=='{oldname}')].id")[0] # edit_tag修改标签需要传tag_id,获取即可,修改成功后,errcode就是0 assert self.a.edit_tag(tag_id,newname)["errcode"] == 0 # 测试删除是否成功的用例 def test_delete(self): name="zzz" # 当tag_id是一个可变的值,只要能够获取,弄成变量即可 tag_id = self.a.jsonpath(self.a.get_tag(), f"$..tag[?(@.name=='{name}')].id")[0] assert self.a.delete_tag(tag_id)["errcode"] ==0
class TestTag(): def setup_class(self): wework = WeWork() self.token = wework.get_token() self.tag = Tag() def test_create_tag(self): r = self.tag.create_tag(self.token) taglist = self.tag.get_tag_list(self.token) print(taglist) tagname = jsonpath(taglist, "$..tagname") assert "UI" in tagname def test_update_tag(self): r = self.tag.update_tag(self.token) taglist = self.tag.get_tag_list(self.token) tagname = jsonpath(taglist, "$..tagname") assert "UI design" in tagname def test_delete_tag(self): r = self.tag.delete_tag(self.token) taglist = self.tag.get_tag_list(self.token) print(taglist) assert len(taglist["taglist"]) == 0
url(identity_specific + r"/members$", IdentityMembershipList.as_view(), name="identity-membership-list"), url( identity_specific + r"/members/(?P<group_name>(%s)$" % user_match, IdentityMembership.as_view(), name="identity-membership-detail", ), ) public_apis = format_suffix_patterns( patterns( "", url(r"^profile$", Profile.as_view(), name="profile"), url(r"^group$", GroupList.as_view(), name="group-list"), url(r"^group/(?P<groupname>.*)$", Group.as_view()), url(r"^tag$", TagList.as_view(), name="tag-list"), url(r"^tag/(?P<tag_slug>.*)$", Tag.as_view()), url(r"^application$", ApplicationList.as_view(), name="application-list"), url(r"^application/search$", ApplicationSearch.as_view(), name="application-search"), url(r"^application/(?P<app_uuid>[a-zA-Z0-9-]+)$", Application.as_view(), name="application-detail"), url(r"^instance_history$", InstanceHistory.as_view(), name="instance-history"), url( r"^instance_history/" "(?P<instance_id>[a-zA-Z0-9-]+)$", InstanceHistoryDetail.as_view(), name="instance-history", ), url( r"^instance_history/" "(?P<instance_id>[a-zA-Z0-9-]+)/" "status_history$", InstanceStatusHistoryDetail.as_view(), name="instance-history", ), url(
name='maintenance-record'), url(r'^api/v1/notification/$', NotificationList.as_view()), #url(r'^api/v1/user/$', atmo_valid_token_required(UserManagement.as_view())), #url(r'^api/v1/user/(?P<username>.*)/$', User.as_view()), url(r'^api/v1/profile/$', Profile.as_view(), name='profile'), url(r'^api/v1/provider/(?P<provider_id>\d+)/occupancy/$', Occupancy.as_view(), name='occupancy'), url(r'^api/v1/provider/(?P<provider_id>\d+)/hypervisor/$', Hypervisor.as_view(), name='hypervisor'), url(r'^api/v1/group/$', GroupList.as_view(), name='group-list'), url(r'^api/v1/group/(?P<groupname>.*)/$', Group.as_view()), url(r'^api/v1/tag/$', TagList.as_view(), name='tag-list'), url(r'^api/v1/tag/(?P<tag_slug>.*)/$', Tag.as_view()), url(r'^api/v1/application/$', ApplicationListNoAuth.as_view(), name='application-list-no-auth'), url(r'^api/v1/instance/$', InstanceHistory.as_view(), name='instance-history'), url(r'^api/v1/request_image/$', MachineRequestStaffList.as_view(), name='direct-machine-request-list'), url(r'^api/v1/request_image/(?P<machine_request_id>\d+)/$', MachineRequestStaff.as_view(), name='direct-machine-request-detail'), url(r'^api/v1/request_image/(?P<machine_request_id>\d+)/(?P<action>.*)/$', MachineRequestStaff.as_view(), name='direct-machine-request-action'),
def setup_class(self): self.tag = Tag()
class TestTag: def setup_class(self): self.tag = Tag() def teardown_class(self): pass def setup(self): pass def teardown(self): pass @pytest.mark.parametrize("group_name, tag_name,order", [ ['测试','test1', 1], ['测试','test2', 2], ['客户等级', '1级', 1], ['客户等级', '2级', 2] ]) def test_add_list(self,group_name, tag_name, order): group_name=group_name tag = [{"name": tag_name, "order": order}] r = self.tag.add(group_name=group_name,tag=tag) result = r assert result == tag_name @pytest.mark.parametrize("group_name, name,order", [ ['测试', 'ddddddddddddddddddddddddddddddd', 1] ]) def test_add_list_fail(self, group_name, name, order): group_name = group_name tag = [{"name": name, "order": order}] r = self.tag.add_fail(group_name=group_name, tag=tag) assert 'tag.name exceed max utf8 words 30' in r.json()['errmsg'] @pytest.mark.parametrize("group_name,tag_name,i", [ ['测试','tag1_new_',0], ['客户等级','tag1——中文',0], ['测试','tag1[中文]',1], ['客户等级', 'tag2——abcDE d', 1] ]) def test_tag_update_list(self, group_name,tag_name,i): tag_name = tag_name + str(datetime.datetime.now().strftime("%Y%m%d-%H%M%S")) tag_id = self.tag.get_tag_id(group_name)[i]#改第i个标签名字 r = self.tag.list() r = self.tag.update( id=tag_id, tag_name=tag_name ) r = self.tag.list() # tags = [ # tag # for group in r.json()['tag_group'] if group['group_name'] == group_name # for tag in group['tag'] if tag['name'] == tag_name # ] assert jsonpath(r.json(), f"$..[?(@.name=='{tag_name}')]")[0]['name'] == tag_name # assert tags != [] @pytest.mark.parametrize("group_name,tag_name", [ ['测试','DFDASFSDFDSAFADSFDSAF'], ['客户等级','DFDASFSDFDSAFADSFDSAF'] ] ) def test_tag_update_list_fail(self,group_name,tag_name): tag_name = tag_name + str(datetime.datetime.now().strftime("%Y%m%d-%H%M%S")) tag_id = self.tag.get_tag_id(group_name) r = self.tag.list() r = self.tag.update( id=tag_id, tag_name=tag_name ) assert "name exceed max utf8 words 30" in r.json()['errmsg'] def test_del_tagid_all(self): group_name = self.tag.get_group_name() for i in group_name: tag_id = self.tag.get_tag_id(group_name=i) r = self.tag.delete_tag_id(tag_id) assert r['errcode'] == 0 assert r['errmsg'] == 'ok'
def test_addTag(self): print(Tag().addTag("tagName3"))
url(identity_specific + r'/members$', IdentityMembershipList.as_view(), name='identity-membership-list'), url(identity_specific + r'/members/(?P<group_name>%s)$' % user_match, IdentityMembership.as_view(), name='identity-membership-detail'), ) public_apis = format_suffix_patterns( patterns( '', url(r'^profile$', Profile.as_view(), name='profile'), url(r'^group$', GroupList.as_view(), name='group-list'), url(r'^group/(?P<groupname>.*)$', Group.as_view()), url(r'^tag$', TagList.as_view(), name='tag-list'), url(r'^tag/(?P<tag_slug>.*)$', Tag.as_view()), url(r'^application$', ApplicationList.as_view(), name='application-list'), url(r'^application/search$', ApplicationSearch.as_view(), name='application-search'), url(r'^application/(?P<app_uuid>%s)$' % uuid_match, Application.as_view(), name='application-detail'), #ApplicationThreshold Related APIs url(r'^application/(?P<app_uuid>%s)/threshold$' % uuid_match, ApplicationThresholdDetail.as_view(), name='threshold-detail'), url(r'^instance_history$', InstanceHistory.as_view(),
def test_add_tag(self): print(Tag().add("abcde"))
def setup_class(cls): cls.tag = Tag()
#!/usr/bin/env python
class Testtag: def setup_class(self): self.tag = Tag() @pytest.mark.parametrize( "tag_id,tag_name", [['etL_AEDgAAmLkcZSXNBosVXWhnExVQaA', 'hogwarts01_aaaa'], ['etL_AEDgAAmLkcZSXNBosVXWhnExVQaA', 'hogwarts01_bbbb'], ['etL_AEDgAAmLkcZSXNBosVXWhnExVQaA', 'hogwarts01_ddddd']]) def test_tag_list(self, tag_id, tag_name): group_name = "hogwarts01" tag_id = tag_id tag_name = tag_name + str(datetime.datetime.now().strftime("%s")) r = self.tag.list() r = self.tag.update(id=tag_id, tag_name=tag_name) r = self.tag.list() tags = [] for group in r.json()['tag_group']: if group['group_name'] == group_name: for tag in group['tag']: if tag['name'] == tag_name: tags.append(tag) print(tags) # jsonpath(f"$..[?(@.name='{tag_name}')]") assert tags != "" def test_add_tag(self): add_group = "GROUP_123" add_tag = [ { "name": "TAG_NAME_1" }, { "name": "TAG_NAME_2" }, { "name": "TAG_NAME_3" }, ] self.tag.add(groupname=add_group, tagname=add_tag) def test_list(self): self.tag.list() def test_delete(self): oldtag = ["etL_AEDgAAv9KhmVVswhhbK9EdoI2aYw"] self.tag.delete_tag(oldtag) def test_add_and_detect_tag(self): add_group = "GROUP_123" add_tag = [ { "name": "TAG_NAME_1" }, { "name": "TAG_NAME_2" }, { "name": "TAG_NAME_3" }, ] self.tag.add_and_detect(groupname=add_group, tagname=add_tag)
def test_deleteTag(self): print(Tag().deleteTag("etjN3BBwAA-nIOzsPbyu_1-PqfS-9_OQ"))
def test_editTag(self): print(Tag().editTag("etjN3BBwAAv-FpTaZp2iTfgxgOv3ZOnw", "zhangsan"))
def setup_class(self): wework = WeWork() self.token = wework.get_token() self.tag = Tag()
def test_delete(self): tag_name = "abc" tag_data = self.tag.get() tag_id = self.jsonpath(tag_data, f"$..tag[?(@.name=='{tag_name}')].id")[0] print(Tag().delete(tag_id))
def test_update(self): print(Tag().update("etMCs1DwAAsL96xN_6Y5gEfadl2qexbw", "abcd"))
def setup_class(cls): cls.tag = Tag() #遍历删除测试数据 cls.reset()
def setup(self): self.tag = Tag()
url(identity_specific + r'/members$', IdentityMembershipList.as_view(), name='identity-membership-list'), url(identity_specific + r'/members/(?P<group_name>%s)$' % user_match, IdentityMembership.as_view(), name='identity-membership-detail'), ) public_apis = format_suffix_patterns(patterns( '', url(r'^profile$', Profile.as_view(), name='profile'), url(r'^group$', GroupList.as_view(), name='group-list'), url(r'^group/(?P<groupname>.*)$', Group.as_view()), url(r'^tag$', TagList.as_view(), name='tag-list'), url(r'^tag/(?P<tag_slug>.*)$', Tag.as_view()), url(r'^application$', ApplicationList.as_view(), name='application-list'), url(r'^application/search$', ApplicationSearch.as_view(), name='application-search'), url(r'^application/(?P<app_uuid>%s)$' % uuid_match, Application.as_view(), name='application-detail'), #ApplicationThreshold Related APIs url(r'^application/(?P<app_uuid>%s)/threshold$' % uuid_match, ApplicationThresholdDetail.as_view(), name='threshold-detail'),
def test_getTag(self): print(json.dumps(Tag().getTag(), indent=2))