def __init__(self, config=None):
        """
        Setup necessary objects for negotiating with dynamo
        :param config: Optional config param most useful for testing
        """
        if config is None:
            self.dynamodb = initialise_dynamo_connection()
        else:
            self.dynamodb = initialise_dynamo_connection(config)

        table_name = self._get_table_name()
        self.orders_table = self.dynamodb.Table(table_name)
    def __init__(self):
        """
        Setup necessary objects for negotiating with dynamo
        :param config: Optional config param most useful for testing
        """
        if self.config is None:

            self.dynamodb = utils.initialise_dynamo_connection()
        else:
            self.dynamodb = utils.initialise_dynamo_connection(self.config)

        table_name = self._get_table_name()
        self.customer_table = self.dynamodb.Table(table_name)
def create_orders_table(table_name, logger, dynamo_config):
    """
    Creates a table in Dynamo in the format map_store.environment.orders
    :param table_name: Table we want to create
    :param logger: Logger object
    :param dynamo_config: Dynamo Config for connection
    """

    dynamodb = initialise_dynamo_connection(dynamo_config)
    orders_table = dynamodb.Table(table_name)

    # Don't create table if it already exists
    try:
        status = orders_table.table_status
        logger.debug('Table {0} exists, status is {1}'.format(table_name, status))
        return
    except ClientError:
        # Swallow this exception as it demonstrates table doesn't exist
        pass

    logger.info('Creating table {0}'.format(table_name))
    table = dynamodb.create_table(
        TableName=table_name,
        KeySchema=[
            {
                'AttributeName': 'customerEmailAddress',
                'KeyType': 'HASH'  # Partition key
            },
            {
                'AttributeName': 'orderId',
                'KeyType': 'RANGE'  # Sort Key
            },
        ],
        AttributeDefinitions=[
            {
                'AttributeName': 'customerEmailAddress',
                'AttributeType': 'S'  # String
            },
            {
                'AttributeName': 'orderId',
                'AttributeType': 'S'  # String
            },
        ],
        ProvisionedThroughput={
            'ReadCapacityUnits': 1,
            'WriteCapacityUnits': 1
        }
    )

    logger.info('Table {0} created'.format(table_name))
 def test_init_connections_success(self):
     dynamo = utils.initialise_dynamo_connection(DYNAMODB_CONFIG)
 def test_init_connections_raises_error_if_os_vars_not_found(self):
     with self.assertRaises(RuntimeError):
         utils.initialise_dynamo_connection(DYNAMODB_CONFIG)