コード例 #1
0
    def test_convert_attr_value_default(self, mock_get_field_type):
        # type: (MagicMock) -> None
        # Arrange
        value = "attribute_field_value"
        mock_get_field_type.return_value = "text"

        # Act
        actual_result = db.convert_attr_value("attribute_name",
                                              "attribute_field_name",
                                              value)
        # Assert
        self.assertEqual(value, actual_result)
コード例 #2
0
    def test_convert_attr_value_interval(self,
                                         mock_get_field_type):
        # type: (MagicMock) -> None

        # Arrange
        mock_get_field_type.return_value = "interval(0)"

        value = "1 day"

        expected_result = "'1 day' :: interval"

        # Act
        actual_result = db.convert_attr_value("attribute_name",
                                              "attribute_field_name",
                                              value)
        # Assert
        self.assertEqual(expected_result, str(actual_result))
コード例 #3
0
    def test_convert_attr_value_timestamptz(self,
                                            mock_get_field_type):
        # type: (MagicMock) -> None

        # Arrange
        mock_get_field_type.return_value = "timestamptz"

        value = "2017-01-01 00:00"

        expected_result = datetime.datetime(2017, 1, 1, 0, 0)

        # Act
        actual_result = db.convert_attr_value("attribute_name",
                                              "attribute_field_name",
                                              value)
        # Assert
        self.assertEqual(expected_result, actual_result)
コード例 #4
0
    def test_convert_attr_value_offentlighedundtagettype_none(
            self,
            mock_get_field_type):
        # type: (MagicMock) -> None

        # Arrange
        mock_get_field_type.return_value = "offentlighedundtagettype"

        value = {}

        expected_result = None

        # Act
        actual_result = db.convert_attr_value("attribute_name",
                                              "attribute_field_name",
                                              value)
        # Assert
        self.assertEqual(expected_result, actual_result)
コード例 #5
0
    def test_convert_attr_value_soegeord(self,
                                         mock_get_field_type):
        # type: (MagicMock) -> None
        from oio_rest.db_helpers import Soegeord

        # Arrange
        mock_get_field_type.return_value = "soegeord"

        value = [
            ["identifier1", "description1", "category1"],
            ["identifier2", "description2", "category2"]
        ]

        expected_result = [Soegeord(*value[0]), Soegeord(*value[1])]

        # Act
        actual_result = db.convert_attr_value("attribute_name",
                                              "attribute_field_name",
                                              value)
        # Assert
        self.assertEqual(expected_result, actual_result)
コード例 #6
0
    def test_convert_attr_value_offentlighedundtagettype(self,
                                                         mock_get_field_type):
        # type: (MagicMock) -> None
        from oio_rest.db_helpers import OffentlighedUndtaget

        # Arrange
        mock_get_field_type.return_value = "offentlighedundtagettype"

        alternativtitel = 'ALTERNATIVTITEL'
        hjemmel = 'HJEMMEL'

        value = {
            'alternativtitel': alternativtitel,
            'hjemmel': hjemmel
        }

        expected_result = OffentlighedUndtaget(alternativtitel, hjemmel)

        # Act
        actual_result = db.convert_attr_value("attribute_name",
                                              "attribute_field_name",
                                              value)
        # Assert
        self.assertEqual(expected_result, actual_result)