Esempio n. 1
0
 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/'
Esempio n. 2
0
 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'
     })
Esempio n. 3
0
 def test_tuple(self):
     field = fields.FormattedString('/foo/{0[account_sid]}/{0[sid]}/')
     self.assert_field_raises(field, (3, 4))
Esempio n. 4
0
 def test_invalid_object(self):
     field = fields.FormattedString('/foo/{0[account_sid]}/{0[sid]}/')
     self.assert_field_raises(field, {})
Esempio n. 5
0
 def test_none(self):
     field = fields.FormattedString('{foo}')
     # self.assert_field_raises(field, None)
     with pytest.raises(fields.MarshallingError):
         field.output('foo', None)
Esempio n. 6
0
 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/'
Esempio n. 7
0
 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/')
Esempio n. 9
0
 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})
Esempio n. 10
0
 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'})
Esempio n. 11
0
 def test_simple_formatted_string_field(self):
     prop = field_to_property(fields.FormattedString('Hello {name}'))
     self.assertEqual(prop, {'type': 'string'})