How to use parse_response method in localstack

Best Python code snippet using localstack_python

test_transaction_api.py

Source:test_transaction_api.py Github

copy

Full Screen

...25) -> None:26 currency_converter.btc_to_usd = 227 system_configuration.initial_balance = 128 system_configuration.same_user_transfer_fee = 5029 key = parse_response(30 user_client.create_user(random_string()), CreateUserResponse31 ).api_key32 wallet_address_1 = parse_response(33 wallet_client.create_wallet(api_key=key), CreateWalletResponse34 ).wallet.address35 wallet_address_2 = parse_response(36 wallet_client.create_wallet(api_key=key), CreateWalletResponse37 ).wallet.address38 response = transaction_client.create_transaction(39 api_key=key,40 source_address=wallet_address_1,41 destination_address=wallet_address_2,42 amount=1,43 )44 wallet_1 = parse_response(45 wallet_client.fetch_wallet(wallet_address=wallet_address_1, api_key=key),46 FetchWalletResponse,47 ).wallet48 wallet_2 = parse_response(49 wallet_client.fetch_wallet(wallet_address=wallet_address_2, api_key=key),50 FetchWalletResponse,51 ).wallet52 assert wallet_1.balance[Currency.BTC] == 053 assert wallet_1.balance[Currency.USD] == 054 assert wallet_2.balance[Currency.BTC] == 1.555 assert wallet_2.balance[Currency.USD] == 356 assert response.status_code == status.HTTP_201_CREATED57def test_should_not_create_transaction_with_invalid_api_key(58 user_client: UserClient,59 wallet_client: WalletClient,60 transaction_client: TransactionClient,61) -> None:62 key = parse_response(63 user_client.create_user(random_string()), CreateUserResponse64 ).api_key65 wallet_address_1 = parse_response(66 wallet_client.create_wallet(api_key=key), CreateWalletResponse67 ).wallet.address68 wallet_address_2 = parse_response(69 wallet_client.create_wallet(api_key=key), CreateWalletResponse70 ).wallet.address71 response = transaction_client.create_transaction(72 api_key=random_api_key(),73 source_address=wallet_address_1,74 destination_address=wallet_address_2,75 amount=1,76 )77 error = parse_response(response, Error)78 assert error.error_message is not None79 assert response.status_code == status.HTTP_401_UNAUTHORIZED80def test_should_not_create_transaction_for_invalid_wallets(81 user_client: UserClient,82 wallet_client: WalletClient,83 transaction_client: TransactionClient,84) -> None:85 key = parse_response(86 user_client.create_user(random_string()), CreateUserResponse87 ).api_key88 wallet_address = parse_response(89 wallet_client.create_wallet(api_key=key), CreateWalletResponse90 ).wallet.address91 response_1 = transaction_client.create_transaction(92 api_key=key,93 source_address=wallet_address,94 destination_address=random_string(),95 amount=1,96 )97 error_1 = parse_response(response_1, Error)98 response_2 = transaction_client.create_transaction(99 api_key=key,100 source_address=random_string(),101 destination_address=wallet_address,102 amount=1,103 )104 error_2 = parse_response(response_2, Error)105 assert error_1.error_message is not None106 assert error_2.error_message is not None107 assert response_1.status_code == status.HTTP_401_UNAUTHORIZED108 assert response_2.status_code == status.HTTP_401_UNAUTHORIZED109def test_should_not_create_transaction_with_invalid_funds(110 user_client: UserClient,111 wallet_client: WalletClient,112 transaction_client: TransactionClient,113 system_configuration: StubSystemConfiguration,114) -> None:115 system_configuration.initial_balance = 1116 key = parse_response(117 user_client.create_user(random_string()), CreateUserResponse118 ).api_key119 wallet_address_1 = parse_response(120 wallet_client.create_wallet(api_key=key), CreateWalletResponse121 ).wallet.address122 wallet_address_2 = parse_response(123 wallet_client.create_wallet(api_key=key), CreateWalletResponse124 ).wallet.address125 response_1 = transaction_client.create_transaction(126 api_key=key,127 source_address=wallet_address_1,128 destination_address=wallet_address_2,129 amount=2,130 )131 error_1 = parse_response(response_1, Error)132 response_2 = transaction_client.create_transaction(133 api_key=key,134 source_address=wallet_address_1,135 destination_address=wallet_address_2,136 amount=-0.1,137 )138 error_2 = parse_response(response_2, Error)139 assert error_1.error_message is not None140 assert error_2.error_message is not None141 assert response_1.status_code == status.HTTP_409_CONFLICT142 assert response_2.status_code == status.HTTP_409_CONFLICT143def test_should_fetch_transactions_for_wallet(144 user_client: UserClient,145 wallet_client: WalletClient,146 transaction_client: TransactionClient,147 currency_converter: StubCurrencyConverter,148 system_configuration: StubSystemConfiguration,149) -> None:150 currency_converter.btc_to_usd = 2151 system_configuration.initial_balance = 1152 system_configuration.same_user_transfer_fee = 0153 key = parse_response(154 user_client.create_user(random_string()), CreateUserResponse155 ).api_key156 wallet_address_1 = parse_response(157 wallet_client.create_wallet(api_key=key), CreateWalletResponse158 ).wallet.address159 wallet_address_2 = parse_response(160 wallet_client.create_wallet(api_key=key), CreateWalletResponse161 ).wallet.address162 transaction_client.create_transaction(163 api_key=key,164 source_address=wallet_address_1,165 destination_address=wallet_address_2,166 amount=1,167 )168 response_1 = transaction_client.fetch_transactions(169 wallet_address=wallet_address_1, api_key=key170 )171 response_2 = transaction_client.fetch_transactions(172 wallet_address=wallet_address_2, api_key=key173 )174 transactions_1 = parse_response(response_1, FetchTransactionsResponse).transactions175 transactions_2 = parse_response(response_2, FetchTransactionsResponse).transactions176 assert len(transactions_1) == 1177 assert len(transactions_2) == 1178 assert transactions_1[0].id == transactions_2[0].id179 assert transactions_1[0].source_address == wallet_address_1180 assert transactions_1[0].destination_address == wallet_address_2181 assert transactions_1[0].amount == 1182 assert transactions_1[0].timestamp == transactions_2[0].timestamp183 assert response_1.status_code == status.HTTP_200_OK184 assert response_2.status_code == status.HTTP_200_OK185def test_should_not_fetch_transactions_for_wallet_with_invalid_api_key(186 user_client: UserClient,187 wallet_client: WalletClient,188 transaction_client: TransactionClient,189) -> None:190 key = parse_response(191 user_client.create_user(random_string()), CreateUserResponse192 ).api_key193 wallet_address = parse_response(194 wallet_client.create_wallet(api_key=key), CreateWalletResponse195 ).wallet.address196 response = transaction_client.fetch_transactions(197 wallet_address=wallet_address, api_key=random_api_key()198 )199 error = parse_response(response, Error)200 assert error.error_message is not None201 assert response.status_code == status.HTTP_401_UNAUTHORIZED202def test_should_not_fetch_transactions_for_invalid_wallet(203 user_client: UserClient,204 transaction_client: TransactionClient,205) -> None:206 key = parse_response(207 user_client.create_user(random_string()), CreateUserResponse208 ).api_key209 response = transaction_client.fetch_transactions(210 wallet_address=random_string(), api_key=key211 )212 error = parse_response(response, Error)213 assert error.error_message is not None214 assert response.status_code == status.HTTP_401_UNAUTHORIZED215def test_should_fetch_transactions_for_user(216 user_client: UserClient,217 wallet_client: WalletClient,218 transaction_client: TransactionClient,219 currency_converter: StubCurrencyConverter,220 system_configuration: StubSystemConfiguration,221) -> None:222 currency_converter.btc_to_usd = 2223 system_configuration.initial_balance = 1224 system_configuration.cross_user_transfer_fee = 10225 key_1 = parse_response(226 user_client.create_user(random_string()), CreateUserResponse227 ).api_key228 key_2 = parse_response(229 user_client.create_user(random_string()), CreateUserResponse230 ).api_key231 wallet_address_1 = parse_response(232 wallet_client.create_wallet(api_key=key_1), CreateWalletResponse233 ).wallet.address234 wallet_address_2 = parse_response(235 wallet_client.create_wallet(api_key=key_2), CreateWalletResponse236 ).wallet.address237 transaction_client.create_transaction(238 api_key=key_1,239 source_address=wallet_address_1,240 destination_address=wallet_address_2,241 amount=1,242 )243 response_1 = transaction_client.fetch_user_transactions(api_key=key_1)244 response_2 = transaction_client.fetch_user_transactions(api_key=key_2)245 transactions_1 = parse_response(246 response_1, FetchUserTransactionsResponse247 ).transactions248 transactions_2 = parse_response(249 response_2, FetchUserTransactionsResponse250 ).transactions251 assert len(transactions_1) == 2252 assert len(transactions_2) == 1253 assert transactions_1[0].id == transactions_2[0].id254 assert transactions_1[0].source_address == wallet_address_1255 assert transactions_1[0].destination_address == wallet_address_2256 assert transactions_1[0].amount == 0.9257 assert transactions_1[0].timestamp == transactions_2[0].timestamp258 assert transactions_1[1].source_address == wallet_address_1259 assert (260 transactions_1[1].destination_address261 == system_configuration.get_system_wallet_address()262 )263 assert transactions_1[1].amount == pytest.approx(0.1)264 assert response_1.status_code == status.HTTP_200_OK265 assert response_2.status_code == status.HTTP_200_OK266def test_should_fetch_empty_transaction_list_for_invalid_user(267 transaction_client: TransactionClient,268) -> None:269 response = transaction_client.fetch_user_transactions(api_key=random_api_key())270 transactions = parse_response(response, FetchUserTransactionsResponse).transactions271 assert transactions == []...

Full Screen

Full Screen

testing.py

Source:testing.py Github

copy

Full Screen

...14 self.assertEqual(snake_to_camel("hello_world"), "HelloWorld")15 def test_string_to_camel(self):16 self.assertEqual(string_to_camel("hello world"), "helloWorld")17 def test_intent_error(self):18 self.assertEqual(parse_response('testing/IntentError.wav'), front_end_error + 'intent not Detected')19 def test_comment(self):20 self.assertEqual(parse_response('testing/CommentHelloWorld.wav'), front_end_block + '# hello world')21 self.assertEqual(parse_response('testing/CommandComment.wav'), front_end_block + '# hello world this has to make an error')22 self.assertEqual(parse_response('testing/LongComment.wav'), front_end_block + "# this is a very long command which should be split into lines i have to go shopping i\n# have to go to the university and i'm going to drink a coffee now please split it into lines")23 def test_if_statement(self):24 self.assertEqual(parse_response('testing/CreateAnIfStatement.wav'),25 front_end_block + 'if ' + placeholder_string + ' :\n\t' + placeholder_string)26 self.assertEqual(parse_response('testing/IfCount5.wav'), front_end_block + 'if count > 5 :\n\t$$')27 self.assertEqual(parse_response('testing/IfAssign.wav'), front_end_block + "if count == 5 :\n\ttest = testing")28 self.assertEqual(parse_response('testing/IfCall.wav'), front_end_block + "if count == 5 :\n\tevaluated_weather ()")29 self.assertEqual(parse_response('testing/IfReturn.wav'), front_end_block + "if there > 2 :\n\treturn high")30 self.assertEqual(parse_response('testing/IfDefineNone.wav'), front_end_block + "if country_s == 5 :\n\tcount = None\n")31 self.assertEqual(parse_response('testing/IfShortComment.wav'), front_end_block + "if number == 2 :\n\t# hello world")32 def test_if_else_statement(self):33 self.assertEqual(parse_response('testing/IfElseReturn.wav'), front_end_block + 'if country == 5 :\n\treturn\nelse:\n\treturn count')34 def test_while(self):35 self.assertEqual(parse_response('testing/WhileLoop.wav'),36 front_end_block + 'while ' + placeholder_string + ':\n\t' + placeholder_string)37 self.assertEqual(parse_response('testing/WhileLoopExp.wav'),38 front_end_block + "while count == 5:\n\t" + placeholder_string)39 self.assertEqual(parse_response('testing/whiletest.wav'),40 front_end_block + "while counter > 5:\n\t" + placeholder_string)41 self.assertEqual(parse_response('testing/WhileUntilTest.wav'),42 front_end_block + "while test_if_not == fail_value:\n\t" + placeholder_string)43 def test_for(self):44 self.assertEqual(parse_response('testing/ForRange1_10.wav'),45 front_end_block + 'for number in range ( 0 , 10 ):\n\t' + placeholder_string)46 self.assertEqual(parse_response('testing/fors2ed.wav'), front_end_warning + "Variable Name not understood\n"47 + front_end_block + "for $$ in range ( 0 , 10 ):\n\t$$")48 self.assertEqual(parse_response('testing/ForElemInCount.wav'),49 front_end_block + "for element in count:\n\t" + placeholder_string)50 self.assertEqual(parse_response('testing/EmptyFor.wav'), front_end_block + "for $$ in range( $$,$$ ):\n\t$$")51 self.assertEqual(parse_response('testing/ForRangeFrom0Until.wav'), front_end_warning + "Second Expression name was not understood in for loop\n" + front_end_block + "for weather in range ( saro , $$ ):\n\t$$")52 self.assertEqual(parse_response('testing/ForLoopMissingExp.wav'), front_end_warning + "Second Variable name was not understood in for loop\n" + front_end_block + "for weather in $$:\n\t$$")53 def test_assignVariable(self):54 self.assertEqual(parse_response('testing/declare expression.wav'),55 front_end_block + 'number_of_cars = 5 + 3 - number_of_entrances')56 self.assertEqual(parse_response('testing/DefineCount=1+1.wav'), front_end_block + 'count = 1 + 1')57 self.assertEqual(parse_response('testing/Declare_variable.wav'),58 front_end_block + 'number_of_cars = ' + placeholder_string)59 self.assertEqual(parse_response('testing/DefineVariabeA.wav'),60 front_end_error + "Variable Name not found")61 self.assertEqual(parse_response('testing/DefineVariableCount.wav'),62 front_end_block + "count = $$")63 def test_create_function(self):64 self.assertEqual(parse_response('testing/CreateFunction.wav'), front_end_error + "FunctionName not found")65 self.assertEqual(parse_response('testing/CreateFunction0Params.wav'), front_end_block + "def multiply ():\n\t")66 self.assertEqual(parse_response('testing/CreateFunction2.wav'),67 front_end_block + "def evaluate_weather (username_common_mail):\n\t")68 def test_call_function(self):69 self.assertEqual(parse_response('testing/CallFunction.wav'), front_end_block + "evaluate_weather (de)")70 self.assertEqual(parse_response('testing/CallFunctionWeather.wav'), front_end_block + "evaluate_weather ()")71 def test_undo_command(self):72 self.assertEqual(parse_response('testing/Undo.wav'), front_end_undo)73 self.assertEqual(parse_response('testing/Undo16.wav'), front_end_undo + "16")74 def test_redo_command(self):75 self.assertEqual(parse_response('testing/Redo20.wav'), front_end_redo + "20")76 self.assertEqual(parse_response('testing/Redo.wav'), front_end_redo)77 def test_delete(self):78 # self.assertEqual(parse_response('Delete1_11.wav'), front_end_delete + "1\n11")79 self.assertEqual(parse_response('testing/Delete.wav'), front_end_delete)80 self.assertEqual(parse_response('testing/Delete1_error.wav'), front_end_error + "delete line numbers where not understood")81 def test_return(self):82 self.assertEqual(parse_response('testing/Return.wav'), front_end_block + "return")83 self.assertEqual(parse_response('testing/ReturnVacDays.wav'), front_end_block + "return vacation_days")84 def test_insert_expression(self):85 self.assertEqual(parse_response('testing/InsExp.wav'), front_end_block + "number + 3 * 4")86 self.assertEqual(parse_response('testing/InsExpErr.wav'), front_end_error + "Expression not found")87 def test_expressions(self):88 self.assertEqual(parse_expression("three plus four"), "3 + 4")89 self.assertEqual(parse("space greater than five and number of cars less than four"), "space > 5 "90 "and "91 "number_of_cars "92 "< 4")93 self.assertEqual(parse("three plus four is less than number of cars and x is greater than five"),94 "3 + 4 < number_of_cars and x > 5")95 self.assertEqual(parse("index or number of times"),96 "index or number_of * ")97 self.assertEqual(parse_expression("three mod four division two"), "3 % 4 / 2")98 self.assertEqual(parse("space greater or equal to five and number of cars less or equal to four"), "space >= 5 "99 "and "100 "number_of_cars "...

Full Screen

Full Screen

error_tests.py

Source:error_tests.py Github

copy

Full Screen

1import unittest2from ..client import Client3from .. import errors as api_errors4from .fixtures.error_fixtures import *5class ErrorTests(unittest.TestCase):6 7 def setUp(self):8 self.client = Client(9 client_id='',10 client_secret='',11 fingerprint='',12 ip_address='',13 devmode=True,14 logging=False )15 self.http = self.client.http16 def test_act_pend(self):17 self.assertRaises(api_errors.ActionPending, self.http.parse_response, act_pend)18 def test_inc_cli_cred(self):19 self.assertRaises(api_errors.IncorrectClientCredentials, self.http.parse_response, inc_cli_cred)20 def test_inc_user_cred(self):21 self.assertRaises(api_errors.IncorrectUserCredentials, self.http.parse_response, inc_user_cred)22 def test_unauth_fing(self):23 self.assertRaises(api_errors.UnauthorizedFingerprint, self.http.parse_response, unauth_fing)24 def test_payload_err(self):25 self.assertRaises(api_errors.PayloadError, self.http.parse_response, payload_err)26 def test_unauth_act(self):27 self.assertRaises(api_errors.UnauthorizedAction, self.http.parse_response, unauth_act)28 29 def test_inc_val(self):30 self.assertRaises(api_errors.IncorrectValues, self.http.parse_response, inc_val)31 32 def test_obj_not_found(self):33 self.assertRaises(api_errors.ObjectNotFound, self.http.parse_response, obj_not_found)34 35 def test_act_not_allow(self):36 self.assertRaises(api_errors.ActionNotAllowed, self.http.parse_response, act_not_allow)37 38 def test_too_many_req(self):39 self.assertRaises(api_errors.TooManyRequests, self.http.parse_response, too_many_req)40 41 def test_idem_conf(self):42 self.assertRaises(api_errors.IdempotencyConflict, self.http.parse_response, idem_conf)43 44 def test_req_fail(self):45 self.assertRaises(api_errors.RequestFailed, self.http.parse_response, req_fail)46 def test_serv_error(self):47 self.assertRaises(api_errors.ServerError, self.http.parse_response, serv_error)48 49 def test_serv_unav(self):50 self.assertRaises(api_errors.ServiceUnavailable, self.http.parse_response, serv_unav)51 52if __name__ == '__main__':...

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