コード例 #1
0
ファイル: test_dynamodb.py プロジェクト: twitty-onica/runway
    def test_dynamodb_invalid_partition_key_handler(self, _mock_client):
        """Test DynamoDB invalid partition key handler."""
        expected_params = {
            "TableName": "TestTable",
            "Key": {
                "FakeKey": {
                    "S": "TestVal"
                }
            },
            "ProjectionExpression": "TestVal,TestMap,String1",
        }
        service_error_code = "ValidationException"
        self.stubber.add_client_error(
            "get_item",
            service_error_code=service_error_code,
            expected_params=expected_params,
        )

        with self.stubber:
            base_lookup_key = "TestTable@FakeKey:TestVal.TestMap[M].String1"
            try:
                DynamodbLookup.handle(base_lookup_key)
            except ValueError as err:
                self.assertEqual(
                    "No DynamoDB record matched the partition key: FakeKey",
                    str(err))
コード例 #2
0
ファイル: test_dynamodb.py プロジェクト: onicagroup/runway
    def test_dynamodb_invalid_partition_key_handler(
        self, cfngin_context: MockCFNginContext
    ) -> None:
        """Test DynamoDB invalid partition key handler."""
        stubber = cfngin_context.add_stubber("dynamodb")
        expected_params = {
            "TableName": "TestTable",
            "Key": {"FakeKey": {"S": "TestVal"}},
            "ProjectionExpression": "TestVal,TestMap,String1",
        }
        service_error_code = "ValidationException"
        stubber.add_client_error(
            "get_item",
            service_error_code=service_error_code,
            expected_params=expected_params,
        )

        with stubber, pytest.raises(ValueError) as excinfo:
            DynamodbLookup.handle(
                "TestTable@FakeKey:TestVal.TestMap[M].String1", context=cfngin_context
            )
        assert (
            str(excinfo.value)
            == "No DynamoDB record matched the partition key: FakeKey"
        )
コード例 #3
0
ファイル: test_dynamodb.py プロジェクト: onicagroup/runway
 def test_dynamodb_missing_table_handler(
     self, cfngin_context: MockCFNginContext
 ) -> None:
     """Test DynamoDB missing table handler."""
     stubber = cfngin_context.add_stubber("dynamodb")
     expected_params = {
         "Key": {"TestKey": {"S": "TestVal"}},
         "ProjectionExpression": "TestVal,TestMap,String1",
     }
     stubber.add_response("get_item", GET_ITEM_RESPONSE, expected_params)
     with stubber, pytest.raises(ValueError) as excinfo:
         DynamodbLookup.handle(
             "TestKey:TestVal.TestMap[M].String1", context=cfngin_context
         )
     assert str(excinfo.value) == "Please make sure to include a tablename"
コード例 #4
0
 def test_dynamodb_missing_table_handler(self, _mock_client):
     """Test DynamoDB missing table handler."""
     expected_params = {
         'Key': {
             'TestKey': {
                 'S': 'TestVal'
             }
         },
         'ProjectionExpression': 'TestVal,TestMap,String1'
     }
     base_lookup_key = 'TestKey:TestVal.TestMap[M].String1'
     self.stubber.add_response('get_item', self.get_parameters_response,
                               expected_params)
     with self.stubber:
         try:
             DynamodbLookup.handle(base_lookup_key)
         except ValueError as err:
             self.assertEqual('Please make sure to include a tablename',
                              str(err))
コード例 #5
0
ファイル: test_dynamodb.py プロジェクト: twitty-onica/runway
 def test_dynamodb_missing_table_handler(self, _mock_client):
     """Test DynamoDB missing table handler."""
     expected_params = {
         "Key": {
             "TestKey": {
                 "S": "TestVal"
             }
         },
         "ProjectionExpression": "TestVal,TestMap,String1",
     }
     self.stubber.add_response("get_item", self.get_parameters_response,
                               expected_params)
     with self.stubber:
         base_lookup_key = "TestKey:TestVal.TestMap[M].String1"
         try:
             DynamodbLookup.handle(base_lookup_key)
         except ValueError as err:
             self.assertEqual("Please make sure to include a tablename",
                              str(err))
コード例 #6
0
ファイル: test_dynamodb.py プロジェクト: onicagroup/runway
 def test_dynamodb_invalid_partition_val_handler(
     self, cfngin_context: MockCFNginContext
 ) -> None:
     """Test DynamoDB invalid partition val handler."""
     stubber = cfngin_context.add_stubber("dynamodb")
     expected_params = {
         "TableName": "TestTable",
         "Key": {"TestKey": {"S": "FakeVal"}},
         "ProjectionExpression": "FakeVal,TestMap,String1",
     }
     empty_response: Dict[str, Any] = {"ResponseMetadata": {}}
     stubber.add_response("get_item", empty_response, expected_params)
     with stubber, pytest.raises(ValueError) as excinfo:
         DynamodbLookup.handle(
             "TestTable@TestKey:FakeVal.TestMap[M].String1", context=cfngin_context
         )
     assert (
         str(excinfo.value)
         == "The DynamoDB record could not be found using the following key: {'S': 'FakeVal'}"
     )
コード例 #7
0
 def test_dynamodb_invalid_partition_val_handler(self, _mock_client):
     """Test DynamoDB invalid partition val handler."""
     expected_params = {
         'TableName': 'TestTable',
         'Key': {
             'TestKey': {
                 'S': 'FakeVal'
             }
         },
         'ProjectionExpression': 'FakeVal,TestMap,String1'
     }
     empty_response = {'ResponseMetadata': {}}
     base_lookup_key = 'TestTable@TestKey:FakeVal.TestMap[M].String1'
     self.stubber.add_response('get_item', empty_response, expected_params)
     with self.stubber:
         try:
             DynamodbLookup.handle(base_lookup_key)
         except ValueError as err:
             self.assertEqual(
                 'The DynamoDB record could not be found using '
                 'the following key: {\'S\': \'FakeVal\'}', str(err))
コード例 #8
0
ファイル: test_dynamodb.py プロジェクト: onicagroup/runway
 def test_dynamodb_invalid_table_handler(
     self, cfngin_context: MockCFNginContext
 ) -> None:
     """Test DynamoDB invalid table handler."""
     stubber = cfngin_context.add_stubber("dynamodb")
     expected_params = {
         "TableName": "FakeTable",
         "Key": {"TestKey": {"S": "TestVal"}},
         "ProjectionExpression": "TestVal,TestMap,String1",
     }
     service_error_code = "ResourceNotFoundException"
     stubber.add_client_error(
         "get_item",
         service_error_code=service_error_code,
         expected_params=expected_params,
     )
     with stubber, pytest.raises(ValueError) as excinfo:
         DynamodbLookup.handle(
             "FakeTable@TestKey:TestVal.TestMap[M].String1", context=cfngin_context
         )
     assert str(excinfo.value) == "Cannot find the DynamoDB table: FakeTable"
コード例 #9
0
 def test_dynamodb_invalid_table_handler(self, _mock_client):
     """Test DynamoDB invalid table handler."""
     expected_params = {
         'TableName': 'FakeTable',
         'Key': {
             'TestKey': {
                 'S': 'TestVal'
             }
         },
         'ProjectionExpression': 'TestVal,TestMap,String1'
     }
     base_lookup_key = 'FakeTable@TestKey:TestVal.TestMap[M].String1'
     service_error_code = 'ResourceNotFoundException'
     self.stubber.add_client_error('get_item',
                                   service_error_code=service_error_code,
                                   expected_params=expected_params)
     with self.stubber:
         try:
             DynamodbLookup.handle(base_lookup_key)
         except ValueError as err:
             self.assertEqual('Cannot find the DynamoDB table: FakeTable',
                              str(err))
コード例 #10
0
ファイル: test_dynamodb.py プロジェクト: onicagroup/runway
 def test_dynamodb_list_handler(self, cfngin_context: MockCFNginContext) -> None:
     """Test DynamoDB list handler."""
     stubber = cfngin_context.add_stubber("dynamodb")
     expected_params = {
         "TableName": "TestTable",
         "Key": {"TestKey": {"S": "TestVal"}},
         "ProjectionExpression": "TestVal,TestMap,List1",
     }
     stubber.add_response("get_item", GET_ITEM_RESPONSE, expected_params)
     with stubber:
         assert DynamodbLookup.handle(
             "TestTable@TestKey:TestVal.TestMap[M].List1[L]", context=cfngin_context
         ) == ["ListVal1", "ListVal2"]
コード例 #11
0
ファイル: test_dynamodb.py プロジェクト: twitty-onica/runway
 def test_dynamodb_invalid_partition_val_handler(self, _mock_client):
     """Test DynamoDB invalid partition val handler."""
     expected_params = {
         "TableName": "TestTable",
         "Key": {
             "TestKey": {
                 "S": "FakeVal"
             }
         },
         "ProjectionExpression": "FakeVal,TestMap,String1",
     }
     empty_response = {"ResponseMetadata": {}}
     self.stubber.add_response("get_item", empty_response, expected_params)
     with self.stubber:
         base_lookup_key = "TestTable@TestKey:FakeVal.TestMap[M].String1"
         try:
             DynamodbLookup.handle(base_lookup_key)
         except ValueError as err:
             self.assertEqual(
                 "The DynamoDB record could not be found using "
                 "the following key: {'S': 'FakeVal'}",
                 str(err),
             )
コード例 #12
0
    def test_dynamodb_invalid_partition_key_handler(self, _mock_client):
        """Test DynamoDB invalid partition key handler."""
        expected_params = {
            'TableName': 'TestTable',
            'Key': {
                'FakeKey': {
                    'S': 'TestVal'
                }
            },
            'ProjectionExpression': 'TestVal,TestMap,String1'
        }
        base_lookup_key = 'TestTable@FakeKey:TestVal.TestMap[M].String1'
        service_error_code = 'ValidationException'
        self.stubber.add_client_error('get_item',
                                      service_error_code=service_error_code,
                                      expected_params=expected_params)

        with self.stubber:
            try:
                DynamodbLookup.handle(base_lookup_key)
            except ValueError as err:
                self.assertEqual(
                    'No DynamoDB record matched the partition key: FakeKey',
                    str(err))
コード例 #13
0
ファイル: test_dynamodb.py プロジェクト: twitty-onica/runway
 def test_dynamodb_invalid_table_handler(self, _mock_client):
     """Test DynamoDB invalid table handler."""
     expected_params = {
         "TableName": "FakeTable",
         "Key": {
             "TestKey": {
                 "S": "TestVal"
             }
         },
         "ProjectionExpression": "TestVal,TestMap,String1",
     }
     service_error_code = "ResourceNotFoundException"
     self.stubber.add_client_error(
         "get_item",
         service_error_code=service_error_code,
         expected_params=expected_params,
     )
     with self.stubber:
         base_lookup_key = "FakeTable@TestKey:TestVal.TestMap[M].String1"
         try:
             DynamodbLookup.handle(base_lookup_key)
         except ValueError as err:
             self.assertEqual("Cannot find the DynamoDB table: FakeTable",
                              str(err))
コード例 #14
0
 def test_dynamodb_handler(self, _mock_client):
     """Test DynamoDB handler."""
     expected_params = {
         'TableName': 'TestTable',
         'Key': {
             'TestKey': {
                 'S': 'TestVal'
             }
         },
         'ProjectionExpression': 'TestVal,TestMap,String1'
     }
     base_lookup_key = 'TestTable@TestKey:TestVal.TestMap[M].String1'
     base_lookup_key_valid = 'StringVal1'
     self.stubber.add_response('get_item', self.get_parameters_response,
                               expected_params)
     with self.stubber:
         value = DynamodbLookup.handle(base_lookup_key)
         self.assertEqual(value, base_lookup_key_valid)
コード例 #15
0
ファイル: test_dynamodb.py プロジェクト: twitty-onica/runway
 def test_dynamodb_list_handler(self, _mock_client):
     """Test DynamoDB list handler."""
     expected_params = {
         "TableName": "TestTable",
         "Key": {
             "TestKey": {
                 "S": "TestVal"
             }
         },
         "ProjectionExpression": "TestVal,TestMap,List1",
     }
     self.stubber.add_response("get_item", self.get_parameters_response,
                               expected_params)
     with self.stubber:
         base_lookup_key = "TestTable@TestKey:TestVal.TestMap[M].List1[L]"
         value = DynamodbLookup.handle(base_lookup_key)
         base_lookup_key_valid = ["ListVal1", "ListVal2"]
         self.assertEqual(value, base_lookup_key_valid)