Esempio n. 1
0
 def test_fetching_item(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.create_table()
     dynamodb_client.create_item(
         dynamodb_item={
             "CustomerId": "1482328791",
             "name": "James Joseph",
             "address": "Jeff Bezos Candy land road",
             "age": "32",
             "car": "Black Skoda",
         })
     self.assertEqual(
         dynamodb_client.fetch_item(key={"CustomerId": "1482328791"}),
         {
             "statusCode": 200,
             "body": {
                 "CustomerId": "1482328791",
                 "name": "James Joseph",
                 "address": "Jeff Bezos Candy land road",
                 "age": "32",
                 "car": "Black Skoda",
             },
         },
     )
Esempio n. 2
0
 def test_update_item(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.create_table()
     dynamodb_client.create_item(
         dynamodb_item={
             "CustomerId": "1482328791",
             "name": "James Joseph",
             "address": "Jeff Bezos Candy land road",
             "age": "32",
             "car": "Black Skoda",
         })
     self.assertEqual(
         dynamodb_client.update_item(dynamodb_attributes={
             "CustomerId": "1482328791",
             "age": "45",
             "car": "Blue BMW",
         }),
         {
             "statusCode": 200,
             "body":
             "Item with the key provided has been updated successfully",
         },
     )
Esempio n. 3
0
 def test_generating_expressions(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.assertEqual(
         dynamodb_client.generate_expressions(confirmed_new_attributes={
             "address": "Foreign road",
             "age": "42"
         }),
         (
             "SET #A = :a, #AG = :ag",
             {
                 "#A": "address",
                 "#AG": "age"
             },
             {
                 ":a": {
                     "S": "Foreign road"
                 },
                 ":ag": {
                     "S": "42"
                 },
             },
         ),
     )
Esempio n. 4
0
 def test_delete_existing_attributes(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.create_table()
     dynamodb_client.create_item(
         dynamodb_item={
             "CustomerId": "1482328791",
             "name": "James Joseph",
             "address": "Jeff Bezos Candy land road",
             "age": "32",
             "car": "Black Skoda",
         })
     self.assertEqual(
         dynamodb_client.delete_existing_attributes(
             key={"CustomerId": {
                 "S": "1482328791"
             }},
             validated_attributes={
                 "address": "Foreign road",
                 "age": "42",
                 "car": "Black Skoda",
             },
         ),
         {
             "address": "Foreign road",
             "age": "42"
         },
     )
Esempio n. 5
0
 def test_validate_data(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.assertEqual(
         dynamodb_client.validate_data(
             validation_type="read_item",
             unvalidated_data={"CustomerId": "2010482012"},
         ),
         {"CustomerId": "2010482012"},
     )
Esempio n. 6
0
 def test_confirm_item_raising_exception(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     with self.assertRaises(ValidationFailedAttributesUpdateError):
         dynamodb_client.confirm_item_updated(
             update_response={},
             confirmed_new_attributes={
                 "age": "32",
                 "car": "Black Skoda"
             },
         )
Esempio n. 7
0
 def test_failing_to_fetch_item(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.assertEqual(
         dynamodb_client.fetch_item(key={"Test_key": 4820203}),
         {
             "statusCode":
             400,
             "body":
             "Key 'CustomerId' was missing from the schema from this data, please try again",
         },
     )
Esempio n. 8
0
 def test_failing_to_delete_item(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.create_table()
     self.assertEqual(
         dynamodb_client.delete_item(key={"Name": "148232879"}),
         {
             "statusCode":
             400,
             "body":
             "Key 'CustomerId' was missing from the schema from this data, please try again",
         },
     )
Esempio n. 9
0
 def test_failing_to_fetch_items(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.assertEqual(
         dynamodb_client.fetch_items(),
         {
             "statusCode":
             400,
             "body":
             "Either the table does not exist or there are no items populated yet, "
             "please check and try again",
         },
     )
Esempio n. 10
0
 def test_failing_creating_item(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.create_table()
     self.assertEqual(
         dynamodb_client.create_item(
             dynamodb_item={
                 "CustomerId": "148232879",
                 "address": "Jeff Bezos Candy land road",
                 "age": "32",
                 "car": "Black Skoda",
             }),
         {
             "statusCode":
             400,
             "body":
             f"Key 'name' was missing from the schema from this data, please try again",
         },
     )
Esempio n. 11
0
 def test_confirm_item_updated(self):
     dynamodb_client: DynamodbClient = DynamodbClient(
         dynamodb_table="test_table",
         table_schema=self.generate_schema_template())
     self.assertTrue(
         dynamodb_client.confirm_item_updated(
             update_response={
                 "Attributes": {
                     "age": {
                         "S": "32"
                     },
                     "car": {
                         "S": "Black Skoda"
                     }
                 }
             },
             confirmed_new_attributes={
                 "age": "32",
                 "car": "Black Skoda"
             },
         ))