def test_dict(self): data = { 'sid': 3, 'account_sid': 4, } field = fields.FormattedString('/foo/{account_sid}/{sid}/') assert field.output('foo', data) == '/foo/4/3/'
def test_formatted_string_field_with_description(self): prop = field_to_property( fields.FormattedString('Hello {name}', description='A description')) self.assertEqual(prop, { 'type': 'string', 'description': 'A description' })
def test_tuple(self): field = fields.FormattedString('/foo/{0[account_sid]}/{0[sid]}/') self.assert_field_raises(field, (3, 4))
def test_invalid_object(self): field = fields.FormattedString('/foo/{0[account_sid]}/{0[sid]}/') self.assert_field_raises(field, {})
def test_none(self): field = fields.FormattedString('{foo}') # self.assert_field_raises(field, None) with pytest.raises(fields.MarshallingError): field.output('foo', None)
def test_object(self, mocker): obj = mocker.Mock() obj.sid = 3 obj.account_sid = 4 field = fields.FormattedString('/foo/{account_sid}/{sid}/') assert field.output('foo', obj) == '/foo/4/3/'
def test_defaults(self): field = fields.FormattedString('Hello {name}') assert not field.required assert field.__schema__ == {'type': 'string'}
def test_object(self): obj = Mock() obj.sid = 3 obj.account_sid = 4 field = fields.FormattedString('/foo/{account_sid}/{sid}/') assert_equal(field.output('foo', obj), '/foo/4/3/')
def test_formatted_string_field_with_readonly(self): prop = field_to_property( fields.FormattedString('Hello {name}', readonly=True)) self.assertEqual(prop, {'type': 'string', 'readOnly': True})
def test_formatted_field_with_title(self): prop = field_to_property( fields.FormattedString('Hello {name}', title='A title')) self.assertEqual(prop, {'type': 'string', 'title': 'A title'})
def test_simple_formatted_string_field(self): prop = field_to_property(fields.FormattedString('Hello {name}')) self.assertEqual(prop, {'type': 'string'})