def test_dynamodb_upsert(): dynamodb_access = DynamoDBAccess(profile_name=test_awsimple_str, table_name=test_awsimple_str) dynamodb_access.create_table(id_str) test_id = "upserter" dynamodb_access.delete_item(id_str, test_id) # make sure the item doesn't exist item_value = {id_str: test_id, "color": "blue"} dynamodb_access.upsert_item(id_str, test_id, item={"color": "blue"}) # insert assert dynamodb_access.get_item( id_str, test_id) == item_value # check that it's set item_value["my_size"] = 9 dynamodb_access.upsert_item(id_str, test_id, item={"my_size": 9}) # update with new data assert dynamodb_access.get_item( id_str, test_id) == item_value # check that it's set to the new value item_value["my_size"] = 10 dynamodb_access.upsert_item(id_str, test_id, item={"my_size": 10}) # update existing data assert dynamodb_access.get_item( id_str, test_id) == item_value # check that it's set to the new value
def test_dynamodb_delete(): dynamodb_access = DynamoDBAccess(profile_name=test_awsimple_str, table_name=test_awsimple_str) dynamodb_access.create_table(id_str) test_id = "deleter" item_value = {id_str: test_id, "color": "blue"} dynamodb_access.put_item(item_value) assert dynamodb_access.get_item( id_str, test_id) == item_value # check that it's set dynamodb_access.delete_item(id_str, test_id) with pytest.raises(DBItemNotFound): print(dynamodb_access.get_item(id_str, test_id)) # check that it's deleted