Best Python code snippet using localstack_python
test_fixture.py
Source:test_fixture.py
1import json2import inspect # иÑполÑзÑем меÑод Ð´Ð»Ñ Ð²Ð¾Ð·Ð²ÑаÑÐµÐ½Ð¸Ñ Ð¸Ð¼ÐµÐ½Ð¸ ÑÑнкÑии3from conftest import do_repeat_it, add_file_log # импоÑÑиÑÑем декоÑаÑоÑÑ4from app.api_fixture import PetFriends5import pytest6import os7pf = PetFriends()8@pytest.mark.usefixtures("get_name_func") # ÑикÑÑÑÑа Ð´Ð»Ñ Ð²Ñвода в конÑоли Ð½Ð°Ð·Ð²Ð°Ð½Ð¸Ñ ÑеÑÑа9def test_get_api_key(get_api_keys): # в аÑгÑменÑе ÑÑнкÑии - ÑикÑÑÑÑа Ð´Ð»Ñ Ð¿Ð¾Ð»ÑÑÐµÐ½Ð¸Ñ ÐºÐ»ÑÑа10 """ ÐÑовеÑÑем, ÑÑо запÑÐ¾Ñ ÐºÐ»ÑÑа возвÑаÑÐ°ÐµÑ ÑÑаÑÑÑ 200 и ÑодеÑжиÑÑÑ Ñлово key"""11 result = get_api_keys12 with open("out_json.json", 'w', encoding='utf8') as my_file:13 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n') # ÐÑводим Ð¸Ð¼Ñ ÑÑнкÑии, как заголовок оÑвеÑа14 json.dump(result, my_file, ensure_ascii=False, indent=4)15 # СвеÑÑем полÑÑеннÑе даннÑе Ñ Ð½Ð°Ñими ожиданиÑми16 assert 'key' in result17@pytest.mark.usefixtures("get_name_func")18@do_repeat_it # декоÑаÑÐ¾Ñ Ð´Ð»Ñ Ð²Ñзова ÑÑнкÑии неÑколÑко Ñаз19def test_add_new_pet(get_api_keys, name='King-Kong', animal_type='Monkey', age='188', pet_photo=r'../images/king-kong1.jpg'):20 """ÐÑовеÑÑем, ÑÑо можно добавиÑÑ Ð¿Ð¸ÑомÑа Ñ ÐºÐ¾ÑÑекÑнÑми даннÑми"""21 # ÐолÑÑаем полнÑй пÑÑÑ Ð¸Ð·Ð¾Ð±ÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð¿Ð¸ÑомÑа и ÑоÑ
ÑанÑем в пеÑеменнÑÑ pet_photo22 pet_photo = os.path.join(os.path.dirname(__file__), pet_photo)23 # ÐобавлÑем пиÑомÑа24 status, result, content, optional = pf.add_new_pet(get_api_keys, name, animal_type, age, pet_photo)25 with open("out_json.json", 'a', encoding='utf8') as my_file:26 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n')27 json.dump(result, my_file, ensure_ascii=False, indent=4)28 print('\nContent:', content)29 print('Optional:', optional)30 # СвеÑÑем полÑÑеннÑй оÑÐ²ÐµÑ Ñ Ð¾Ð¶Ð¸Ð´Ð°ÐµÐ¼Ñм ÑезÑлÑÑаÑом31 assert status == 20032 assert result['name'] == name, result['animal_type'] == animal_type and result['age'] == age33@pytest.mark.usefixtures("get_name_func")34@add_file_log # декоÑаÑÐ¾Ñ Ð´Ð»Ñ Ð¿Ð¾Ð»ÑÑÐµÐ½Ð¸Ñ Ð¾ÑвеÑа запÑоÑа в Ñайл35def test_get_all_pets(get_api_keys, filter='my_pets'):36 """ÐÑовеÑÑем, ÑÑо запÑÐ¾Ñ Ð²Ð¾Ð·Ð²ÑаÑÐ°ÐµÑ Ð²ÑеÑ
пиÑомÑев"""37 # ÐÑли Ñ Ð¿Ð¾Ð»ÑзоваÑÐµÐ»Ñ Ð½ÐµÑ Ð·Ð°Ð³ÑÑженнÑÑ
пиÑомÑев, помеÑим ÑеÑÑ, как падаÑÑий ÑеÑез маÑÐºÐµÑ xfail38 _, my_pets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")39 if len(my_pets['pets']) == 0:40 pytest.xfail("ТеÑÑ ÑабоÑий, возможно пÑоÑÑо Ð½ÐµÑ Ð·Ð°Ð³ÑÑженнÑÑ
пиÑомÑев.")41 status, result, content, optional = pf.get_list_of_pets(get_api_keys, filter)42 with open("out_json.json", 'a', encoding='utf8') as my_file:43 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n') # ÐÑводим Ð¸Ð¼Ñ ÑÑнкÑии, как заголовок оÑвеÑа44 my_file.write(str(f'\n{status}\n{content}\n{optional}\n'))45 json.dump(result, my_file, ensure_ascii=False, indent=4)46 print('\nContent:', content)47 print('Optional:', optional)48 assert status == 20049 assert len(result['pets']) > 050@pytest.mark.usefixtures("get_name_func")51def test_update_pet_info(get_api_keys, name='Ping-Pong', animal_type='Gorila/Monkey', age='155'):52 """ÐÑовеÑÑем возможноÑÑÑ Ð¾Ð±Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ñ Ð¸Ð½ÑоÑмаÑии о пиÑомÑе"""53 # ÐолÑÑаем клÑÑ auth_key и ÑпиÑок ÑвоиÑ
пиÑомÑев54 _, my_pets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")55 # ÐÑли ÑпиÑок не пÑÑÑой, Ñо пÑобÑем обновиÑÑ ÐµÐ³Ð¾ имÑ, Ñип и возÑаÑÑ56 if len(my_pets['pets']) > 0:57 status, result, content, optional = pf.update_pet_info(get_api_keys, my_pets['pets'][0]['id'], name, animal_type, age)58 with open("out_json.json", 'a', encoding='utf8') as my_file:59 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n')60 json.dump(result, my_file, ensure_ascii=False, indent=4)61 print('\nContent:', content)62 print('Optional:', optional)63 # ÐÑовеÑÑем ÑÑо ÑÑаÑÑÑ Ð¾ÑвеÑа = 200 и новÑе даннÑе пиÑомÑа ÑооÑвеÑÑÑвÑÐµÑ Ð·Ð°Ð´Ð°Ð½Ð½Ñм64 assert status == 20065 assert result['name'] == name, result['animal_type'] == animal_type and result['age'] == age66 else:67 # еÑли ÑпиÑок пиÑомÑев пÑÑÑой, Ñо вÑкидÑваем иÑклÑÑение Ñ ÑекÑÑом об оÑÑÑÑÑÑвии ÑвоиÑ
пиÑомÑев68 raise Exception("There is no my pets!")69"""ТеÑÑиÑÑем Ñоздание нового пиÑомÑа без ÑоÑо"""70@pytest.mark.usefixtures("get_name_func")71def test_add_pet_NOfoto(get_api_keys, name='King-Bongs', animal_type='Monkey-Milk', age='122'):72 # ÐобавлÑем пиÑомÑа73 status, result, content, optional = pf.add_new_pet_nofoto(get_api_keys, name, animal_type, age)74 with open("out_json.json", 'a', encoding='utf8') as my_file:75 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n')76 json.dump(result, my_file, ensure_ascii=False, indent=4)77 print('\nContent:', content)78 print('Optional:', optional)79 # СвеÑÑем полÑÑеннÑй оÑÐ²ÐµÑ Ñ Ð¾Ð¶Ð¸Ð´Ð°ÐµÐ¼Ñм ÑезÑлÑÑаÑом80 assert status == 20081 assert result['name'] == name, result['animal_type'] == animal_type and result['age'] == age82 assert result.get('pet_photo') == ''83@pytest.mark.usefixtures("get_name_func")84def test_add_foto_to_pet(get_api_keys, pet_photo=r'../images/king-kong2.jpg'):85 """ТеÑÑиÑÑем добавление ÑоÑо к id Ñозданного пиÑомÑа без ÑоÑо"""86 # ÐолÑÑаем полнÑй пÑÑÑ Ð¸Ð·Ð¾Ð±ÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð¿Ð¸ÑомÑа и ÑоÑ
ÑанÑем в пеÑеменнÑÑ pet_photo87 pet_photo = os.path.join(os.path.dirname(__file__), pet_photo)88 _, my_pets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")89 pet_id = my_pets['pets'][0]['id'] # id изменÑемого пиÑомÑа90 # ÐобавлÑем ÑоÑо91 status, result, content, optional = pf.add_pet_photo(get_api_keys, pet_photo, pet_id)92 with open("out_json.json", 'a', encoding='utf8') as my_file:93 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n')94 json.dump(result, my_file, ensure_ascii=False, indent=4)95 print('\nContent:', content)96 print('Optional:', optional)97 # СвеÑÑем полÑÑеннÑй оÑÐ²ÐµÑ Ñ Ð¾Ð¶Ð¸Ð´Ð°ÐµÐ¼Ñм ÑезÑлÑÑаÑом98 assert status == 20099 # ÐÑли даннÑй ÑекÑÑ ÑодеÑжиÑÑÑ Ð² полÑÑенном оÑвеÑе, Ñо Passed:100 assert 'data:image/jpeg' in result.get('pet_photo')101@pytest.mark.skip(reason="ÐÑÑÑ Ð´Ð»Ñ ÑоÑо задан некоÑÑекÑно!")102def test_add_foto_to_pet_skip(get_api_keys, pet_photo=r'../images/king-kong44.jpg'):103 """ТеÑÑиÑÑем skip (пÑопÑÑк) по какой-либо пÑиÑине"""104 # ÐолÑÑаем полнÑй пÑÑÑ Ð¸Ð·Ð¾Ð±ÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð¿Ð¸ÑомÑа и ÑоÑ
ÑанÑем в пеÑеменнÑÑ pet_photo105 pet_photo = os.path.join(os.path.dirname(__file__), pet_photo)106 _, my_pets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")107 pet_id = my_pets['pets'][0]['id'] # id изменÑемого пиÑомÑа108 # ÐобавлÑем ÑоÑо109 status, result, content, optional = pf.add_pet_photo(get_api_keys, pet_photo, pet_id)110 with open("out_json.json", 'a', encoding='utf8') as my_file:111 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n')112 json.dump(result, my_file, ensure_ascii=False, indent=4)113 print('\nContent:', content)114 print('Optional:', optional)115 # СвеÑÑем полÑÑеннÑй оÑÐ²ÐµÑ Ñ Ð¾Ð¶Ð¸Ð´Ð°ÐµÐ¼Ñм ÑезÑлÑÑаÑом116 assert status == 200117 # ÐÑли даннÑй ÑекÑÑ ÑодеÑжиÑÑÑ Ð² полÑÑенном оÑвеÑе, Ñо Passed:118 assert 'data:image/jpeg' in result.get('pet_photo')119"""ТеÑÑиÑÑем изменение ÑоÑо, добавленного Ñанее пиÑомÑа"""120@pytest.mark.usefixtures("get_name_func")121def test_changes_foto(get_api_keys, pet_photo=r'../images/king-kong3.jpg'):122 # # ÐолÑÑаем полнÑй пÑÑÑ Ð¸Ð·Ð¾Ð±ÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð¿Ð¸ÑомÑа и ÑоÑ
ÑанÑем в пеÑеменнÑÑ pet_photo123 pet_photo = os.path.join(os.path.dirname(__file__), pet_photo)124 # ÐолÑÑаем ÑпиÑок пиÑомÑев и беÑÑм id поÑледнего добавленного125 _, my_pets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")126 pet_id = my_pets['pets'][0]['id'] # id изменÑемого пиÑомÑа127 value_image1 = my_pets['pets'][0]['pet_photo'] # image изменÑемой ÑоÑки128 print(f"\nvalue_image1: {len(str(value_image1))} Ñимволов: {value_image1}", sep='')129 # ÐобавлÑем ÑоÑо130 status, result, content, optional = pf.add_pet_photo(get_api_keys, pet_photo, pet_id)131 value_image2 = result.get('pet_photo')132 print(f"value_image2: {len(str(value_image2))} Ñимволов: {value_image2}")133 with open("out_json.json", 'a', encoding='utf8') as my_file:134 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n')135 json.dump(result, my_file, ensure_ascii=False, indent=4)136 print('\nContent:', content)137 print('Optional:', optional)138 # СвеÑÑем полÑÑеннÑй оÑÐ²ÐµÑ Ñ Ð¾Ð¶Ð¸Ð´Ð°ÐµÐ¼Ñм ÑезÑлÑÑаÑом139 assert status == 200140 # ÐÑли ÑекÑÑ Ð¿ÐµÑвой ÑоÑки не Ñавен ÑекÑÑÑ Ð²ÑоÑой, Ñо Passed:141 assert value_image1 != value_image2142@pytest.mark.usefixtures("get_name_func_setup", "time_delta_teardown")143class TestDeletePets:144 """ТеÑÑиÑÑем возможноÑÑÑ ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ Ð¾Ð´Ð½Ð¾Ð³Ð¾ пиÑомÑа"""145 def test_delete_first_pet(self, get_api_keys):146 # ÐапÑаÑиваем ÑпиÑок ÑвоиÑ
пиÑомÑев147 _, my_pets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")148 # ÐÑовеÑÑем - еÑли ÑпиÑок ÑвоиÑ
пиÑомÑев пÑÑÑой, Ñо добавлÑем нового и опÑÑÑ Ð·Ð°Ð¿ÑаÑиваем ÑпиÑок ÑвоиÑ
пиÑомÑев149 if len(my_pets['pets']) == 0:150 pf.add_new_pet(get_api_keys, "King-Kong", "Gorila", "133", r'../images/king-kong2.jpg')151 _, my_pets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")152 # ÐеÑÑм id пеÑвого пиÑомÑа из ÑпиÑка и оÑпÑавлÑем запÑÐ¾Ñ Ð½Ð° Ñдаление153 pet_id = my_pets['pets'][0]['id']154 status, result, content, optional = pf.delete_pet(get_api_keys, pet_id)155 with open("out_json.json", 'a', encoding='utf8') as my_file:156 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n')157 json.dump(result, my_file, ensure_ascii=False, indent=4)158 print('\nContent:', content)159 print('Optional:', optional)160 # ÐÑÑ Ñаз запÑаÑиваем ÑпиÑок ÑвоиÑ
пиÑомÑев161 _, my_pets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")162 # ÐÑовеÑÑем ÑÑо ÑÑаÑÑÑ Ð¾ÑвеÑа Ñавен 200 и в ÑпиÑке пиÑомÑев Ð½ÐµÑ id ÑдалÑнного пиÑомÑа163 assert status == 200164 assert pet_id not in my_pets.values()165 """ТеÑÑиÑÑем Ñдаление вÑеÑ
пиÑомÑев"""166 def test_delete_all_pets(self, get_api_keys):167 # ÐолÑÑаем клÑÑ auth_key и запÑаÑиваем ÑпиÑок ÑвоиÑ
пиÑомÑев168 _, my_pets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")169 with open("out_json.json", 'a', encoding='utf8') as my_file:170 my_file.write(f'\n{inspect.currentframe().f_code.co_name}/ÑекÑÑий ÑпиÑок пиÑомÑев:\n')171 json.dump(my_pets, my_file, ensure_ascii=False, indent=4)172 pet_id = my_pets['pets'][0]['id']173 # ÐолÑÑаем в Ñикле id вÑеÑ
пиÑомÑев из ÑпиÑка и оÑпÑавлÑем запÑÐ¾Ñ Ð½Ð° Ñдаление:174 for id_pet in my_pets["pets"]:175 pf.delete_pet(get_api_keys, id_pet["id"])176 # ÐÑÑ Ñаз запÑаÑиваем ÑпиÑок пиÑомÑев:177 status, my_pets, content, optional = pf.get_list_of_pets(get_api_keys, "my_pets")178 with open("out_json.json", 'a', encoding='utf8') as my_file:179 my_file.write(f'\n{inspect.currentframe().f_code.co_name}/ÑпиÑок поÑле ÑдалениÑ:\n')180 json.dump(my_pets, my_file, ensure_ascii=False, indent=4)181 print('\nContent:', content)182 print('Optional:', optional)183 assert status == 200...
test_pet_friends.py
Source:test_pet_friends.py
1from api import PetFriends2from settigs import *3from conftest import *4import pytest5import os6import json7import requests8import inspect # иÑполÑзÑем меÑод Ð´Ð»Ñ Ð²Ð¾Ð·Ð²ÑаÑÐµÐ½Ð¸Ñ Ð¸Ð¼ÐµÐ½Ð¸ ÑÑнкÑии9pf = PetFriends()10def generate_string(n):11 return "x" * n12def russian_chars():13 return 'абвгдеÑжзийклмнопÑÑÑÑÑÑ
ÑÑÑÑÑÑÑÑÑÑ'14def chinese_chars():15 return 'çä¸æ¯ä¸äºäººæå¨æä»è¿ä¸ºä¹å¤§æ¥ä»¥ä¸ªä¸ä¸ä»¬'16def special_chars():17 return '|\\/!@#$%^&*()-_=+`~?"â;:[]{}'18@pytest.fixture(autouse=True)19def ket_api_key():20 #""" ÐÑовеÑÑем, ÑÑо запÑÐ¾Ñ api-клÑÑа возвÑаÑÐ°ÐµÑ ÑÑаÑÑÑ 200 и в ÑезÑлÑÑаÑе ÑодеÑжиÑÑÑ Ñлово key"""21 # ÐÑпÑавлÑем запÑÐ¾Ñ Ð¸ ÑоÑ
ÑанÑем полÑÑеннÑй оÑÐ²ÐµÑ Ñ ÐºÐ¾Ð´Ð¾Ð¼ ÑÑаÑÑÑа в status, а ÑекÑÑ Ð¾ÑвеÑа в result22 status, pytest.key = pf.get_api_key(valid_email, valid_password)23 # СвеÑÑем полÑÑеннÑе даннÑе Ñ Ð½Ð°Ñими ожиданиÑми24 assert status == 20025 assert 'key' in pytest.key26 yield27@pytest.mark.parametrize("filter",28 [29 generate_string(255)30 , generate_string(1001)31 , russian_chars()32 , russian_chars().upper()33 , chinese_chars()34 , special_chars()35 , 12336 ],37 ids =38 [39 '255 symbols'40 , 'more than 1000 symbols'41 , 'russian'42 , 'RUSSIAN'43 , 'chinese'44 , 'specials'45 , 'digit'46 ])47# negative test48def test_get_all_pets_with_negative_filter(filter):49 pytest.status, result, _, _ = pf.get_list_of_pets(pytest.key, filter)50 # ÐÑовеÑÑем ÑÑаÑÑÑ Ð¾ÑвеÑа51 assert pytest.status == 40052@pytest.mark.parametrize("filter",53 ['', 'my_pets'],54 ids=['empty string', 'only my pets'])55# pozitive test56def test_get_all_pets_with_valid_key(filter):57 pytest.status, result, _, _ = pf.get_list_of_pets(pytest.key, filter)58 # ÐÑовеÑÑем ÑÑаÑÑÑ Ð¾ÑвеÑа59 assert pytest.status == 20060 assert len(result['pets']) > 061# @pytest.fixture(autouse=True)62# def ket_api_key():63# status, pytest.key = pf.get_api_key(valid_email, valid_password)64# assert status == 20065# assert 'key' in pytest.key66#67# yield68#69# assert pytest.status == 20070@pytest.mark.parametrize("filter", ['', 'my_pets'], ids= ['empty string', 'only my pets'])71def test_get_all_pets_with_valid_key(filter):72 pytest.status, result, _, _ = pf.get_list_of_pets(pytest.key, filter)73 assert len(result['pets']) > 074@pytest.mark.parametrize("name", ['', generate_string(255), russian_chars(), '123'],75 ids=['empty', '255 symbols', 'russian', 'digit'])76@pytest.mark.parametrize("animal_type", ['', generate_string(255), russian_chars(), '123'],77 ids=['empty', '255 symbols', 'russian', 'digit'])78@pytest.mark.parametrize("age", ['', '-1', '0', '1', '100', '1.5', chinese_chars()],79 ids=['empty', 'negative', 'zero', 'min', 'greater than max', 'float', 'chinese'])80def test_add_new_pet_simple(name, animal_type, age):81 """ÐÑовеÑÑем, ÑÑо можно добавиÑÑ Ð¿Ð¸ÑомÑа Ñ ÑазлиÑнÑми даннÑми"""82 # ÐобавлÑем пиÑомÑа83 pytest.status, result = pf.add_new_pet_simple(pytest.key, name, animal_type, age)84 assert pytest.status == 20085 assert result['name'] == name86 assert result['age'] == age87 assert result['animal_type'] == animal_type88def test_get_api_key(get_api_keys):89 result = get_api_keys90 with open("out_json.json", 'w', encoding='utf8') as my_file:91 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n')92 json.dump(result, my_file, ensure_ascii=False, indent=4)93 assert 'key' in result94 def test_get_not_api_key(self, email=invalid_email, password=invalid_password):95 # ÑеÑÑ Ð½Ð° некоÑÑекÑнÑе логин Ñ Ð¿Ð°Ñолем96 status, result = self.pf.get_api_key(email, password)97 assert status == 40398def tests_get_all_pets(get_api_keys, filter=''):99 status, result, content, optional = pf.get_list_of_pets(get_api_keys, filter)100 print('\nContent:', content)101 print('Optional:', optional)102 assert status == 200103 assert len(result['pets']) > 0104def tests_get_my_filter_pets(get_api_keys, filter='my_pets'):105 try:106 status, result, content, optional = pf.get_list_of_pets(get_api_keys, filter)107 with open("out_json.json", 'a', encoding='utf8') as my_file:108 my_file.write(f'\n{inspect.currentframe().f_code.co_name}:\n') # ÐÑводим Ð¸Ð¼Ñ ÑÑнкÑии, как заголовок оÑвеÑа109 my_file.write(str(f'\n{status}\n{content}\n{optional}\n'))110 json.dump(result, my_file, ensure_ascii=False, indent=4)111 assert status == 200112 assert len(result['pets']) > 0113 except:114 print(' status = ', status)115 print('There is no my pets')116def tests_add_new_pet(get_api_keys, name='pig', animal_type='swan', age='2', pet_photo='..\images\cor.jpg'):117 pet_photo = os.path.join(os.path.dirname(__file__), pet_photo)118 status, result = pf.add_new_pet(get_api_keys, name, animal_type, age, pet_photo)119 assert status == 200120 assert result['name'] == name121def tests_put_my_pet(get_api_keys, name='ÑеÑдÑе', animal_type='ÑеловеÑÑе', age=60):122 _, myPets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")123 if len(myPets['pets']) > 0:124 status, result = pf.update_pet_info(get_api_keys, myPets['pets'][0]['id'], name, animal_type, age)125 assert status == 200126 assert result['name'] == name127 else:128 print("There is no my pets")129def tests_add_my_pet(get_api_keys, name='svin', animal_type='suka', age=555):130 status, result = pf.add_new_pet_simple(get_api_keys, name, animal_type, age)131 assert status == 200132 assert result['name'] == name133 def tests_add_my_negat_pet(self, name='svin', animal_type='pig', age=5):134 # добавлÑем пеÑа Ñ Ð¸ÑполÑзованием клÑÑа, забиÑого в settigs.py.135 # Ð ÑлÑÑае непÑавилÑного клÑÑа ÑеÑÑ Ð²ÑполнÑеÑÑÑ Ñ Ñказанием status_code и incorrect auth_key136 try:137 status, result = self.pf.aadd_new_pet_simple(auth_key, name, animal_type, age)138 assert status == 200139 assert result['name'] == name140 except:141 print('incorrect auth_key')142def test_delet_my_one_pet(get_api_keys):143 # УбиÑаем одного пеÑа (по индекÑÑ "0")144 status, resalt, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")145 if len(resalt['pets']) > 0:146 pet_id = resalt['pets'][0]['id']147 status, _ = pf.delete_pet(get_api_keys, pet_id)148 assert status == 200149 assert pet_id not in resalt.values()150 else:151 print(' status = ', status)152 print("There is no my pets")153def test_delet_my_all_pets(get_api_keys):154 # УбиÑаем вÑеÑ
ÑвоиÑ
пеÑов155 status, myPets, _, _ = pf.get_list_of_pets(get_api_keys, "my_pets")156 for i in range(len(myPets['pets'])):157 pet_id = myPets['pets'][i]['id']158 status, _ = pf.delete_pet(get_api_keys, pet_id)159 try:160 assert status == 200161 assert pet_id not in myPets.values()162 except:163 print(' status = ', status)164 print("There is no my pets")165@pytest.mark.parametrize("name"166 , [generate_string(255), generate_string(1001), russian_chars(), russian_chars().upper(), chinese_chars(),167 special_chars(), '123']168 , ids=['255 symbols', 'more than 1000 symbols', 'russian', 'RUSSIAN', 'chinese', 'specials', 'digit'])169@pytest.mark.parametrize("animal_type"170 , [generate_string(255), generate_string(1001), russian_chars(), russian_chars().upper(), chinese_chars(),171 special_chars(), '123']172 , ids=['255 symbols', 'more than 1000 symbols', 'russian', 'RUSSIAN', 'chinese', 'specials', 'digit'])173@pytest.mark.parametrize("age", ['1'], ids=['min'])174def test_add_new_pet_simple(name, animal_type, age):175 """ÐÑовеÑÑем, ÑÑо можно добавиÑÑ Ð¿Ð¸ÑомÑа Ñ ÑазлиÑнÑми даннÑми"""176 # ÐобавлÑем пиÑомÑа177 pytest.status, result = pf.add_new_pet_simple(pytest.key, name, animal_type, age)178 # СвеÑÑем полÑÑеннÑй оÑÐ²ÐµÑ Ñ Ð¾Ð¶Ð¸Ð´Ð°ÐµÐ¼Ñм ÑезÑлÑÑаÑом179 assert pytest.status == 200180 assert result['name'] == name181 assert result['age'] == age182 assert result['animal_type'] == animal_type183@pytest.mark.parametrize("name", [''], ids=['empty'])184@pytest.mark.parametrize("animal_type", [''], ids=['empty'])185@pytest.mark.parametrize("age",186 ['', '-1', '0', '100', '1.5', '2147483647', '2147483648', special_chars(), russian_chars(),187 russian_chars().upper(), chinese_chars()]188 , ids=['empty', 'negative', 'zero', 'greater than max', 'float', 'int_max', 'int_max + 1', 'specials',189 'russian', 'RUSSIAN', 'chinese'])190def test_add_new_pet_simple_negative(name, animal_type, age):191 # ÐобавлÑем пиÑомÑа192 pytest.status, result = pf.add_new_pet_simple(pytest.key, name, animal_type, age)193 # СвеÑÑем полÑÑеннÑй оÑÐ²ÐµÑ Ñ Ð¾Ð¶Ð¸Ð´Ð°ÐµÐ¼Ñм ÑезÑлÑÑаÑом...
test_api.py
Source:test_api.py
...3from weasyl import api4from weasyl.test import db_utils5@pytest.mark.usefixtures('db')6class ApiTestCase(unittest.TestCase):7 def test_get_api_keys(self):8 user = db_utils.create_user()9 self.assertEqual(0, api.get_api_keys(user).rowcount)10 token = "some token"11 db_utils.create_api_key(user, token)12 self.assertEqual(1, api.get_api_keys(user).rowcount)13 self.assertEqual(token, api.get_api_keys(user).first()["token"])14 def test_add_api_key(self):15 user = db_utils.create_user()16 api.add_api_key(user, "")17 self.assertEqual(1, api.get_api_keys(user).rowcount)18 def test_delete_api_keys(self):19 user = db_utils.create_user()20 token = "some token"21 db_utils.create_api_key(user, token)22 api.delete_api_keys(user, [token])...
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!!