def test_get_real_table_identifiers(self):
     "DynamoDB get_real_table_identifiers gets region and real table name from environment and client."
     dynamodb = DiscoDynamoDB("arbitrary")
     region, real_name = dynamodb.get_real_table_identifiers("FunnyTable")
     self.assertEqual("ap-southeast-1",
                      region)  # pass-through value from aws configuration
     self.assertEqual("FunnyTable_arbitrary", real_name)
    def test_describe_table(self):
        """ Ensures DiscoDynamoDB.describe_table() returns the right property values of a table """

        self._mock_create_table(MOCK_TABLE_NAME_1 + "_" + ENVIRONMENT_NAME)

        dynamodb = DiscoDynamoDB(ENVIRONMENT_NAME)
        table = dynamodb.describe_table(MOCK_TABLE_NAME_1)

        self.assertEqual(len(table["KeySchema"]), 2)
        for key in table["KeySchema"]:
            if key["KeyType"] == "HASH":
                self.assertEqual(key["AttributeName"], MOCK_TABLE_HASH_KEY)
            else:
                self.assertEqual(key["AttributeName"], MOCK_TABLE_RANGE_KEY)
        self.assertEqual(table["ProvisionedThroughput"]["ReadCapacityUnits"],
                         MOCK_TABLE_READ_THROUGHPUT)
        self.assertEqual(table["ProvisionedThroughput"]["WriteCapacityUnits"],
                         MOCK_TABLE_WRITE_THROUGHPUT)
        self.assertEqual(table["TableStatus"], "ACTIVE")
        self.assertEqual(len(table["GlobalSecondaryIndexes"]), 1)
        self.assertEqual(table["GlobalSecondaryIndexes"][0]["IndexName"],
                         MOCK_TABLE_GLOBAL_INDEX_NAME)
        self.assertEqual(len(table["GlobalSecondaryIndexes"][0]["KeySchema"]),
                         1)
        self.assertEqual(
            table["GlobalSecondaryIndexes"][0]["KeySchema"][0]
            ["AttributeName"], MOCK_TABLE_GLOBAL_INDEX_ATTR_NAME)
    def test_list_tables(self):
        """ Ensures DiscoDynamoDB returns names of all the tables in sorted order """

        self._mock_create_table(MOCK_TABLE_NAME_1)
        self._mock_create_table(MOCK_TABLE_NAME_2)

        dynamodb = DiscoDynamoDB(ENVIRONMENT_NAME)
        tables = dynamodb.get_all_tables()
        self.assertEqual(tables, [MOCK_TABLE_NAME_1, MOCK_TABLE_NAME_2])
示例#4
0
    def test_list_tables(self):
        """ Ensures DiscoDynamoDB returns names of all the tables in sorted order """

        self._mock_create_table(MOCK_TABLE_NAME_1)
        self._mock_create_table(MOCK_TABLE_NAME_2)

        dynamodb = DiscoDynamoDB(ENVIRONMENT_NAME)
        tables = dynamodb.get_all_tables()
        self.assertEqual(tables,
                         [MOCK_TABLE_NAME_1, MOCK_TABLE_NAME_2])
    def test_invalid_env_name(self):
        """ Ensures invalid environment name raises DynamoDBEnvironmentError exception """

        with self.assertRaises(DynamoDBEnvironmentError):
            DiscoDynamoDB(None)

        with self.assertRaises(DynamoDBEnvironmentError):
            DiscoDynamoDB('none')

        with self.assertRaises(DynamoDBEnvironmentError):
            DiscoDynamoDB('-')
示例#6
0
    def test_update_table(self):
        """ Ensures DiscoDynamoDB.update_table() correctly updates a table """

        self._mock_create_table(MOCK_TABLE_NAME_2 + "_" + ENVIRONMENT_NAME)

        dynamodb = DiscoDynamoDB(ENVIRONMENT_NAME)
        dynamodb.update_table(MOCK_TABLE_NAME_2, MOCK_TABLE_CONFIG_UPDATE, True)

        table = dynamodb.describe_table(MOCK_TABLE_NAME_2)

        self.assertEqual(table["ProvisionedThroughput"]["ReadCapacityUnits"],
                         MOCK_TABLE_READ_THROUGHPUT_UPDATE)
        self.assertEqual(table["ProvisionedThroughput"]["WriteCapacityUnits"],
                         MOCK_TABLE_WRITE_THROUGHPUT_UPDATE)
    def test_update_table(self):
        """ Ensures DiscoDynamoDB.update_table() correctly updates a table """

        self._mock_create_table(MOCK_TABLE_NAME_2 + "_" + ENVIRONMENT_NAME)

        dynamodb = DiscoDynamoDB(ENVIRONMENT_NAME)
        dynamodb.update_table(MOCK_TABLE_NAME_2, MOCK_TABLE_CONFIG_UPDATE,
                              True)

        table = dynamodb.describe_table(MOCK_TABLE_NAME_2)

        self.assertEqual(table["ProvisionedThroughput"]["ReadCapacityUnits"],
                         MOCK_TABLE_READ_THROUGHPUT_UPDATE)
        self.assertEqual(table["ProvisionedThroughput"]["WriteCapacityUnits"],
                         MOCK_TABLE_WRITE_THROUGHPUT_UPDATE)
示例#8
0
    def test_describe_table(self):
        """ Ensures DiscoDynamoDB.describe_table() returns the right property values of a table """

        self._mock_create_table(MOCK_TABLE_NAME_1 + "_" + ENVIRONMENT_NAME)

        dynamodb = DiscoDynamoDB(ENVIRONMENT_NAME)
        table = dynamodb.describe_table(MOCK_TABLE_NAME_1)

        self.assertEqual(len(table["KeySchema"]), 2)
        for key in table["KeySchema"]:
            if key["KeyType"] == "HASH":
                self.assertEqual(key["AttributeName"], MOCK_TABLE_HASH_KEY)
            else:
                self.assertEqual(key["AttributeName"], MOCK_TABLE_RANGE_KEY)
        self.assertEqual(table["ProvisionedThroughput"]["ReadCapacityUnits"], MOCK_TABLE_READ_THROUGHPUT)
        self.assertEqual(table["ProvisionedThroughput"]["WriteCapacityUnits"], MOCK_TABLE_WRITE_THROUGHPUT)
        self.assertEqual(table["TableStatus"], "ACTIVE")
        self.assertEqual(len(table["GlobalSecondaryIndexes"]), 1)
        self.assertEqual(table["GlobalSecondaryIndexes"][0]["IndexName"], MOCK_TABLE_GLOBAL_INDEX_NAME)
        self.assertEqual(len(table["GlobalSecondaryIndexes"][0]["KeySchema"]), 1)
        self.assertEqual(table["GlobalSecondaryIndexes"][0]["KeySchema"][0]["AttributeName"],
                         MOCK_TABLE_GLOBAL_INDEX_ATTR_NAME)
示例#9
0
def run():
    """ Parses command line and dispatches the commands disco_dynamodb.py list """
    config = read_config()
    parser = get_parser()
    args = parser.parse_args()

    environment_name = args.env \
        if (hasattr(args, "env") and args.env) else config.get("disco_aws", "default_environment")
    dynamodb = DiscoDynamoDB(environment_name=environment_name)

    if args.mode == "list":
        list_tables(dynamodb, args.header)
    elif args.mode == "create":
        create_table(dynamodb, args.config, args.wait)
    elif args.mode == "update":
        update_table(dynamodb, args.table, args.config, args.wait)
    elif args.mode == "delete":
        delete_table(dynamodb, args.table, args.wait)
    elif args.mode == "describe":
        describe_table(dynamodb, args.table)
示例#10
0
 def test_get_real_table_identifiers(self):
     "DynamoDB get_real_table_identifiers gets region and real table name from environment and client."
     dynamodb = DiscoDynamoDB("arbitrary")
     region, real_name = dynamodb.get_real_table_identifiers("FunnyTable")
     self.assertEqual("ap-southeast-1", region)  # pass-through value from aws configuration
     self.assertEqual("FunnyTable_arbitrary", real_name)