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", } ])
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())
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", })
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())
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)
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': {} })
def test_get_mapping(self): field = ListField(StringField(attr='foo.bar')) self.assertEqual({ 'type': 'string', }, field.to_dict())
def test_get_mapping(self): field = StringField() self.assertEqual({ 'type': 'string', }, field.to_dict())