Best Python code snippet using assertpy_python
test_req_store.py
Source:test_req_store.py
1import copy2import json3from unittest.mock import MagicMock4import pytest5from data_acquisition.acquisition_request import AcquisitionRequest, AcquisitionRequestStore6from tests.consts import TEST_ACQUISITION_REQ, TEST_ACQUISITION_REQ_STR, TEST_ACQUISITION_REQ_JSON7@pytest.fixture8def redis_mock():9 return MagicMock()10@pytest.fixture11def req_store(redis_mock):12 return AcquisitionRequestStore(redis_mock)13def test_get_request_redis_id(req_store):14 request_redis_id = req_store.get_request_redis_id(TEST_ACQUISITION_REQ)15 assert request_redis_id == '{}:{}'.format(TEST_ACQUISITION_REQ.orgUUID, TEST_ACQUISITION_REQ.id)16def test_put(req_store, redis_mock):17 req_store.put(TEST_ACQUISITION_REQ)18 redis_mock.hset.assert_called_with(19 AcquisitionRequestStore.REDIS_HASH_NAME,20 AcquisitionRequestStore.get_request_redis_id(TEST_ACQUISITION_REQ),21 TEST_ACQUISITION_REQ_STR)22def _get_store_id(acquisition_req):23 return '{}:{}'.format(acquisition_req.orgUUID, acquisition_req.id).encode()24def test_get_for_org(req_store, redis_mock):25 test_requests = [copy.deepcopy(TEST_ACQUISITION_REQ) for _ in range(3)]26 test_requests[1].orgUUID = 'other-fake-uuid'27 test_requests[2].id = 'other-fake-id'28 redis_mock.hgetall.return_value = {_get_store_id(req): str(req).encode()29 for req in test_requests}30 acquisition_requests = req_store.get_for_org('fake-org-uuid')31 assert test_requests[0] in acquisition_requests32 assert test_requests[2] in acquisition_requests33def test_get_from_old_base(req_store, redis_mock):34 old_request = dict(TEST_ACQUISITION_REQ_JSON)35 old_request.update({'unnecessary_field': 'blablabla'})36 redis_mock.hgetall.return_value = {b'fake-org-uuid:fake-id': json.dumps(old_request).encode()}37 acquisition_req = req_store.get('fake-id')38 assert acquisition_req == AcquisitionRequest(**TEST_ACQUISITION_REQ_JSON)...
urls.py
Source:urls.py
1from server.requesthandlers import test_requests2from server.requesthandlers.virus_info_request import virus_info_handler3from server.requesthandlers.single_request import single_handler4from server.requesthandlers.cycle_request import cycle_handler5URLS = {"GET/test/default": test_requests.default_handler,6 "POST/test/scheduler": test_requests.scheduler_handler,7 "POST/test/binary": test_requests.binary_handler,8 "POST/api/virus": virus_info_handler,9 "POST/api/singleVirusTotal": single_handler,...
test_anonymize.py
Source:test_anonymize.py
1import requests2from anonymize import enable_proxy, disable_proxy3#This url returns your ip as plain text4url = 'http://icanhazip.com'5def test_requests():6 print('requests: %s' % requests.get(url).text)7enable_proxy()8test_requests()9disable_proxy()...
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!!