Exemplo n.º 1
0
 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': '******'},
         type=self.url('/slumber_examples/PizzaPrice/'),
         identity=self.url('/slumber_examples/PizzaPrice/data/1/'),
         display="p1 2010-01-01",
         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)
Exemplo n.º 2
0
 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())
Exemplo n.º 3
0
 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': '******'},
         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)
Exemplo n.º 4
0
 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")
Exemplo n.º 5
0
 def test_delete_instance_with_post(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)
Exemplo n.º 6
0
 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})
Exemplo n.º 7
0
 def test_model_operation_instances_twelve_instances(self):
     for i in range(12):
         Pizza(name='S%s' % i, for_sale=True).save()
     response, json = self.do_get('/slumber_examples/Pizza/instances/')
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(json['page']), 10)
     self.assertEquals(json['next_page'],
         self.url('/slumber_examples/Pizza/instances/?start_after=3'))
     response, json = self.do_get('/slumber_examples/Pizza/instances/',
         {'start_after': '3'})
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(json['page']), 2)
     self.assertEquals(json['next_page'],
         self.url('/slumber_examples/Pizza/instances/?start_after=1'))
     response, json = self.do_get('/slumber_examples/Pizza/instances/',
         {'start_after': '1'})
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(json['page']), 0)
     self.assertFalse(json.has_key('next_page'), json)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 def setUp(self):
     super(OrderTests, self).setUp()
     self.pizza = Pizza(name='S1', for_sale=True)
     self.pizza.save()
     self.cnx = Client()
Exemplo n.º 10
0
 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())
Exemplo n.º 11
0
 def test_model_operation_instances_one_instance(self):
     Pizza(name='S1', for_sale=True).save()
     response, json = self.do_get('/slumber_examples/Pizza/instances/')
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(json['page']), 1)
Exemplo n.º 12
0
 def setUp(self):
     self.pizza = Pizza(name='Before change')
     self.pizza.save()
     super(TestAuthnRequired, self).setUp()