Beispiel #1
0
    def test_convert_relations_calls_convert_relation_value(self,
                                                            mock_conv_rel):
        # type: (MagicMock) -> None
        # Arrange

        mock_conv_rel.return_value = "value"

        relations = {
            'relation1': [
                {
                    'field1': 'value1',
                    'field2': 'value2'
                }
            ],
            'relation2': [
                {
                    'field3': 'value3',
                    'field4': 'value4'
                }
            ]
        }

        # Act
        db.convert_relations(relations, "classname")

        # Assert
        self.assertIn(call("classname", "field1", "value1"),
                      mock_conv_rel.call_args_list)
        self.assertIn(call("classname", "field2", "value2"),
                      mock_conv_rel.call_args_list)
        self.assertIn(call("classname", "field3", "value3"),
                      mock_conv_rel.call_args_list)
        self.assertIn(call("classname", "field4", "value4"),
                      mock_conv_rel.call_args_list)
Beispiel #2
0
    def test_convert_relations_raises_on_malformed_relation(self):
        # Arrange
        relations = {
            'relation': [
                "This is not a dict"
            ]
        }

        # Act & Assert
        with self.assertRaises(BadRequestException):
            db.convert_relations(relations, "classname")
Beispiel #3
0
    def test_convert_relations_no_value(self,
                                        mock_conv_rel):
        # type: (MagicMock) -> None
        # Arrange

        mock_conv_rel.return_value = "value"

        relations = {}

        # Act
        actual_result = db.convert_relations(relations, "classname")

        # Assert
        self.assertEqual(relations, actual_result)
Beispiel #4
0
    def test_convert_relations_returns_as_expected(self):
        # type: (MagicMock) -> None
        # Arrange

        relations = {
            'relation1': [
                {
                    'field1': 'value1',
                    'field2': 'value2'
                }
            ],
            'relation2': [
                {
                    'field3': 'value3',
                    'field4': 'value4'
                }
            ]
        }

        expected_result = {
            'relation1': [
                {
                    'field1': 'value1',
                    'field2': 'value2'
                }
            ],
            'relation2': [
                {
                    'field3': 'value3',
                    'field4': 'value4'
                }
            ]
        }

        # Act
        actual_result = db.convert_relations(relations, "classname")

        # Assert
        self.assertEqual(expected_result, actual_result)