Пример #1
0
    def test_get_value_from_iterable(self):
        field = ObjectField(attr='person', properties={
            'first_name': StringField(analyzier='foo'),
            'last_name': StringField()
        })

        instance = NonCallableMock(
            person=[
                NonCallableMock(
                    first_name="foo1", last_name="bar1"
                ),
                NonCallableMock(
                    first_name="foo2", last_name="bar2"
                )
            ]
        )

        self.assertEqual(field.get_value_from_instance(instance), [
            {
                'first_name': "foo1",
                'last_name': "bar1",
            },
            {
                'first_name': "foo2",
                'last_name': "bar2",
            }
        ])
Пример #2
0
    def test_get_mapping(self):
        field = StringField()

        expected_type = 'string' if ES_MAJOR_VERSION == 2 else 'text'

        self.assertEqual({
            'type': expected_type,
        }, field.to_dict())
Пример #3
0
    def test_get_value_from_instance(self):
        field = ObjectField(attr='person', properties={
            'first_name': StringField(analyzier='foo'),
            'last_name': StringField()
        })

        instance = NonCallableMock(person=NonCallableMock(
            first_name='foo', last_name='bar'))

        self.assertEqual(field.get_value_from_instance(instance), {
            'first_name': "foo",
            'last_name': "bar",
        })
Пример #4
0
    def test_get_mapping(self):
        field = ObjectField(attr='person', properties={
            'first_name': StringField(analyzer='foo'),
            'last_name': StringField()
        })

        self.assertEqual({
            'type': 'object',
            'properties': {
                'first_name': {'type': 'string', 'analyzer': 'foo'},
                'last_name': {'type': 'string'},
            }
        }, field.to_dict())
Пример #5
0
 def test_get_value_from_instance(self):
     instance = NonCallableMock(
         foo=NonCallableMock(bar=["alpha", "beta", "gamma"])
     )
     field = ListField(StringField(attr='foo.bar'))
     self.assertEqual(
         field.get_value_from_instance(instance), instance.foo.bar)
Пример #6
0
    def test_get_value_from_instance_with_none_inner_objectfield(self):
        field = ObjectField(attr='person',
                            properties={
                                'first_name':
                                StringField(analyzier='foo'),
                                'last_name':
                                StringField(),
                                'aditional':
                                ObjectField(properties={'age': IntegerField()})
                            })

        instance = NonCallableMock(person=NonCallableMock(
            first_name="foo", last_name="bar", aditional=None))

        self.assertEqual(field.get_value_from_instance(instance), {
            'first_name': "foo",
            'last_name': "bar",
            'aditional': {}
        })
Пример #7
0
 def test_get_mapping(self):
     field = ListField(StringField(attr='foo.bar'))
     self.assertEqual({
         'type': 'string',
     }, field.to_dict())
Пример #8
0
    def test_get_mapping(self):
        field = StringField()

        self.assertEqual({
            'type': 'string',
        }, field.to_dict())