예제 #1
0
def test_query_radius_sort():
    try:
        table_name = str(uuid.uuid4())
        config = dynamodbgeo.GeoDataManagerConfiguration(dynamodb, table_name)
        geoDataManager = dynamodbgeo.GeoDataManager(config)
        table_util = dynamodbgeo.GeoTableUtil(config)
        create_table_input = table_util.getCreateTableRequest()
        # tweaking the base table parameters
        create_table_input["ProvisionedThroughput"]['ReadCapacityUnits'] = 5
        # pass the input to create_table method
        table_util.create_table(create_table_input)
        PutItemInput = {
            'Item': {
                'Country': {
                    'S': "Italy"
                },
                'Capital': {
                    'S': "Tunis"
                },
                'year': {
                    'S': '2020'
                }
            },
            # ... Anything else to pass through to `putItem`, eg ConditionExpression
            'ConditionExpression': "attribute_not_exists(hashKey)"
        }
        geoDataManager.put_Point(
            dynamodbgeo.PutPointInput(
                dynamodbgeo.GeoPoint(36.874419, 10.241062), "1", PutItemInput))
        geoDataManager.put_Point(
            dynamodbgeo.PutPointInput(
                dynamodbgeo.GeoPoint(36.874507, 10.240857), "2", PutItemInput))
        geoDataManager.put_Point(
            dynamodbgeo.PutPointInput(
                dynamodbgeo.GeoPoint(36.874617, 10.241441), "3", PutItemInput))
        QueryRadiusInput = {
            "FilterExpression": "Country = :val1",
            "ExpressionAttributeValues": {
                ":val1": {
                    "S": "Italy"
                },
            }
        }
        result = geoDataManager.queryRadius(
            dynamodbgeo.QueryRadiusRequest(dynamodbgeo.GeoPoint(
                36.874444, 10.241059),
                                           95,
                                           QueryRadiusInput,
                                           sort=True))
        if len(result) != 3 or result[0]["rangeKey"]["S"] != "1" or result[1][
                "rangeKey"]["S"] != "2" or result[2]["rangeKey"]["S"] != "3":
            assert False
        assert True
    except:
        assert False
예제 #2
0
def create_geo_table(aws_region, table_name, hash_key_length):

    geo_data_manager_config = get_geo_data_manager_config(
        aws_region, table_name, hash_key_length)
    table_util = dynamodbgeo.GeoTableUtil(geo_data_manager_config)

    create_table_input = table_util.getCreateTableRequest()
    del create_table_input["ProvisionedThroughput"]
    create_table_input["BillingMode"] = "PAY_PER_REQUEST"

    table_util.create_table(create_table_input)
def test_query_rectangle():
    try:
        table_name = str(uuid.uuid4())
        config = dynamodbgeo.GeoDataManagerConfiguration(dynamodb, table_name)
        geoDataManager = dynamodbgeo.GeoDataManager(config)
        table_util = dynamodbgeo.GeoTableUtil(config)
        create_table_input = table_util.getCreateTableRequest()
        # tweaking the base table parameters
        create_table_input["ProvisionedThroughput"]['ReadCapacityUnits'] = 5
        # pass the input to create_table method
        table_util.create_table(create_table_input)
        PutItemInput = {
            'Item': {
                'Country': {
                    'S': "Italy"
                },
                'Capital': {
                    'S': "Tunis"
                },
                'year': {
                    'S': '2020'
                }
            },
            # ... Anything else to pass through to `putItem`, eg ConditionExpression
            'ConditionExpression': "attribute_not_exists(hashKey)"
        }
        geoDataManager.put_Point(
            dynamodbgeo.PutPointInput(
                dynamodbgeo.GeoPoint(36.879163, 10.243120), "inside",
                PutItemInput))
        geoDataManager.put_Point(
            dynamodbgeo.PutPointInput(
                dynamodbgeo.GeoPoint(36.879502, 10.242143), "outside",
                PutItemInput))
        QueryRectangleInput = {
            "FilterExpression": "Country = :val1",
            "ExpressionAttributeValues": {
                ":val1": {
                    "S": "Italy"
                },
            }
        }
        result = geoDataManager.queryRectangle(
            dynamodbgeo.QueryRectangleRequest(
                dynamodbgeo.GeoPoint(36.878184, 10.242358),
                dynamodbgeo.GeoPoint(36.879317, 10.243648),
                QueryRectangleInput))
        if len(result) != 1 or result[0]["rangeKey"]["S"] != "inside":
            assert False
        assert True
    except:
        assert False
예제 #4
0
def create_table():
    # Pick a hashKeyLength appropriate to your usage
    config.hashKeyLength = 3

    # Use GeoTableUtil to help construct a CreateTableInput.
    table_util = dynamodbgeo.GeoTableUtil(config)
    create_table_input = table_util.getCreateTableRequest()

    # tweaking the base table parameters as a dict
    create_table_input["ProvisionedThroughput"]["ReadCapacityUnits"] = 5

    # Use GeoTableUtil to create the table
    table_util.create_table(create_table_input)
예제 #5
0
def test_create_table():
    try:
        table_name = str(uuid.uuid4())
        config = dynamodbgeo.GeoDataManagerConfiguration(dynamodb, table_name)
        geoDataManager = dynamodbgeo.GeoDataManager(config)
        table_util = dynamodbgeo.GeoTableUtil(config)
        create_table_input = table_util.getCreateTableRequest()
        # tweaking the base table parameters
        create_table_input["ProvisionedThroughput"]['ReadCapacityUnits'] = 5
        # pass the input to create_table method
        table_util.create_table(create_table_input)
        response = dynamodb.list_tables()
        if table_name not in response["TableNames"]:
            assert False
        else:
            assert True
    except:
        assert False
예제 #6
0
def test_get_point():
    try:
        table_name = str(uuid.uuid4())
        config = dynamodbgeo.GeoDataManagerConfiguration(dynamodb, table_name)
        geoDataManager = dynamodbgeo.GeoDataManager(config)
        table_util = dynamodbgeo.GeoTableUtil(config)
        create_table_input = table_util.getCreateTableRequest()
        # tweaking the base table parameters
        create_table_input["ProvisionedThroughput"]['ReadCapacityUnits'] = 5
        # pass the input to create_table method
        table_util.create_table(create_table_input)
        # define a dict of the item to input
        PutItemInput = {
            'Item': {
                'Country': {
                    'S': "Italy"
                },
                'Capital': {
                    'S': "Tunis"
                },
                'year': {
                    'S': '2020'
                }
            },
            # ... Anything else to pass through to `putItem`, eg ConditionExpression
            'ConditionExpression': "attribute_not_exists(hashKey)"
        }
        range_key = "b385bbf9-581b-4df4-b5ad-4c0e3a0794b6"
        cords = (36.879163, 10.243120)
        response = geoDataManager.put_Point(
            dynamodbgeo.PutPointInput(dynamodbgeo.GeoPoint(cords[0], cords[1]),
                                      range_key, PutItemInput))
        response = geoDataManager.get_Point(
            dynamodbgeo.GetPointInput(dynamodbgeo.GeoPoint(cords[0], cords[1]),
                                      range_key))
        assert response != "Error"
    except:
        assert False
예제 #7
0
def test_put_point():
    try:
        table_name = str(uuid.uuid4())
        config = dynamodbgeo.GeoDataManagerConfiguration(dynamodb, table_name)
        geoDataManager = dynamodbgeo.GeoDataManager(config)
        table_util = dynamodbgeo.GeoTableUtil(config)
        create_table_input = table_util.getCreateTableRequest()
        # tweaking the base table parameters
        create_table_input["ProvisionedThroughput"]['ReadCapacityUnits'] = 5
        # pass the input to create_table method
        table_util.create_table(create_table_input)
        # define a dict of the item to input
        PutItemInput = {
            'Item': {
                'Country': {
                    'S': "Italy"
                },
                'Capital': {
                    'S': "Tunis"
                },
                'year': {
                    'S': '2020'
                }
            },
            # ... Anything else to pass through to `putItem`, eg ConditionExpression
            'ConditionExpression': "attribute_not_exists(hashKey)"
        }
        response = geoDataManager.put_Point(
            dynamodbgeo.PutPointInput(
                # latitude then latitude longitude
                dynamodbgeo.GeoPoint(36.879163, 10.243120),
                # Use this to ensure uniqueness of the hash/range pairs.
                str(uuid.uuid4()),
                PutItemInput))
        assert response != "Error"
    except:
        assert False
예제 #8
0
import boto3
import dynamodbgeo
import uuid  # used in range key uniquness
'''
Entry point script for testing
'''

if __name__ == "__main__":
    # initiat dynamodb service ressource,
    dynamodb = boto3.client('dynamodb', region_name='us-east-2')
    config = dynamodbgeo.GeoDataManagerConfiguration(dynamodb, 'geo_test_8')
    geoDataManager = dynamodbgeo.GeoDataManager(config)

    table_util = dynamodbgeo.GeoTableUtil(config)
    create_table_input = table_util.getCreateTableRequest()

    # tweaking the base table parameters
    create_table_input["ProvisionedThroughput"]['ReadCapacityUnits'] = 5

    # pass the input to create_table method
    table_util.create_table(create_table_input)

    # define a dict of the item to input
    PutItemInput = {
        'Item': {
            'Country': {
                'S': "Italy"
            },
            'Capital': {
                'S': "Tunis"
            },