Пример #1
0
class TestOptionType(unittest.TestCase):

    def setUp(self):
        self.opttype = OptionType()

    def test_when_options_is_null_then_validation_passes(self):
        self.opttype.validate(None)

    def test_when_options_is_empty_then_validation_passes(self):
        self.opttype.validate([])

    def test_when_options_is_not_a_list_then_validation_fails(self):
        self.assertRaises(ValidationError,
                          self.opttype.validate,
                          'options')

    def test_when_options_is_a_one_dimension_array_then_validation_fails(self):
        self.assertRaises(ValidationError,
                          self.opttype.validate,
                          ['option1', 'option2', 'option3'])

    def test_when_items_in_options_are_not_pairs_then_validation_fails(self):
        self.assertRaises(ValidationError,
                          self.opttype.validate,
                          [['option1', 'option2', 'option3']])

    def test_when_an_option_pair_are_not_strings_then_validation_fails(self):
        self.assertRaises(ValidationError,
                          self.opttype.validate,
                          [['option', 1]])

    def test_when_option_items_are_pairs_of_strings_then_validation_passes(self):
        self.opttype.validate([['option1', 'value1'],
                               ['option2', 'value2']])
Пример #2
0
class TestOptionType(unittest.TestCase):
    def setUp(self):
        self.opttype = OptionType()

    def test_when_options_is_null_then_validation_passes(self):
        self.opttype.validate(None)

    def test_when_options_is_empty_then_validation_passes(self):
        self.opttype.validate([])

    def test_when_options_is_not_a_list_then_validation_fails(self):
        self.assertRaises(ValidationError, self.opttype.validate, 'options')

    def test_when_options_is_a_one_dimension_array_then_validation_fails(self):
        self.assertRaises(ValidationError, self.opttype.validate,
                          ['option1', 'option2', 'option3'])

    def test_when_items_in_options_are_not_pairs_then_validation_fails(self):
        self.assertRaises(ValidationError, self.opttype.validate,
                          [['option1', 'option2', 'option3']])

    def test_when_an_option_pair_are_not_strings_then_validation_fails(self):
        self.assertRaises(ValidationError, self.opttype.validate,
                          [['option', 1]])

    def test_when_option_items_are_pairs_of_strings_then_validation_passes(
            self):
        self.opttype.validate([['option1', 'value1'], ['option2', 'value2']])
Пример #3
0
def load(core_rest_api):
    blueprint = Blueprint('voicemails',
                          __name__,
                          url_prefix='/%s/voicemails' % config.API_VERSION)
    document = core_rest_api.content_parser.document(
        Field('id', Int()), Field('name', Unicode()),
        Field('number', Unicode()), Field('context', Unicode()),
        Field('password', Unicode()), Field('email', Unicode()),
        Field('language', Unicode()), Field('timezone', Unicode()),
        Field('pager', Unicode()), Field('max_messages', Int()),
        Field('attach_audio', Boolean()), Field('delete_messages', Boolean()),
        Field('ask_password', Boolean()), Field('enabled', Boolean()),
        Field('options', OptionType()))

    converter = Converter.resource(document, Voicemail)

    service = build_service()
    resource = VoicemailResource(service, converter)

    DecoratorChain.register_scrud(core_rest_api, blueprint, resource)
Пример #4
0
 def setUp(self):
     self.opttype = OptionType()
Пример #5
0
 def setUp(self):
     self.opttype = OptionType()