예제 #1
0
    def test_model_router(self):
        router = Router()
        handler_name = 'handler'
        router.register(handler_name, ModelHandler)

        self.assertItemsEqual(
            [('^/{}/$'.format(handler_name), ModelHandler),
             ('^/{}$'.format(handler_name), ModelHandler),
             ('^/{}/(?P<urlsafe>[^/.]+)/$'.format(handler_name), ModelHandler),
             ('^/{}/(?P<urlsafe>[^/.]+)$'.format(handler_name), ModelHandler)],
            router.urls)
예제 #2
0
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

        ndb.get_context().clear_cache()

        router = Router()
        router.register('user', APIUserHandler)
        app = webapp2.WSGIApplication(router.urls)
        self.testapp = webtest.TestApp(app)
예제 #3
0
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

        ndb.get_context().clear_cache()

        router = Router()
        router.register('user', DynamicUserHandler)
        app = webapp2.WSGIApplication(router.urls)
        self.testapp = webtest.TestApp(app)
        self.entity = UserModel(email='*****@*****.**',
                                first_name='admin',
                                last_name='restae',
                                age=28)
        self.entity.put()
예제 #4
0
    def setUp(self):
        class Author(ndb.Model):
            name = ndb.StringProperty()
            lang = ndb.StringProperty()

        class AuthorSerializer(UserModelSerializer):
            class Meta:
                model = Author
                fields = '__all__'

        class Book(ndb.Model):
            name = ndb.StringProperty()
            author = ndb.KeyProperty(Author)
            page_count = ndb.IntegerProperty()

        class BookSerializer(UserModelSerializer):
            class Meta:
                model = Book
                fields = '__all__'

        class BookModelHandler(APIModelHandler):
            queryset = Book.query()
            serializer_class = BookSerializer

        class AuthorModelHandler(APIModelHandler):
            queryset = Author.query()
            serializer_class = AuthorSerializer

        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

        ndb.get_context().clear_cache()

        router = Router()
        router.register('book', BookModelHandler)
        router.register('author', AuthorModelHandler)

        app = webapp2.WSGIApplication(router.urls)
        self.testapp = webtest.TestApp(app)

        self.author_1 = Author(name='Azomov', lang='US')
        self.author_1.put()
        self.author_2 = Author(name='Barjavel', lang='FR')
        self.author_2.put()

        self.book_1 = Book(name='Fondation',
                           page_count=1337,
                           author=self.author_1.key)
        self.book_1.put()

        self.book_2 = Book(name='Ravages',
                           page_count=250,
                           author=self.author_2.key)
        self.book_2.put()