Beispiel #1
0
class URLParserTestCase(unittest.TestCase):
    def setUp(self):
        super(URLParserTestCase, self).setUp()
        self.parser = URLParser()

    def test_parse_static_url(self):
        route = self.parser.define_route('/api', FakeGetView, 'GET')
        self.assertIsInstance(route, PlainEndpoint)

    def test_parse_dynamic_url(self):
        route = self.parser.define_route('/api/{users}', FakeGetView, 'GET')
        self.assertIsInstance(route, DynamicEndpoint)

    def test_parse_invalid_url_1(self):
        self.assertRaises(EndpointValueError, self.parser.define_route,
                          '/api/{users', FakeGetView, 'GET')

    def test_parse_invalid_url_2(self):
        self.assertRaises(EndpointValueError, self.parser.define_route,
                          '/api/{users{}}', FakeGetView, 'GET')

    def test_parse_invalid_url_3(self):
        self.assertRaises(EndpointValueError, self.parser.define_route,
                          '/api/{users{}', FakeGetView, 'GET')

    def test_parse_invalid_url_4(self):
        self.assertRaises(EndpointValueError, self.parser.define_route,
                          '/api/{users"}', FakeGetView, 'GET')

    def test_parse_invalid_url_5(self):
        self.assertRaises(EndpointValueError, self.parser.define_route,
                          r"/api/{users+++}", FakeGetView, 'GET')
Beispiel #2
0
    def setUpClass(cls):
        super(TestHyperlinkedRelatedField, cls).setUpClass()
        session = SESSION()
        user = cls.TestHyperlinkedRelatedFieldUserModel(name='admin')
        address = cls.TestHyperlinkedRelatedFieldAddressModel(
            email_address='*****@*****.**')
        user_composite_pk = cls.TestHyperlinkedRelatedFieldCompositePkModel(
            id=1, name='test_user')
        user.addresses.append(address)
        session.add(user)
        session.add(address)
        session.add(user_composite_pk)
        session.commit()
        session.close()

        url_parser = URLParser()
        cls.data = {
            'urls': [
                url_parser.define_route('/user/{pk}/',
                                        FakeView, [
                                            'GET',
                                        ],
                                        name='user-detail'),
            ]
        }
        set_urlconf(cls.data)
Beispiel #3
0
class URLParserTestCase(unittest.TestCase):

    def setUp(self):
        super(URLParserTestCase, self).setUp()
        self.parser = URLParser()

    def test_parse_static_url(self):
        route = self.parser.define_route('/api', FakeGetView, 'GET')
        self.assertIsInstance(route, PlainEndpoint)

    def test_parse_dynamic_url(self):
        route = self.parser.define_route('/api/{users}', FakeGetView, 'GET')
        self.assertIsInstance(route, DynamicEndpoint)

    def test_parse_invalid_url_1(self):
        self.assertRaises(
            EndpointValueError,
            self.parser.define_route, '/api/{users', FakeGetView, 'GET'
        )

    def test_parse_invalid_url_2(self):
        self.assertRaises(
            EndpointValueError,
            self.parser.define_route,
            '/api/{users{}}', FakeGetView, 'GET'
        )

    def test_parse_invalid_url_3(self):
        self.assertRaises(
            EndpointValueError,
            self.parser.define_route,
            '/api/{users{}', FakeGetView, 'GET'
        )

    def test_parse_invalid_url_4(self):
        self.assertRaises(
            EndpointValueError,
            self.parser.define_route,
            '/api/{users"}', FakeGetView, 'GET'
        )

    def test_parse_invalid_url_5(self):
        self.assertRaises(
            EndpointValueError,
            self.parser.define_route,
            r"/api/{users+++}", FakeGetView, 'GET'
        )
Beispiel #4
0
 def setUpClass(cls):
     super(TestResolve, cls).setUpClass()
     url_parser = URLParser()
     cls.data = {
         'path': 'wss://127.0.0.1:8000',
         'urls': [
             url_parser.define_route(
                 '/user/list/', FakeView, ['GET', ], name='user-list'
             ),
             url_parser.define_route(
                 '/user/{pk}/', FakeView, ['GET', ]
             ),
             url_parser.define_route(
                 '/user/', FakeView, ['GET', ]
             )
         ]
     }
Beispiel #5
0
 def setUpClass(cls):
     super(TestResolve, cls).setUpClass()
     url_parser = URLParser()
     cls.data = {
         'path':
         'wss://127.0.0.1:8000',
         'urls': [
             url_parser.define_route('/user/list/',
                                     FakeView, [
                                         'GET',
                                     ],
                                     name='user-list'),
             url_parser.define_route('/user/{pk}/', FakeView, [
                 'GET',
             ]),
             url_parser.define_route('/user/', FakeView, [
                 'GET',
             ])
         ]
     }
Beispiel #6
0
 def setUp(self):
     super(TestReverse, self).setUpClass()
     url_parser = URLParser()
     data = {
         'path': 'wss://127.0.0.1:8000',
         'routes': {
             'user-detail': url_parser.define_route(
                 '/user/{pk}/', FakeView, ['GET', ], name='user-detail'
             )
         }
     }
     set_urlconf(data)
Beispiel #7
0
 def setUp(self):
     super(TestReverse, self).setUpClass()
     url_parser = URLParser()
     data = {
         'path': 'wss://127.0.0.1:8000',
         'routes': {
             'user-detail':
             url_parser.define_route('/user/{pk}/',
                                     FakeView, [
                                         'GET',
                                     ],
                                     name='user-detail')
         }
     }
     set_urlconf(data)
Beispiel #8
0
    def setUpClass(cls):
        super(TestHyperlinkedRelatedField, cls).setUpClass()
        cls.publisher = cls.Publisher.objects.create(name='publisher')
        cls.book = cls.Book.objects.create(name="test book")
        cls.book.publisher = cls.publisher
        cls.book.save()

        url_parser = URLParser()
        cls.data = {
            'urls': [
                url_parser.define_route(
                    '/book/{pk}/', FakeView, ['GET', ], name='book-detail'
                ),
            ]
        }
        set_urlconf(cls.data)