def test_instance_data_array(self): s = Pizza(name='P', for_sale=True) s.save() for p in range(15): PizzaPrice(pizza=s, amount=str(p), date='2011-04-%s' % (p + 1)).save() response, json = self.do_get( '/slumber/slumber_test/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'], '/slumber/slumber_test/Pizza/data/1/prices/?start_after=6', json['next_page']) response, json = self.do_get( '/slumber/slumber_test/Pizza/data/1/prices/', {'start_after': '6'}) self.assertEquals(response.status_code, 200) self.assertEquals(len(json['page']), 5) self.assertEquals( json['next_page'], '/slumber/slumber_test/Pizza/data/1/prices/?start_after=1') response, json = self.do_get( '/slumber/slumber_test/Pizza/data/1/prices/', {'start_after': '1'}) self.assertEquals(response.status_code, 200) self.assertEquals(len(json['page']), 0) self.assertFalse(json.has_key('next_page'))
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/slumber_test/Pizza/instances/') self.assertEquals(response.status_code, 200) self.assertEquals(len(json['page']), 10) self.assertEquals( json['next_page'], '/slumber/slumber_test/Pizza/instances/?start_after=3') response, json = self.do_get('/slumber/slumber_test/Pizza/instances/', {'start_after': '3'}) self.assertEquals(response.status_code, 200) self.assertEquals(len(json['page']), 2) self.assertEquals( json['next_page'], '/slumber/slumber_test/Pizza/instances/?start_after=1') response, json = self.do_get('/slumber/slumber_test/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)
def test_instance_data(self): s = Pizza(name='S1', for_sale=True) s.save() response, json = self.do_get('/slumber/slumber_test/Pizza/data/%s/' % s.pk) self.maxDiff = None self.assertEquals( json, dict(fields=dict( id=dict(data=s.pk, type='django.db.models.fields.AutoField'), for_sale=dict(data=s.for_sale, type='django.db.models.fields.BooleanField'), max_extra_toppings=dict( data=s.max_extra_toppings, type='django.db.models.fields.IntegerField'), name=dict(data=s.name, type='django.db.models.fields.CharField')), display='S1', data_arrays=dict( prices='/slumber/slumber_test/Pizza/data/%s/prices/' % s.pk)))
def test_instance_data(self): s = Pizza(name='S1', for_sale=True) s.save() client = Client('localhost:8003', '/slumber') pizza = client.slumber_test.Pizza.get(pk=s.pk) self.assertEqual('S1', pizza.name)
def test_model_operation_instances_one_instance(self): Pizza(name='S1', for_sale=True).save() response, json = self.do_get('/slumber/slumber_test/Pizza/instances/') self.assertEquals(response.status_code, 200) self.assertEquals(len(json['page']), 1)