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="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)
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)
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_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)