Ejemplo n.º 1
0
 def _setup(self):
     # Can't use setUp as that runs before the mock is applied
     self.shop = client.pizzas.slumber_examples.Shop.get(pk=1)
     self.order = Order(shop=self.shop)
     self.order.save()
     for order in Order.objects.all():
         logging.debug(order.shop)
Ejemplo n.º 2
0
 def test_instance_data_order(self):
     shop = Shop(name="Home", slug='home', active=True)
     shop.save()
     order = Order(shop=self.url("/slumber_examples/Shop/data/%s/" % shop.pk))
     order.save()
     response, json = self.do_get('/slumber_examples/Order/data/%s/' % order.pk)
     self.assertEquals(response.status_code, 200)
     expected = dict(
         _meta={'message': 'OK', 'status': 200, 'username': '******'},
         type=self.url('/slumber_examples/Order/'),
         identity=self.url('/slumber_examples/Order/data/1/'),
         display="Order object",
         operations=dict(
             data=self.url('/slumber_examples/Order/data/1/'),
             delete=self.url('/slumber_examples/Order/delete/1/'),
             update=self.url('/slumber_examples/Order/update/1/')),
         fields=dict(
             id={'data': 1, 'kind': 'value', 'type': 'django.db.models.fields.AutoField'},
             nested={'data': None,
                     'kind': 'value',
                     'type': 'slumber.fields.RemoteForeignKey'},
             shop={'data': self.url('/slumber_examples/Shop/data/%s/' % shop.pk),
                   'kind': 'value',
                   'type': 'slumber.fields.RemoteForeignKey'}
         ),
         data_arrays={})
     self.assertEquals(json, expected)
Ejemplo n.º 3
0
 def test_find_order_by_shop_remote_instance(self):
     with patch('slumber._client', Client()):
         shop = client.pizzas.slumber_examples.Shop.get(pk=1)
         order = Order(shop=shop)
         order.save()
         fetched = Order.objects.get(shop=shop)
         self.assertEqual(order, fetched)
Ejemplo n.º 4
0
 def test_model_form_with_order(self):
     shop = self.client.pizzas.slumber_examples.Shop.create(name='Shop',
                                                            slug='shop')
     order = Order(shop=shop)
     order.save()
     form = WidgetTest.ModelForm(instance=order)
     self.sameSoup(
         form, '''<p><label for="id_shop">Shop:</label> '''
         '''<input type="text" name="shop" '''
         '''value="http://localhost:8000/slumber/pizzas/slumber_examples/Shop/data/1/" '''
         '''id="id_shop" /></p>''')
Ejemplo n.º 5
0
 def test_service_configuration_missing_for_remoteforeignkey(self):
     self.user.is_superuser = True
     self.user.save()
     client = Client()
     shop = client.slumber_examples.Shop.create(name="Home", slug='home')
     order = Order(shop=shop)
     order.save()
     self.assertIsNotNone(order.shop)
     cursor = connection.cursor()
     cursor.execute("SELECT shop FROM slumber_examples_order WHERE id=%s",
                    [order.pk])
     row = cursor.fetchone()
     self.assertEquals(row[0], order.shop._url)
     with self.assertRaises(SlumberServiceURLError):
         order2 = Order.objects.get(pk=order.pk)
Ejemplo n.º 6
0
 def test_service_configuration_works_for_remoteforeignkey(self):
     self.user.is_superuser = True
     self.user.save()
     client = Client()
     shop = client.pizzas.slumber_examples.Shop.create(name="Home", slug='home')
     order = Order(shop=shop)
     order.save()
     cursor = connection.cursor()
     cursor.execute(
         "SELECT shop FROM slumber_examples_order WHERE id=%s",
         [order.pk])
     row = cursor.fetchone()
     self.assertEquals(row[0],
         'slumber://pizzas/shop/%s/' % shop.id)
     order2 = Order.objects.get(pk=order.pk)
     self.assertEquals(unicode(order2.shop), unicode(order.shop))
     self.assertEquals(order2.shop.id, order.shop.id)