How to use group_resources method in localstack

Best Python code snippet using localstack_python

test_group.py

Source:test_group.py Github

copy

Full Screen

1import pytest2from api_university.config import Configuration as Config3from api_university.responses.response_strings import gettext_4from api_university.models.group import GroupModel5from tests.test_data.data import group_count6api_url = Config.API_URL7group_resources = {8 'group': "{}/groups/{}",9 'full_group': "{}/groups/{}?full={}",10 'group_list': "{}/groups",11 'full_group_list': "{}/groups?full={}",12 'group_list_by_student_count': "{}/groups?student_count={}"13}14class TestGroup:15 @pytest.mark.parametrize("group_id", [1, 2, 3])16 # default (short schema)17 def test_get_default_group_schema(self, group_id, client):18 url = group_resources['group'].format(api_url, group_id)19 response = client.get(url)20 attrs_ = list(response.json.keys())21 assert response.status_code == 20022 assert 'application/json' in response.headers['Content-Type']23 assert attrs_ == ['group_id', 'name']24 assert response.json['group_id'] == group_id25 assert isinstance(response.json['name'], str) is True26 @pytest.mark.parametrize("group_id", [1, 2, 3])27 # full schema28 def test_get_full_default_group_schema(self, group_id, client):29 url = group_resources['full_group'].format(api_url, group_id, 'true')30 response = client.get(url)31 attrs_ = list(response.json.keys())32 assert response.status_code == 20033 assert 'application/json' in response.headers['Content-Type']34 assert attrs_ == ['group_id', 'name', 'students']35 assert response.json['group_id'] == group_id36 assert isinstance(response.json['name'], str) is True37 assert isinstance(response.json['students'], list) is True38 @pytest.mark.parametrize("group_id, json_to_send, result_json, student_count", [39 (40 4,41 {"name": "DD-44"},42 {'message': gettext_("group_post").format(4),43 'status': 200},44 045 ),46 (47 5,48 {"name": "EE-55",49 "students": [1, 3, 5]},50 {'message': gettext_("group_post").format(5),51 'status': 200},52 353 )54 ])55 def test_post(self, group_id, json_to_send, result_json, student_count, client):56 mimetype = 'application/json'57 headers = {58 'Content-Type': mimetype,59 'accept': mimetype60 }61 url = group_resources['group'].format(api_url, group_id)62 response = client.post(url, json=json_to_send, headers=headers)63 assert response.status_code == 20064 assert response.content_type == mimetype65 assert response.json == result_json66 assert GroupModel.find_by_id(group_id) is not None67 assert len(GroupModel.get_group_students(group_id)) == student_count68 @pytest.mark.parametrize("group_id, json_to_send, result_json, student_count", [69 (70 1,71 {"name": "DD-44"},72 {'message': gettext_("group_put").format(1),73 'status': 200},74 375 ),76 (77 3,78 {"add_students": [1, 5, 6],79 "delete_students": [8, 10],80 "name": "XY-77"},81 {'message': gettext_("group_put").format(3),82 'status': 200},83 384 )85 ])86 def test_put(self, group_id, json_to_send, result_json, student_count, client):87 mimetype = 'application/json'88 headers = {89 'Content-Type': mimetype,90 'accept': mimetype91 }92 url = group_resources['group'].format(api_url, group_id)93 response = client.put(url, json=json_to_send, headers=headers)94 assert response.status_code == 20095 assert response.content_type == mimetype96 assert response.json == result_json97 assert len(GroupModel.get_group_students(group_id)) == student_count98 @pytest.mark.parametrize("group_id, result_json, remaining_group_count", [99 (100 1,101 {'message': gettext_("group_delete").format(1),102 'status': 200},103 2104 ),105 (106 3,107 {'message': gettext_("group_delete").format(3),108 'status': 200},109 2110 )111 ])112 def test_delete(self, group_id, result_json, remaining_group_count, client):113 url = group_resources['group'].format(api_url, group_id)114 response = client.delete(url)115 assert response.status_code == 200116 assert response.content_type == 'application/json'117 assert response.json == result_json118 assert len(GroupModel.get_all_groups()) == remaining_group_count119class TestGroupException:120 @pytest.mark.parametrize("group_id, wrong_data", [121 (1, 'smth_wrong'),122 (2, 1000)123 ])124 # wrong query string "?full="125 def test_get_wrong_full(self, group_id, wrong_data, client):126 url = group_resources['full_group'].format(api_url, group_id, wrong_data)127 response = client.get(url)128 attrs_ = list(response.json.keys())129 assert response.status_code == 200130 assert 'application/json' in response.headers['Content-Type']131 assert attrs_ == ['group_id', 'name']132 assert response.json['group_id'] == group_id133 assert isinstance(response.json['name'], str) is True134 @pytest.mark.parametrize("group_id, json_to_send, status, result_json", [135 # 0 don't give required field:136 (137 4,138 {"students": [1, 2]},139 400,140 {'err_name': 'ValidationError',141 'message': {'name': ['Missing data for required field.']},142 'status': 400}143 ),144 # 1 course already exists:145 (146 1,147 {"name": "Physics"},148 400,149 {'message': gettext_("group_exists").format(1),150 'status': 400}151 ),152 # 2 give nonexistent students153 (154 4,155 {"name": "some_course", "students": [1000, 2000]},156 404,157 {'message': gettext_("student_not_found").format(1000),158 'status': 404}159 )160 ])161 def test_post_wrong_group(self, group_id, json_to_send, status, result_json, client):162 mimetype = 'application/json'163 headers = {164 'Content-Type': mimetype,165 'accept': mimetype166 }167 url = group_resources['group'].format(api_url, group_id)168 response = client.post(url, json=json_to_send, headers=headers)169 assert response.status_code == status170 assert response.content_type == mimetype171 assert response.json == result_json172 @pytest.mark.parametrize("group_id, json_to_send, status, result_json", [173 # 0 course not found174 (175 4,176 {"name": "TT-99"},177 404,178 {'message': gettext_("group_not_found").format(4),179 'status': 404}180 ),181 # 1 give 'students' list instead of 'add_students' and 'delete_students' lists182 (183 1,184 {"students": [1, 2, 3]},185 400,186 {"message": gettext_("group_err_put_students"),187 "status": 400}188 ),189 # 2 give nonexistent students190 (191 3,192 {"add_students": [1000, 2000]},193 404,194 {'message': gettext_("student_not_found").format(1000),195 'status': 404}196 )197 ])198 def test_put_wrong_group(self, group_id, json_to_send, status, result_json, client):199 mimetype = 'application/json'200 headers = {201 'Content-Type': mimetype,202 'accept': mimetype203 }204 url = group_resources['group'].format(api_url, group_id)205 response = client.put(url, json=json_to_send, headers=headers)206 assert response.status_code == status207 assert response.content_type == mimetype208 assert response.json == result_json209 @pytest.mark.parametrize("group_id, result_json, status", [210 # 0 delete nonexistence course211 (212 100,213 {'message': gettext_("group_not_found").format(100),214 'status': 404},215 404216 )217 ])218 def test_delete_wrong_group(self, group_id, status, result_json, client):219 mimetype = 'application/json'220 headers = {221 'Content-Type': mimetype,222 'accept': mimetype223 }224 url = group_resources['group'].format(api_url, group_id)225 response = client.delete(url, headers=headers)226 assert response.status_code == status227 assert response.content_type == mimetype228 assert response.json == result_json229class TestGroupList:230 # default (short schema)231 def test_get_default_schema(self, client):232 url = group_resources['group_list'].format(api_url)233 response = client.get(url)234 assert response.status_code == 200235 assert 'application/json' in response.headers['Content-Type']236 assert len(response.json) == group_count237 for group in response.json:238 attrs_ = list(group.keys())239 assert attrs_ == ['group_id', 'name']240 assert isinstance(group['name'], str) is True241 # full schema242 def test_get_full_schema(self, client):243 url = group_resources['full_group_list'].format(api_url, 'true')244 response = client.get(url)245 assert response.status_code == 200246 assert 'application/json' in response.headers['Content-Type']247 assert len(response.json) == group_count248 for full_group in response.json:249 attrs_ = list(full_group.keys())250 assert attrs_ == ['group_id', 'name', 'students']251 assert isinstance(full_group['name'], str) is True252 assert isinstance(full_group['students'], list) is True253 @pytest.mark.parametrize("student_count, number_of_group", [(1, 0), (3, 3), (6, 3)])254 def test_get_groups_filter_by_student_count(self, student_count, number_of_group, client):255 url = group_resources['group_list_by_student_count'].format(api_url, student_count)256 response = client.get(url)257 assert response.status_code == 200258 assert 'application/json' in response.headers['Content-Type']259 assert len(response.json) == number_of_group260 for group in response.json:261 attrs_ = list(group.keys())262 assert attrs_ == ['group_id', 'name']263 assert isinstance(group['name'], str) is True264class TestGroupListException:265 @pytest.mark.parametrize("wrong_data", ['smth_wrong', 1000])266 # wrong query string "?full="267 def test_get_wrong_full(self, wrong_data, client):268 url = group_resources['full_group_list'].format(api_url, wrong_data)269 response = client.get(url)270 assert response.status_code == 200271 assert 'application/json' in response.headers['Content-Type']272 assert len(response.json) == group_count273 for group in response.json:274 attrs_ = list(group.keys())275 assert attrs_ == ['group_id', 'name']276 assert isinstance(group['name'], str) is True277 @pytest.mark.parametrize("wrong_data, status, result_json", [278 (279 'smth_wrong',280 400,281 {'message': {'student_count': "invalid literal for int() with base 10: "282 "'smth_wrong'"}}283 ),284 (285 1000,286 200,287 [{'group_id': 1, 'name': 'AA-11'},288 {'group_id': 2, 'name': 'BB-22'},289 {'group_id': 3, 'name': 'CC-33'}]290 )291 ])292 # wrong query string "?student_count="293 def test_get_wrong_student_count(self, wrong_data, status, result_json, client):294 url = group_resources['group_list_by_student_count'].format(api_url, wrong_data)295 response = client.get(url)296 assert response.status_code == status297 assert 'application/json' in response.headers['Content-Type']...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...69 else:70 state['card_name'] = args71@para_tarot.got('card_name', prompt='你想要看哪张塔罗牌呢?')72async def handle_para_tarot(bot: Bot, event: GroupMessageEvent, state: T_State):73 group_resources = plugin_config.get_group_resources(group_id=event.group_id)74 card_name = state['card_name']75 if card_name is None:76 result = await handle_random_single_tarot(bot=bot, event=event, state=state)77 await para_tarot.finish(result)78 else:79 try:80 # 获取卡牌信息81 card = group_resources.pack.get_card_by_name(name=card_name)82 # 绘制卡图83 card_result = await generate_tarot_card(84 id_=card.id,85 resources=group_resources,86 need_desc=True,87 need_upright=True,88 need_reversed=True)89 if card_result.error:90 logger.error(f'{event.group_id}/{event.user_id} 生成塔罗牌图片失败, {card_result.info}')91 await para_tarot.send('生成塔罗牌图片失败了QAQ, 请稍后再试或联系管理员处理')92 return93 else:94 msg = MessageSegment.image(pathlib.Path(card_result.result).as_uri())95 logger.info(f'{event.group_id}/{event.user_id} 生成塔罗牌图片成功')96 await para_tarot.send(msg)97 return98 except Exception as e:99 logger.error(f'{event.group_id}/{event.user_id} 获取塔罗牌 {card_name} 信息失败, {repr(e)}')100 await para_tarot.finish(f'没有找到塔罗牌: {card_name}, 你发送的真的是卡牌名吗?')101async def handle_random_single_tarot(bot: Bot, event: GroupMessageEvent, state: T_State) -> Union[MessageSegment, str]:102 group_resources = plugin_config.get_group_resources(group_id=event.group_id)103 # 随机一张出来104 card = random.choice(group_resources.pack.cards)105 # 再随机正逆106 direction = random.choice([-1, 1])107 if direction == 1:108 need_upright = True109 need_reversed = False110 else:111 need_upright = False112 need_reversed = True113 # 绘制卡图114 card_result = await generate_tarot_card(115 id_=card.id,116 resources=group_resources,...

Full Screen

Full Screen

test_software_deployment_group.py

Source:test_software_deployment_group.py Github

copy

Full Screen

...74 self._wait_for_resource_status(75 stack_identifier, 'deployment', 'CREATE_IN_PROGRESS')76 nested_identifier = self.assert_resource_is_a_stack(77 stack_identifier, 'deployment')78 group_resources = self.list_group_resources(79 stack_identifier, 'deployment', minimal=False)80 self.assertEqual(4, len(group_resources))81 self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE',82 signal_required=True,83 resources_to_signal=group_resources)84 self.check_input_values(group_resources, 'foo', 'foo_input')85 self.update_stack(stack_identifier,86 template=template,87 environment={'parameters': {'input': 'input2'}},88 expected_status='UPDATE_IN_PROGRESS')89 nested_identifier = self.assert_resource_is_a_stack(90 stack_identifier, 'deployment')91 self.assertEqual(4, len(group_resources))92 self._wait_for_stack_status(stack_identifier, 'UPDATE_COMPLETE',93 signal_required=True,94 resources_to_signal=group_resources)95 self.check_input_values(group_resources, 'foo', 'input2')96 # We explicitly test delete here, vs just via cleanup and check97 # the nested stack is gone98 self._stack_delete(stack_identifier)99 self._wait_for_stack_status(100 nested_identifier, 'DELETE_COMPLETE',101 success_on_not_found=True)102 def test_deployment_crud(self):103 self.deployment_crud(self.sd_template)104 def test_deployment_crud_with_rolling_update(self):105 self.deployment_crud(self.sd_template_with_upd_policy)106 def test_deployments_create_delete_in_progress(self):107 stack_identifier = self.stack_create(108 template=self.sd_template,109 enable_cleanup=self.enable_cleanup,110 expected_status='CREATE_IN_PROGRESS')111 self._wait_for_resource_status(112 stack_identifier, 'deployment', 'CREATE_IN_PROGRESS')113 nested_identifier = self.assert_resource_is_a_stack(114 stack_identifier, 'deployment')115 group_resources = self.list_group_resources(116 stack_identifier, 'deployment', minimal=False)117 self.assertEqual(4, len(group_resources))118 # Now test delete while the stacks are still IN_PROGRESS119 self._stack_delete(stack_identifier)120 self._wait_for_stack_status(121 nested_identifier, 'DELETE_COMPLETE',...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful