How to use put_version method in localstack

Best Python code snippet using localstack_python

edition_test.py

Source:edition_test.py Github

copy

Full Screen

1import pytest2import json3from boto3.dynamodb.conditions import Key4from metadata.CommonRepository import ID_COLUMN5from tests import common_test_helper6@pytest.fixture(autouse=True)7def metadata_table(dynamodb):8 return common_test_helper.create_metadata_table(dynamodb)9class TestCreateEdition:10 def test_create_edition(self, metadata_table, auth_event, put_version):11 import metadata.edition.handler as edition_handler12 dataset_id, version = put_version13 create_event = auth_event(14 common_test_helper.raw_edition, dataset=dataset_id, version=version15 )16 response = edition_handler.create_edition(create_event, None)17 body = json.loads(response["body"])18 edition_id = body["Id"]19 expected_location = (20 f"/datasets/{dataset_id}/versions/6/editions/20190528T133700"21 )22 assert response["statusCode"] == 20123 assert response["headers"]["Location"] == expected_location24 assert edition_id == f"{dataset_id}/6/20190528T133700"25 def test_create_invalid_edition(self, metadata_table, auth_event, put_version):26 import metadata.edition.handler as edition_handler27 dataset_id, version = put_version28 invalid_edition = common_test_helper.raw_edition.copy()29 invalid_edition["edition"] = "2019-05-28T15:37:00"30 create_event = auth_event(invalid_edition, dataset=dataset_id, version=version)31 response = edition_handler.create_edition(create_event, None)32 message = json.loads(response["body"])33 assert response["statusCode"] == 40034 assert message == {35 "message": "Validation error",36 "errors": ["edition: '2019-05-28T15:37:00' is not a 'date-time'"],37 }38 def test_create_duplicate_edition_should_fail(39 self, metadata_table, auth_event, put_version40 ):41 import metadata.edition.handler as edition_handler42 dataset_id, version = put_version43 create_event = auth_event(44 common_test_helper.raw_edition, dataset=dataset_id, version=version45 )46 response = edition_handler.create_edition(create_event, None)47 assert response["statusCode"] == 20148 response = edition_handler.create_edition(create_event, None)49 assert response["statusCode"] == 40950 body = json.loads(response["body"])51 assert str.startswith(body[0]["message"], "Resource Conflict")52 def test_forbidden(self, metadata_table, event, put_version):53 import metadata.edition.handler as edition_handler54 dataset_id, version = put_version55 create_event = event(56 common_test_helper.raw_edition, dataset=dataset_id, version=version57 )58 response = edition_handler.create_edition(create_event, None)59 assert response["statusCode"] == 40360 assert json.loads(response["body"]) == [61 {"message": f"You are not authorized to access dataset {dataset_id}"}62 ]63 def test_dataset_not_exist(self, metadata_table, auth_event):64 import metadata.edition.handler as edition_handler65 dataset_id = "some-dataset_id"66 create_event = auth_event(67 common_test_helper.raw_edition, dataset=dataset_id, version="1"68 )69 response = edition_handler.create_edition(create_event, None)70 assert response["statusCode"] == 40471 assert json.loads(response["body"]) == [72 {"message": f"Dataset {dataset_id} does not exist"}73 ]74 def test_version_not_exist(self, metadata_table, auth_event, put_version):75 import metadata.edition.handler as edition_handler76 dataset_id, _ = put_version77 version_not_exist = "10"78 create_event = auth_event(79 common_test_helper.raw_edition,80 dataset=dataset_id,81 version=version_not_exist,82 )83 response = edition_handler.create_edition(create_event, None)84 assert response["statusCode"] == 40485 assert json.loads(response["body"]) == [86 {87 "message": f"'Parent item with id {dataset_id}/{version_not_exist} does not exist'"88 }89 ]90class TestUpdateEdition:91 def test_update_edition(self, metadata_table, auth_event, put_version):92 import metadata.edition.handler as edition_handler93 dataset_id, version = put_version94 create_event = auth_event(95 common_test_helper.raw_edition, dataset=dataset_id, version=version96 )97 body = json.loads(edition_handler.create_edition(create_event, None)["body"])98 edition_id = body["Id"].split("/")[-1]99 update_event = auth_event(100 common_test_helper.edition_updated,101 dataset=dataset_id,102 version=version,103 edition=edition_id,104 )105 response = edition_handler.update_edition(update_event, None)106 body = json.loads(response["body"])107 edition_id = body["Id"]108 assert response["statusCode"] == 200109 assert edition_id == "antall-besokende-pa-gjenbruksstasjoner/6/20190528T133700"110 db_response = metadata_table.query(111 KeyConditionExpression=Key(ID_COLUMN).eq(edition_id)112 )113 edition_from_db = db_response["Items"][0]114 assert edition_from_db["edition"] == "2019-05-28T15:37:00+02:00"115 assert edition_from_db["description"] == "CHANGED"116 def test_update_edition_latest_is_updated(117 self, metadata_table, auth_event, put_version118 ):119 import metadata.edition.handler as edition_handler120 dataset_id, version = put_version121 create_event = auth_event(122 common_test_helper.raw_edition, dataset=dataset_id, version=version123 )124 body = json.loads(edition_handler.create_edition(create_event, None)["body"])125 edition = body["Id"].split("/")[-1]126 update_event = auth_event(127 common_test_helper.edition_updated,128 dataset=dataset_id,129 version=version,130 edition=edition,131 )132 edition_handler.update_edition(update_event, None)133 edition_id = f"{dataset_id}/{version}/latest"134 db_response = metadata_table.query(135 KeyConditionExpression=Key(ID_COLUMN).eq(edition_id)136 )137 edition_from_db = db_response["Items"][0]138 assert edition_from_db["latest"] == f"{dataset_id}/{version}/{edition}"139 def test_forbidden(self, metadata_table, auth_event, event, put_version):140 import metadata.edition.handler as edition_handler141 dataset_id, version = put_version142 create_event = auth_event(143 common_test_helper.raw_edition, dataset=dataset_id, version=version144 )145 body = json.loads(edition_handler.create_edition(create_event, None)["body"])146 edition_id = body["Id"].split("/")[-1]147 update_event = event(148 common_test_helper.edition_updated,149 dataset=dataset_id,150 version=version,151 edition=edition_id,152 )153 response = edition_handler.update_edition(update_event, None)154 assert response["statusCode"] == 403155 assert json.loads(response["body"]) == [156 {"message": f"You are not authorized to access dataset {dataset_id}"}157 ]158 def test_dataset_not_exist(self, metadata_table, auth_event):159 import metadata.edition.handler as edition_handler160 dataset_id = "some-dataset_id"161 update_event = auth_event(162 common_test_helper.edition_updated,163 dataset=dataset_id,164 version="1",165 edition="20190603T092711",166 )167 response = edition_handler.update_edition(update_event, None)168 assert response["statusCode"] == 404169 assert json.loads(response["body"]) == [170 {"message": f"Dataset {dataset_id} does not exist"}171 ]172 def test_version_not_exist(self, metadata_table, auth_event, put_version):173 import metadata.edition.handler as edition_handler174 dataset_id, version = put_version175 # create_event = auth_event(176 # common_test_helper.raw_edition, dataset=dataset_id, version=version177 # )178 # edition_id = edition_handler.create_edition(create_event, None)179 version_not_exist = "10"180 update_event = auth_event(181 common_test_helper.raw_edition,182 dataset=dataset_id,183 version=version_not_exist,184 edition="20190603T092711",185 )186 response = edition_handler.update_edition(update_event, None)187 assert response["statusCode"] == 404188 assert json.loads(response["body"]) == [189 {190 "message": f"'Item with id {dataset_id}/{version_not_exist}/20190603T092711 does not exist'"191 }192 ]193class TestEdition:194 def test_edition_not_found(self, event):195 import metadata.edition.handler as edition_handler196 event_for_get = event({}, "1234", "1", "20190401T133700")197 response = edition_handler.get_edition(event_for_get, None)198 assert response["statusCode"] == 404...

Full Screen

Full Screen

versioning.py

Source:versioning.py Github

copy

Full Screen

...3 """Wrapper to add version name to parser.4 Placing the version number on the parse function seems to make5 more sense than adding __version__ to the code and relying on that.6 """7 def put_version(to_wrap):8 @wraps(to_wrap)9 def inner(*args, **kwargs):10 return to_wrap(*args, **kwargs)11 inner.version = version_number12 return inner...

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