Exemplo n.º 1
0
    def test_init(self, mocker):
        mocker.patch.object(renderers.FieldToRender, "_get_one_of_values")
        mocker.patch.object(renderers, "get_object_fields")
        mocker.patch.object(renderers.FieldToRender, "_get_array_items")
        mocker.patch.object(renderers.FieldToRender, "_build_comment")
        mocker.patch.object(renderers.FieldToRender, "_get_default")

        field_metadata = mocker.Mock()
        field_to_render = renderers.FieldToRender("field_name", True, field_metadata)
        assert field_to_render.name == "field_name"
        assert field_to_render.required
        assert field_to_render.field_metadata == field_metadata
        assert field_to_render.one_of_values == field_to_render._get_one_of_values.return_value
        assert field_to_render.object_properties == renderers.get_object_fields.return_value
        assert field_to_render.array_items == field_to_render._get_array_items.return_value
        assert field_to_render.comment == field_to_render._build_comment.return_value
        assert field_to_render.default == field_to_render._get_default.return_value
        field_to_render._build_comment.assert_called_with(
            [
                field_to_render._get_secret_comment,
                field_to_render._get_required_comment,
                field_to_render._get_type_comment,
                field_to_render._get_description_comment,
                field_to_render._get_example_comment,
            ]
        )
Exemplo n.º 2
0
 def test_is_array_of_objects(self):
     field_to_render = renderers.FieldToRender("field_name", True, {"foo": "bar"})
     field_to_render.type = "array"
     field_to_render.items = {"type": "object"}
     assert field_to_render.is_array_of_objects
     field_to_render.type = "array"
     field_to_render.items = {"type": "int"}
     assert not field_to_render.is_array_of_objects
Exemplo n.º 3
0
    def test__get_array_items(self, mocker):
        mocker.patch.object(renderers, "parse_fields")
        mocker.patch.object(renderers.FieldToRender, "is_array_of_objects", False)

        field_to_render = renderers.FieldToRender("field_name", True, {"foo": "bar"})
        assert field_to_render._get_array_items() == []
        field_to_render.items = {"required": [], "properties": []}
        mocker.patch.object(renderers.FieldToRender, "is_array_of_objects", True)
        assert field_to_render._get_array_items() == renderers.parse_fields.return_value
        renderers.parse_fields.assert_called_with([], [])
Exemplo n.º 4
0
    def test__get_one_of_values(self, mocker):
        field_to_render = renderers.FieldToRender("field_name", True, {"foo": "bar"})
        field_to_render.oneOf = False
        assert field_to_render._get_one_of_values() == []

        mocker.patch.object(renderers, "get_object_fields")
        one_of_value = mocker.Mock()
        field_to_render.oneOf = [one_of_value]
        one_of_values = field_to_render._get_one_of_values()
        renderers.get_object_fields.assert_called_once_with(one_of_value)
        assert one_of_values == [renderers.get_object_fields.return_value]
Exemplo n.º 5
0
 def test__get_secret_comment(self):
     field_to_render = renderers.FieldToRender("field_name", True, {"foo": "bar"})
     field_to_render.airbyte_secret = True
     assert field_to_render._get_secret_comment() == "SECRET (please store in environment variables)"
     field_to_render.airbyte_secret = False
     assert field_to_render._get_secret_comment() is None
Exemplo n.º 6
0
 def test__get_type_comment(self, _type, expected_comment):
     field_to_render = renderers.FieldToRender("field_name", True, {"foo": "bar"})
     field_to_render.type = _type
     assert field_to_render._get_type_comment() == expected_comment
Exemplo n.º 7
0
 def test__get_required_comment(self):
     field_to_render = renderers.FieldToRender("field_name", True, {"foo": "bar"})
     field_to_render.required = True
     assert field_to_render._get_required_comment() == "REQUIRED"
     field_to_render.required = False
     assert field_to_render._get_required_comment() == "OPTIONAL"
Exemplo n.º 8
0
 def test_get_attr(self):
     field_to_render = renderers.FieldToRender("field_name", True, {"foo": "bar"})
     assert field_to_render.foo == "bar"
     assert field_to_render.not_existing is None
Exemplo n.º 9
0
 def test__get_default(self, field_metadata, expected_default):
     field_to_render = renderers.FieldToRender("field_name", True, field_metadata)
     assert field_to_render.default == expected_default
Exemplo n.º 10
0
 def test__get_example_comment(self, examples_value, expected_output):
     field_to_render = renderers.FieldToRender("field_name", True, {"foo": "bar"})
     field_to_render.examples = examples_value
     assert field_to_render._get_example_comment() == expected_output
Exemplo n.º 11
0
 def test__get_description_comment(self):
     field_to_render = renderers.FieldToRender("field_name", True, {"foo": "bar"})
     field_to_render.description = "foo"
     assert field_to_render._get_description_comment() == "foo"
     field_to_render.description = None
     assert field_to_render._get_description_comment() is None