Exemplo n.º 1
0
class SchemaTestCase(unittest.TestCase):

    def setUp(self):
        super(SchemaTestCase, self).setUp()
        self.schema = Schema((
            st.String('name'),
            st.LinkObject('project'),
            st.Int('intval')
        ))

    def test_info(self):
        self.assertEquals(len(self.schema.info), 3)
        self.assertEquals(self.schema.info[1].name, 'project')

    def test_sortby_names(self):
        self.assertEquals(self.schema.sortby_names,
                          set(['name', 'intval',
                               'project.name', 'project.id']))

    def test_argument_matcher(self):
        eq = self.schema.argument_matcher('name', 'eq')
        self.assertTrue(eq('a', 'a'))
        self.assertFalse(eq('a', 'b'))

    def test_argument_matcher_bad_type(self):
        self.assertRaises(exc.InvalidRequest,
                          self.schema.argument_matcher, 'name', 'qwe')

    def test_argument_matcher_bad_name(self):
        self.assertRaises(KeyError,
                          self.schema.argument_matcher, 'stuff', 'eq')

    def test_parse_argument_parses(self):
        self.assertEquals(42, self.schema.parse_argument('intval', 'eq', '42'))

    def test_stuff_works(self):
        m = self.schema.argument_matcher('project', 'eq')
        v = self.schema.parse_argument('project', 'eq', 'PID')
        self.assertTrue(m({ 'id': 'PID' }, v))

    def test_doesnt_replace_methods(self):
        self.assertRaises(ValueError, Schema,
                          (st.Int('test'),), argument_matcher=('test',))
Exemplo n.º 2
0
class SchemaTestCase(unittest.TestCase):
    def setUp(self):
        super(SchemaTestCase, self).setUp()
        self.schema = Schema(
            (st.String('name'), st.LinkObject('project'), st.Int('intval')))

    def test_info(self):
        self.assertEquals(len(self.schema.info), 3)
        self.assertEquals(self.schema.info[1].name, 'project')

    def test_sortby_names(self):
        self.assertEquals(
            self.schema.sortby_names,
            set(['name', 'intval', 'project.name', 'project.id']))

    def test_argument_matcher(self):
        eq = self.schema.argument_matcher('name', 'eq')
        self.assertTrue(eq('a', 'a'))
        self.assertFalse(eq('a', 'b'))

    def test_argument_matcher_bad_type(self):
        self.assertRaises(exc.InvalidRequest, self.schema.argument_matcher,
                          'name', 'qwe')

    def test_argument_matcher_bad_name(self):
        self.assertRaises(KeyError, self.schema.argument_matcher, 'stuff',
                          'eq')

    def test_parse_argument_parses(self):
        self.assertEquals(42, self.schema.parse_argument('intval', 'eq', '42'))

    def test_stuff_works(self):
        m = self.schema.argument_matcher('project', 'eq')
        v = self.schema.parse_argument('project', 'eq', 'PID')
        self.assertTrue(m({'id': 'PID'}, v))

    def test_doesnt_replace_methods(self):
        self.assertRaises(ValueError,
                          Schema, (st.Int('test'), ),
                          argument_matcher=('test', ))