Best Python code snippet using localstack_python
test_tag_api.py
Source:test_tag_api.py
1# -*- coding: utf-8 -*-2# @Time :2020/12/13 17:243# @Author :robot_zsj4# @File :test_tag_api.py5import pytest6from homework.api.one.tag_api import TagApi7class TestTagAPi:8 def setup_class(self):9 # todoï¼ æ°æ®æ¸
ç10 self.tag = TagApi()11 self.tag.get_token()12 # æ¯æ¡æ¡ä¾ä¹åæ¸
é¤æ°æ®13 def setup(self):14 r = self.tag.list()15 tag_group = r.json()['tag_group']16 if len(tag_group) != 0:17 self.group_tag_get(tag_group)18 self.data_delete(self.data)19 self.setup()20 # è·åæ ç¾21 def test_tag_list(self):22 # todo: å®ååè½23 r = self.tag.list()24 assert r.json()['errcode'] == 025 # æ ç¾æ·»å 26 @pytest.mark.parametrize("group_name, tags_name", [27 ["group_1", [{"name": "robot1"}]],28 ["group_2", [{"name": "robot2"}]]29 ])30 def test_tag_add(self, group_name, tags_name):31 r = self.tag.list()32 assert r.json()['errcode'] == 033 r = self.tag.add(group_name, tags_name)34 assert r.json()['errcode'] == 035 r = self.tag.list()36 assert r.json()['errcode'] == 037 group = [group for group in r.json()['tag_group'] if group['group_name'] == group_name][0]38 tags = [{'name': tag['name']} for tag in group['tag']]39 print(group)40 print(tags)41 assert group['group_name'] == group_name42 assert tags == tags_name43 # æ ç¾å é¤44 @pytest.mark.parametrize("group_name, tags_name", [45 ["group_1", [{"name": "robot1"}]],46 ["group_2", [{"name": "robot2"}]]47 ])48 def test_tag_delete(self, group_name, tags_name):49 r = self.tag.add(group_name, tags_name)50 assert r.json()['errcode'] == 051 r = self.tag.list()52 assert r.json()['errcode'] == 053 tag_group = r.json()['tag_group']54 if len(tag_group) != 0:55 self.group_tag_get(tag_group)56 for group_id, tag_id in self.data.items():57 res = self.test_delete([group_id], tag_id)58 print(res)59 def test_update(self):60 pass61 def test_tag_add_fail(self):62 pass63 # åå¨ç°ææ ç¾64 def group_tag_get(self, tag_group):65 g_id_dict = {}66 for item in tag_group:67 g_id = item['group_id']68 t_id_list = []69 for t in item['tag']:70 t_id_list.append(t['id'])71 g_id_dict[g_id] = t_id_list72 self.data = g_id_dict73 # å é¤ç°ææ ç¾74 def data_delete(self, dict_data: dict):75 for group_id, tag_id in dict_data.items():76 self.test_delete([group_id], tag_id)77 # å é¤æ ç¾78 def test_delete(self, group_id, tag_id):79 r = self.tag.delete(group_id, tag_id)80 # res = r.json()81 print(r.json())...
tests.py
Source:tests.py
...4 @classmethod5 def setUpTestData(cls):6 super().setUpTestData()7 cls.tags = TagFactory.create_batch(merchant=cls.merchant, size=3)8 def test_tag_api(self):9 self.client.force_authenticate(self.driver)10 resp = self.client.get('/api/mobile/tags/v1/')11 self.assertEqual(resp.status_code, 200)...
__init__.py
Source:__init__.py
1from .test_misc import TestMisc2from .test_routes import TestRoutes3from .test_tag_api import TestTagApi...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!