Example #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)
Example #2
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)
Example #3
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)
Example #4
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)
Example #5
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.assertEquals(form.as_p(),
         '''<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>''')
Example #6
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>''')
Example #7
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/shop/1/" """
         """id="id_shop" /></p>""",
     )
Example #8
0
 def test_model_form_with_order_from_database(self):
     shop = self.client.pizzas.slumber_examples.Shop.create(
         name='Shop', slug='shop')
     order = Order(shop=shop)
     order.save()
     order_db = Order.objects.get(pk=order.pk)
     form = WidgetTest.ModelForm(instance=order_db)
     self.sameSoup(form,
         '''<p><label for="id_shop">Shop:</label> '''
             '''<input type="text" name="shop" '''
                 '''value="http://localhost:8000/slumber/pizzas/shop/1/" '''
                 '''id="id_shop" /></p>''')
Example #9
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)
Example #10
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)
Example #11
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)
Example #12
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/slumber_examples/Shop/data/%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)
Example #13
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)
Example #14
0
class TestMockWithDatabase(ServiceTestsWithDirectory, django.test.TestCase):
    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)

    @mock_client(pizzas__slumber_examples__Shop = [
        dict(pk=1)
    ])
    def test_can_order_with_remote_shop_mock(self):
        self._setup()
        fetched = Order.objects.get(shop=self.shop)
        self.assertEqual(self.order, fetched)

    @mock_client(pizzas__slumber_examples__Shop = [
        dict(pk=1)
    ])
    def test_can_order_with_remote_shop_url(self):
        self._setup()
        fetched = Order.objects.get(
            shop='slumber://pizzas/slumber_examples/Shop/data/1/')
        self.assertEqual(self.order, fetched)

    @mock_client(pizzas__slumber_examples__Shop = [
        dict(pk=1, slug='test-shop-1')
    ])
    def test_order_shop_finds_mock(self):
        self._setup()
        self.assertEqual(self.order.shop.pk, 1)
        self.assertEqual(self.order.shop.slug, 'test-shop-1')

    @mock_client(pizzas__django__contrib__auth__User=[{
            'pk': 1, 'id': 1, 'username': '******',
                'is_active': True, 'is_staff': False, 'is_superuser': False,
                'date_joined': date(2011, 05, 23),
                'first_name': 'test1', 'last_name': 'user', 'email': '*****@*****.**'
        }, {
            'pk': 2, 'id': 2, 'username': '******',
                'is_active': True, 'is_staff': False, 'is_superuser': False,
                'date_joined': date(2011, 05, 23),
                'first_name': 'test2', 'last_name': 'user', 'email': '*****@*****.**'
        }])
Example #15
0
class TestMockWithDatabase(ServiceTestsWithDirectory, django.test.TestCase):
    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)

    @mock_client(pizzas__slumber_examples__Shop=[dict(pk=1)])
    def test_can_order_with_remote_shop_mock(self):
        self._setup()
        fetched = Order.objects.get(shop=self.shop)
        self.assertEqual(self.order, fetched)

    @mock_client(pizzas__slumber_examples__Shop=[dict(pk=1)])
    def test_can_order_with_remote_shop_url(self):
        self._setup()
        fetched = Order.objects.get(
            shop='slumber://pizzas/slumber_examples/Shop/data/1/')
        self.assertEqual(self.order, fetched)

    @mock_client(
        pizzas__slumber_examples__Shop=[dict(pk=1, slug='test-shop-1')])
    def test_order_shop_finds_mock(self):
        self._setup()
        self.assertEqual(self.order.shop.pk, 1)
        self.assertEqual(self.order.shop.slug, 'test-shop-1')

    @mock_client(pizzas__django__contrib__auth__User=[{
        'pk':
        1,
        'id':
        1,
        'username':
        '******',
        'is_active':
        True,
        'is_staff':
        False,
        'is_superuser':
        False,
        'date_joined':
        date(2011, 05, 23),
        'first_name':
        'test1',
        'last_name':
        'user',
        'email':
        '*****@*****.**'
    }, {
        'pk':
        2,
        'id':
        2,
        'username':
        '******',
        'is_active':
        True,
        'is_staff':
        False,
        'is_superuser':
        False,
        'date_joined':
        date(2011, 05, 23),
        'first_name':
        'test2',
        'last_name':
        'user',
        'email':
        '*****@*****.**'
    }])