Beispiel #1
0
 def test_generate_expression_attribute_values_with_wrong_key(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     validation: Validation = Validation(
         table_schema=self.generate_schema_template())
     self.assertRaises(ValidationIncorrectAttributeError,
                       dynamodb_api.generate_expression_attribute_values,
                       new_attributes={
                           "address": "Rochet trust drive",
                           "age": "35",
                           "comic": "Batman",
                       },
                       dynamodb_validation_format_mapper={
                           "CustomerId": {
                               "dynamodb_type": "S"
                           },
                           "name": {
                               "dynamodb_type": "S"
                           },
                           "address": {
                               "dynamodb_type": "S"
                           },
                           "age": {
                               "dynamodb_type": "S"
                           },
                           "car": {
                               "dynamodb_type": "S"
                           },
                       },
                       expression_mapping=validation.expression_mapping)
Beispiel #2
0
 def test_delete_item(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     self.create_table()
     client = boto3.client("dynamodb", region_name="eu-west-2")
     client.put_item(
         TableName="test_table",
         Item={
             "CustomerId": {
                 "S": "1482328791"
             },
             "name": {
                 "S": "James Joseph"
             },
             "address": {
                 "S": "Jeff Bezos Candy land road"
             },
             "age": {
                 "S": "32"
             },
             "car": {
                 "S": "Black Skoda"
             },
         },
     )
     client.put_item(
         TableName="test_table",
         Item={
             "CustomerId": {
                 "S": "1482328721"
             },
             "name": {
                 "S": "John Joseph"
             },
             "address": {
                 "S": "Jeff Bezos Candy land road"
             },
             "age": {
                 "S": "38"
             },
             "car": {
                 "S": "Blue BMW"
             },
         },
     )
     self.assertTrue(
         dynamodb_api.remove_item(key={
             "CustomerId": {
                 "S": "1482328721"
             },
             "name": {
                 "S": "John Joseph"
             }
         }))
Beispiel #3
0
 def test_generate_update_expression_with_wrong_key(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     validation: Validation = Validation(
         table_schema=self.generate_schema_template())
     self.assertRaises(ValidationIncorrectAttributeError,
                       dynamodb_api.generate_update_expression,
                       new_attributes={
                           "address": "Rochet trust drive",
                           "age": "35",
                           "comic": "Batman",
                       },
                       expression_mapping=validation.expression_mapping)
Beispiel #4
0
 def test_push_update(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     self.create_table()
     client = boto3.client("dynamodb", region_name="eu-west-2")
     client.put_item(
         TableName="test_table",
         Item={
             "CustomerId": {
                 "S": "1482328791"
             },
             "name": {
                 "S": "James Joseph"
             },
             "address": {
                 "S": "Jeff Bezos Candy land road"
             },
             "age": {
                 "S": "32"
             },
             "car": {
                 "S": "Black Skoda"
             },
         },
     )
     self.assertEqual(
         dynamodb_api.push_update(
             key={"CustomerId": {
                 "S": "1482328791"
             }},
             update_expression="SET #AD = :ad, #AG = :ag",
             expression_attribute_names={
                 "#AD": "address",
                 "#AG": "age"
             },
             expression_attribute_values={
                 ":ad": {
                     "S": "Rochet trust drive"
                 },
                 ":ag": {
                     "S": "35"
                 },
             },
         )["Attributes"],
         {
             "address": {
                 "S": "Rochet trust drive"
             },
             "age": {
                 "S": "35"
             }
         },
     )
Beispiel #5
0
 def test_generate_update_expression(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     validation: Validation = Validation(
         table_schema=self.generate_schema_template())
     self.assertEqual(
         dynamodb_api.generate_update_expression(
             new_attributes={
                 "address": "Rochet trust drive",
                 "age": "35"
             },
             expression_mapping=validation.expression_mapping),
         "SET #A = :a, #AG = :ag",
     )
Beispiel #6
0
 def test_remove_all_duplicate_attributes(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     self.assertEqual(
         dynamodb_api.remove_duplicated_attributes(
             new_attributes={
                 "address": "Rochet trust drive",
                 "age": "35"
             },
             old_attributes={
                 "address": "Rochet trust drive",
                 "age": "35"
             },
         ),
         {},
     )
Beispiel #7
0
 def test_remove_duplicate_attributes_wrong_key(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     self.assertRaises(
         ValidationIncorrectAttributeError,
         dynamodb_api.remove_duplicated_attributes,
         new_attributes={
             "address": "Jeff Bezos Candy land road",
             "age": "32",
             "comics": "Batman",
         },
         old_attributes={
             "address": "Rochet trust drive",
             "age": "35"
         },
     )
Beispiel #8
0
 def test_failing_to_create_item(self):
     self.create_table()
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     with self.assertRaises(DynamoDbWrongKeyError):
         dynamodb_api.add_item(
             dynamodb_item={
                 "name": {
                     "S": "James Joseph"
                 },
                 "address": {
                     "S": "Jeff Bezos Candy land road"
                 },
                 "age": {
                     "S": "32"
                 },
                 "car": {
                     "S": "Black Skoda"
                 },
             })
Beispiel #9
0
 def test_create_item(self):
     self.create_table()
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     self.assertTrue(
         dynamodb_api.add_item(
             dynamodb_item={
                 "CustomerId": {
                     "S": "1482328791"
                 },
                 "name": {
                     "S": "James Joseph"
                 },
                 "address": {
                     "S": "Jeff Bezos Candy land road"
                 },
                 "age": {
                     "S": "32"
                 },
                 "car": {
                     "S": "Black Skoda"
                 },
             }))
Beispiel #10
0
 def test_generate_expression_attribute_values(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     validation: Validation = Validation(
         table_schema=self.generate_schema_template())
     self.assertEqual(
         dynamodb_api.generate_expression_attribute_values(
             new_attributes={
                 "address": "Rochet trust drive",
                 "age": "35"
             },
             dynamodb_validation_format_mapper={
                 "CustomerId": {
                     "dynamodb_type": "S"
                 },
                 "name": {
                     "dynamodb_type": "S"
                 },
                 "address": {
                     "dynamodb_type": "S"
                 },
                 "age": {
                     "dynamodb_type": "S"
                 },
                 "car": {
                     "dynamodb_type": "S"
                 },
             },
             expression_mapping=validation.expression_mapping),
         {
             ":a": {
                 "S": "Rochet trust drive"
             },
             ":ag": {
                 "S": "35"
             }
         },
     )
Beispiel #11
0
 def test_failing_to_get_items(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     with self.assertRaises(DynamoDbInvalidTableError):
         dynamodb_api.get_items()
Beispiel #12
0
 def test_get_invalid_item(self):
     dynamodb_api: DynamodbApi = DynamodbApi(dynamodb_table="test_table")
     self.create_table()
     with self.assertRaises(DynamoDbWrongKeyError):
         dynamodb_api.get_item(key={"CustomerId": {"S": "1482328791"}})