• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Pizza类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中slumber_examples.models.Pizza的典型用法代码示例。如果您正苦于以下问题:Python Pizza类的具体用法?Python Pizza怎么用?Python Pizza使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Pizza类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: OrderTests

class OrderTests(ConfigureUser, TestCase):
    def setUp(self):
        super(OrderTests, self).setUp()
        self.pizza = Pizza(name="S1", for_sale=True)
        self.pizza.save()
        self.cnx = Client()

    def test_order_get(self):
        with patch("slumber.connector._get_slumber_authn_name", lambda: "service"):
            pizza = self.cnx.slumber_examples.Pizza.get(id=self.pizza.id)
            self.assertEquals(
                pizza._operations["order"], "http://localhost:8000/slumber/slumber_examples/Pizza/order/1/"
            )
            # Do an unsigned GET so there will be no user logged in
            response = self.client.get("/slumber/slumber_examples/Pizza/order/1/")
            self.assertEquals(response.status_code, 200, response.content)
            json = loads(response.content)
            self.assertEquals(json, dict(_meta=dict(status=200, message="OK"), form=dict(quantity="integer")))

    def test_order_post(self):
        pizza = self.cnx.slumber_examples.Pizza.get(id=self.pizza.id)
        response = self.client.post("/slumber/slumber_examples/Pizza/order/1/", dict(quantity=3))
        self.assertEquals(response.status_code, 501, response.content)

    def test_order_create_with_pk(self):
        pizza2 = self.cnx.slumber_examples.Pizza.create(id=2, name="S2", for_sale=True)
        pizza3 = Pizza.objects.create(name="S3", for_sale=True)
        self.assertEqual(Pizza.objects.count(), 3)
开发者ID:merlian,项目名称:django-slumber,代码行数:28,代码来源:operations.py


示例2: test_instance_data_pizzaprice

 def test_instance_data_pizzaprice(self):
     s = Pizza(name='p1', for_sale=True)
     s.save()
     p = PizzaPrice(pizza=s, date='2010-01-01')
     p.save()
     response, json = self.do_get('/slumber_examples/PizzaPrice/data/%s/' % p.pk)
     self.assertEquals(response.status_code, 200)
     expected = dict(
         _meta={'message': 'OK', 'status': 200, 'username': 'service'},
         type=self.url('/slumber_examples/PizzaPrice/'),
         identity=self.url('/slumber_examples/PizzaPrice/data/1/'),
         display="PizzaPrice object",
         operations=dict(
             data=self.url('/slumber_examples/PizzaPrice/data/1/'),
             delete=self.url('/slumber_examples/PizzaPrice/delete/1/'),
             update=self.url('/slumber_examples/PizzaPrice/update/1/')),
         fields=dict(
             id={'data': 1, 'kind': 'value', 'type': 'django.db.models.fields.AutoField'},
             pizza={'data': {
                     'type': self.url('/slumber_examples/Pizza/'), 'display':'p1',
                     'data': self.url('/slumber_examples/Pizza/data/1/')},
                 'kind': 'object', 'type': self.url('/slumber_examples/Pizza/')},
             date={'data': '2010-01-01', 'kind': 'value', 'type': 'django.db.models.fields.DateField'},
         ),
         data_arrays={'amounts': self.url('/slumber_examples/PizzaPrice/data/1/amounts/')})
     if get_version() >= "1.7":
         expected['data_arrays']['pizza_id'] = self.url(
                 '/slumber_examples/PizzaPrice/data/1/pizza_id/')
     self.assertEquals(json, expected)
开发者ID:nuimk-proteus,项目名称:django-slumber,代码行数:29,代码来源:views.py


示例3: test_instance_data_pizza

 def test_instance_data_pizza(self):
     s = Pizza(name='S1', for_sale=True)
     s.save()
     response, json = self.do_get('/slumber_examples/Pizza/data/%s/' % s.pk)
     self.maxDiff = None
     expected = dict(
         _meta={'message': 'OK', 'status': 200, 'username': 'service'},
         type=self.url('/slumber_examples/Pizza/'),
         identity=self.url('/slumber_examples/Pizza/data/1/'),
         display='S1',
         operations=dict(
             data=self.url('/slumber_examples/Pizza/data/1/'),
             delete=self.url('/slumber_examples/Pizza/delete/1/'),
             order=self.url('/slumber_examples/Pizza/order/1/'),
             update=self.url('/slumber_examples/Pizza/update/1/')),
         fields=dict(
             id=dict(data=s.pk, kind='value', type='django.db.models.fields.AutoField'),
             for_sale=dict(data=s.for_sale, kind='value', type='django.db.models.fields.BooleanField'),
             max_extra_toppings=dict(data=s.max_extra_toppings, kind='value', type='django.db.models.fields.IntegerField'),
             name=dict(data=s.name, kind='value', type='django.db.models.fields.CharField'),
             exclusive_to={'data': None, 'kind': 'object', 'type': self.url('/slumber_examples/Shop/')}),
         data_arrays=dict(
             prices=self.url('/slumber_examples/Pizza/data/%s/prices/' % s.pk)))
     if get_version() >= "1.8":
         expected['fields']['exclusive_to_id'] = expected['fields']['exclusive_to']
     elif get_version() >= "1.7":
         expected['data_arrays']['exclusive_to_id'] = self.url(
                 '/slumber_examples/Pizza/data/1/exclusive_to_id/')
     self.assertEquals(json, expected)
开发者ID:nuimk-proteus,项目名称:django-slumber,代码行数:29,代码来源:views.py


示例4: test_update_instance

 def test_update_instance(self):
     self.user.is_superuser = True
     self.user.save()
     s = Pizza(name='S1', for_sale=True)
     s.save()
     response, json = self.do_post('/slumber_examples/Pizza/update/1/', {
         'name': 'New pizza'})
     self.assertEquals(response.status_code, 200)
     n = Pizza.objects.get(pk=1)
     self.assertEquals(n.name, "New pizza")
开发者ID:pombredanne,项目名称:django-slumber,代码行数:10,代码来源:views.py


示例5: test_delete_instance

 def test_delete_instance(self):
     self.user.is_superuser = True
     self.user.save()
     s = Pizza(name='P')
     s.save()
     response, json = self.do_get('/slumber_examples/Pizza/data/%s/' % s.pk)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(json['operations'].has_key('delete'), json['operations'])
     response, json = self.do_post(json['operations']['delete'], {})
     self.assertEquals(response.status_code, 200)
     with self.assertRaises(Pizza.DoesNotExist):
         Pizza.objects.get(pk=s.pk)
开发者ID:pombredanne,项目名称:django-slumber,代码行数:12,代码来源:views.py


示例6: test_get_instance

 def test_get_instance(self):
     s = Pizza(name='S1', for_sale=True)
     s.save()
     response, json = self.do_get('/slumber_examples/Pizza/')
     get_url = json['operations']['get']
     self.assertEquals(get_url, self.url('/slumber_examples/Pizza/get/'))
     def check_query(query):
         response, json = self.do_get(get_url, query)
         self.assertEquals(response.status_code, 200, response)
         self.assertTrue(json['identity'].endswith(
             '/slumber_examples/Pizza/data/%s/' % s.pk), response)
     check_query({'pk': s.pk})
     check_query({'id': s.pk})
     check_query({'name': s.name})
开发者ID:pombredanne,项目名称:django-slumber,代码行数:14,代码来源:views.py


示例7: test_instance_data_array

 def test_instance_data_array(self):
     s = Pizza(name='P', for_sale=True)
     s.save()
     for p in range(15):
         PizzaPrice(pizza=s, date='2011-04-%s' % (p+1)).save()
     response, json = self.do_get('/slumber_examples/Pizza/data/%s/prices/' % s.pk)
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(json['page']), 10, json)
     self.assertTrue(json.has_key('next_page'), json)
     self.assertEquals(json['next_page'],
         self.url('/slumber_examples/Pizza/data/1/prices/?start_after=6'),
         json['next_page'])
     response, json = self.do_get('/slumber_examples/Pizza/data/1/prices/',
         {'start_after': '6'})
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(json['page']), 5)
     self.assertEquals(json['page'][0], {
         'type': self.url('/slumber_examples/PizzaPrice/'),
         'pk': 5, 'data': self.url('/slumber_examples/PizzaPrice/data/5/'), 'display': 'PizzaPrice object'})
     self.assertFalse(json.has_key('next_page'), json.keys())
开发者ID:pombredanne,项目名称:django-slumber,代码行数:20,代码来源:views.py


示例8: setUp

 def setUp(self):
     super(TestsWithPizza, self).setUp()
     self.s = Pizza(name='S1', for_sale=True)
     self.s.save()
     self.pizza = client.slumber_examples.Pizza.get(pk=self.s.pk)
开发者ID:DjNero,项目名称:django-slumber,代码行数:5,代码来源:client.py


示例9: TestsWithPizza

class TestsWithPizza(ConfigureUser, TestCase):
    def setUp(self):
        super(TestsWithPizza, self).setUp()
        self.s = Pizza(name='S1', for_sale=True)
        self.s.save()
        self.pizza = client.slumber_examples.Pizza.get(pk=self.s.pk)

    def test_instance_type(self):
        self.assertEqual(self.s.pk, self.pizza.id)
        self.assertEqual(type(self.pizza).__name__,
            'http://localhost:8000/slumber/slumber_examples/Pizza/data/1/')
        pizza_type = str(type(self.pizza))
        self.assertTrue(pizza_type.endswith("slumber_examples/Pizza/data/1/'>"),
            pizza_type)

    def test_cache_ttl(self):
        self.assertEqual(self.pizza._CACHE_TTL, 0)

    def test_instance_data(self):
        self.assertEqual('S1', self.pizza.name)
        prices = self.pizza.prices
        self.assertEqual(len(prices), 0)
        self.assertTrue(self.pizza.exclusive_to is None, self.pizza.exclusive_to)
        try:
            self.pizza.not_a_field
            self.fail("This should have thrown an AttributeError")
        except AttributeError:
            pass

    def test_instance_data_with_data_array(self):
        for p in range(15):
            PizzaPrice(pizza=self.s, date='2011-04-%s' % (p+1)).save()
        self.assertEqual('S1', self.pizza.name)
        prices = self.pizza.prices
        self.assertEquals(len(prices), 15)
        first_price = prices[0]
        self.assertEquals(unicode(first_price), "PizzaPrice object")
        self.assertEquals(first_price.pizza.for_sale, True)

    def test_instance_data_with_nested_data_array(self):
        p = PizzaPrice(pizza=self.s, date='2010-06-20')
        p.save()
        PizzaSizePrice(price=p, size='s', amount='13.95').save()
        PizzaSizePrice(price=p, size='m', amount='15.95').save()
        PizzaSizePrice(price=p, size='l', amount='19.95').save()
        self.assertEqual('S1', self.pizza.name)
        self.assertEqual(len(self.pizza.prices), 1)
        self.assertEqual(len(self.pizza.prices[0].amounts), 3)
        for a in self.pizza.prices[0].amounts:
            self.assertTrue(a.size in ['s', 'm', 'l'], a.size)

    def test_instance_no_pk(self):
        with self.assertRaises(AssertionError):
            pizza = client.slumber_examples.Pizza.get()

    def test_2nd_pizza_comes_from_cache(self):
        # Force a cache read
        self.assertEqual(unicode(self.pizza), u"S1")
        # Make a 2nd alias to the same object
        fail = lambda *a, **f: self.fail("_InstanceConnector.__init__ called again %s, %s" % (a, f))
        with patch('slumber.connector.api._InstanceConnector.__init__', fail):
            pizza2 = client.slumber_examples.Pizza.get(pk=self.s.pk)
            self.assertEqual(unicode(pizza2), u"S1")

    def test_pizza_not_found(self):
        with self.assertRaises(AssertionError):
            p2 = client.slumber_examples.Pizza.get(pk=2)
开发者ID:DjNero,项目名称:django-slumber,代码行数:67,代码来源:client.py


示例10: setUp

 def setUp(self):
     super(OrderTests, self).setUp()
     self.pizza = Pizza(name="S1", for_sale=True)
     self.pizza.save()
     self.cnx = Client()
开发者ID:merlian,项目名称:django-slumber,代码行数:5,代码来源:operations.py


示例11: test_pizza_has_instance_proxy

 def test_pizza_has_instance_proxy(self):
     lpizza = Pizza(name='Test pizza')
     lpizza.save()
     rpizza = client.slumber_examples.Pizza.get(
         pk=lpizza.pk)
     self.assertTrue(rpizza.has_pizza_proxy())
开发者ID:DjNero,项目名称:django-slumber,代码行数:6,代码来源:proxies.py


示例12: setUp

 def setUp(self):
     self.pizza = Pizza(name='Before change')
     self.pizza.save()
     super(TestAuthnRequired, self).setUp()
开发者ID:duisetsuna,项目名称:django-slumber,代码行数:4,代码来源:authentication.py


示例13: TestAuthnRequired

class TestAuthnRequired(ConfigureUser, TestCase):
    def setUp(self):
        self.pizza = Pizza(name='Before change')
        self.pizza.save()
        super(TestAuthnRequired, self).setUp()

    def test_directory_works_when_not_authenticated(self):
        response = self.client.get('/slumber/')
        self.assertEqual(response.status_code, 200)

    def test_model_requires_authentication(self):
        response = self.client.get('/slumber/slumber_examples/Pizza/data/%s/' % self.pizza.pk)
        self.assertEqual(response.status_code, 401)
        self.assertEqual(response.get('WWW-Authenticate', None),
            'FOST Realm="Slumber"')

    def test_authenticated(self):
        response = self.signed_get(None,
            '/slumber/slumber_examples/Pizza/data/234234/')
        self.assertEqual(response.status_code, 404)
        json = loads(response.content)
        self.assertEqual(json["error"], "Pizza matching query does not exist.")

    def test_model_create_requires_permission(self):
        response = self.signed_post(self.user.username,
            '/slumber/slumber_examples/Pizza/create/',
            {'name': 'new test pizza'})
        self.assertEqual(response.status_code, 403)

    def test_model_create_checks_correct_permission(self):
        permission = Permission.objects.get(codename="add_pizza")
        self.user.user_permissions.add(permission)
        response = self.signed_post(None,
            '/slumber/slumber_examples/Pizza/create/',
            {'name': 'new test pizza'})
        self.assertEqual(response.status_code, 200, response.content)

    def test_model_update_requires_permission(self):
        response = self.signed_post(self.user.username,
            '/slumber/slumber_examples/Pizza/update/%s/' % self.pizza.pk,
            {'name': 'new test pizza'})
        self.assertEqual(response.status_code, 403)

    def test_model_update_checks_correct_permission(self):
        permission = Permission.objects.get(codename="change_pizza")
        self.user.user_permissions.add(permission)
        response = self.signed_post(self.user.username,
            '/slumber/slumber_examples/Pizza/update/%s/' % self.pizza.pk,
            {'name': 'new test pizza'})
        self.assertEqual(response.status_code, 200, response.content)

    def test_model_delete_requires_permission(self):
        response = self.signed_post(self.user.username,
            '/slumber/slumber_examples/Pizza/delete/%s/' % self.pizza.pk, {})
        self.assertEqual(response.status_code, 403)

    def test_model_delete_checks_correct_permission(self):
        permission = Permission.objects.get(codename="delete_pizza")
        self.user.user_permissions.add(permission)
        response = self.signed_post(self.user.username,
            '/slumber/slumber_examples/Pizza/delete/%s/' % self.pizza.pk, {})
        self.assertEqual(response.status_code, 200, response.content)
开发者ID:duisetsuna,项目名称:django-slumber,代码行数:62,代码来源:authentication.py



注:本文中的slumber_examples.models.Pizza类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python extractors.apply_extractors函数代码示例发布时间:2022-05-27
下一篇:
Python ua.get函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap