def test_create_pizza(self):
     response1, json1 = post('/slumber/slumber_examples/Pizza/create/', {
             'id': 1, 'name': 'Test P', 'for_sale': True})
     self.assertEqual(response1.status_code, 200)
     response2, json2 = post('/slumber/slumber_examples/Pizza/create/', {
             'id': 1, 'name': 'Test P', 'for_sale': True})
     self.assertEqual(response2.status_code, 200)
     self.assertEqual(Pizza.objects.all().count(), 1)
    def test_create_pizza_twice(self):
        response1, json1 = post('/slumber/slumber_examples/Pizza/create/', {
                'id': 1, 'name': 'Test P', 'for_sale': True})
        self.assertEqual(response1.status_code, 200)
        self.assertTrue(json1['created'], json1)

        response2, json2 = post('/slumber/slumber_examples/Pizza/create/', {
                'id': 1, 'name': 'Test P', 'for_sale': True})
        self.assertEqual(response2.status_code, 200)
        self.assertFalse(json2['created'], json2)
        self.assertEqual(Pizza.objects.all().count(), 1)
Exemple #3
0
    def test_create_pizza_twice(self):
        response1, json1 = post(
            "/slumber/slumber_examples/Pizza/create/", {"id": 1, "name": "Test P", "for_sale": True}
        )
        self.assertEqual(response1.status_code, 200)
        self.assertTrue(json1["created"], json1)

        response2, json2 = post(
            "/slumber/slumber_examples/Pizza/create/", {"id": 1, "name": "Test P", "for_sale": True}
        )
        self.assertEqual(response2.status_code, 200)
        self.assertFalse(json2["created"], json2)
        self.assertEqual(Pizza.objects.all().count(), 1)
Exemple #4
0
 def test_create_pizza_crust(self):
     response1, json1 = post(
         "/slumber/slumber_examples/PizzaCrust/create/", {"code": "org", "full_name": "original crust"}
     )
     self.assertEqual(response1.status_code, 200)
     self.assertTrue(json1["created"], json1)
     self.assertEqual(PizzaCrust.objects.all().count(), 1)
Exemple #5
0
    def test_fake(self):
        def _post(self, url, data, **kw):
            return _response_fake()

        with patch('slumber.connector.ua.FakeClient.post', _post):
            response, json = post('/local/', {})
        self.assertEqual(json, 123)
Exemple #6
0
 def test_real(self):
     def _request(_self, url, method, body, headers={}):
         self.assertEqual(body, '{"data": 23}')
         return _response_httplib2(), "123"
     with patch('slumber.connector.ua.Http.request', _request):
         response, json = post('http://example.com/', {
             'data': 23})
     self.assertEqual(json, 123)
Exemple #7
0
    def test_real(self):
        def _request(_self, url, method, body, headers={}):
            self.assertEqual(body, '{"data": 23}')
            return _response_httplib2(), "123"

        with patch('slumber.connector.ua.Http.request', _request):
            response, json = post('http://example.com/', {'data': 23})
        self.assertEqual(json, 123)
Exemple #8
0
 def test_create_pizza(self):
     response, json = post("/slumber/slumber_examples/Pizza/create/", {"id": 1, "name": "Test P", "for_sale": True})
     self.assertEqual(response.status_code, 200)
     self.assertTrue(json.has_key("pk"), json)
     self.assertEqual(json["pk"], 1, json)
     self.assertTrue(json.has_key("created"), json)
     self.assertTrue(json["created"], json)
     self.assertEqual(Pizza.objects.all().count(), 1)
 def test_model_operation_with_mock_ua(self, expect):
     expect.get('http://pizzas/app/Model/test-op/', {'test': 'item'})
     expect.post('http://pizzas/app/Model/test-op/', {'test': 'item'}, {'item': 'test'})
     self.assertEqual(len(expect.expectations), 2)
     response1, json1 = get(client.pizzas.app.Model._operations['test-op'])
     self.assertEqual(json1, dict(test='item'))
     response2, json2 = post(client.pizzas.app.Model._operations['test-op'], json1)
     self.assertEqual(json2, dict(item='test'))
 def test_create_pizza(self):
     response, json = post('/slumber/slumber_examples/Pizza/create/', {
         'id': 1, 'name': 'Test P', 'for_sale': True})
     self.assertEqual(response.status_code, 200)
     self.assertTrue(json.has_key('pk'), json)
     self.assertEqual(json['pk'], 1, json)
     self.assertTrue(json.has_key('created'), json)
     self.assertTrue(json['created'], json)
     self.assertEqual(Pizza.objects.all().count(), 1)
 def test_model_operation_with_mock_ua_no_post_data_match(self, expect):
     expect.get('http://pizzas/app/Model/test-op/', {'test': 'item'})
     expect.post('http://pizzas/app/Model/test-op/', None, {'item': 'test'})
     self.assertEqual(len(expect.expectations), 2)
     response1, json1 = get(client.pizzas.app.Model._operations['test-op'])
     self.assertEqual(json1, dict(test='item'))
     response2, json2 = post(client.pizzas.app.Model._operations['test-op'],
                             json1)
     self.assertEqual(json2, dict(item='test'))
 def test_create_pizza_crust(self):
     response1, json1 = post('/slumber/slumber_examples/PizzaCrust/create/',
                             {
                                 'code': 'org',
                                 'full_name': 'original crust'
                             })
     self.assertEqual(response1.status_code, 200)
     self.assertTrue(json1['created'], json1)
     self.assertEqual(PizzaCrust.objects.all().count(), 1)
Exemple #13
0
 def test_create_pizza(self):
     response, json = post('/slumber/slumber_examples/Pizza/create/', {
         'id': 1, 'name': 'Test P', 'for_sale': True})
     self.assertEqual(response.status_code, 200)
     self.assertTrue(json.has_key('pk'), json)
     self.assertEqual(json['pk'], 1, json)
     self.assertTrue(json.has_key('created'), json)
     self.assertTrue(json['created'], json)
     self.assertEqual(Pizza.objects.all().count(), 1)
Exemple #14
0
 def test_update_pizza(self):
     self.cnx = Client()
     p_id, p_sale = 1 , False
     response1, json1 = post('/slumber/slumber_examples/Pizza/create/',{
             'id':p_id, 'name':'Test P', 'for_sale': True})
     self.assertEqual(response1.status_code, 200)
     pizza = self.cnx.slumber_examples.Pizza.get(pk = p_id)
     self.cnx.slumber_examples.Pizza.update(pizza, for_sale = p_sale)
     pizza = self.cnx.slumber_examples.Pizza.get(pk = p_id)
     self.assertEqual(pizza.for_sale, p_sale)
 def test_update_pizza(self):
     self.cnx = Client()
     p_id, p_sale = 1 , False
     response1, json1 = post('/slumber/slumber_examples/Pizza/create/',{
             'id':p_id, 'name':'Test P', 'for_sale': True})
     self.assertEqual(response1.status_code, 200)
     pizza = self.cnx.slumber_examples.Pizza.get(pk = p_id)
     self.cnx.slumber_examples.Pizza.update(pizza, for_sale = p_sale)
     pizza = self.cnx.slumber_examples.Pizza.get(pk = p_id)
     self.assertEqual(pizza.for_sale, p_sale)
Exemple #16
0
 def test_update_pizza(self):
     self.cnx = Client()
     p_id, p_sale = 1, False
     response1, json1 = post(
         "/slumber/slumber_examples/Pizza/create/", {"id": p_id, "name": "Test P", "for_sale": True}
     )
     self.assertEqual(response1.status_code, 200)
     pizza = self.cnx.slumber_examples.Pizza.get(pk=p_id)
     self.cnx.slumber_examples.Pizza.update(pizza, for_sale=p_sale)
     pizza = self.cnx.slumber_examples.Pizza.get(pk=p_id)
     self.assertEqual(pizza.for_sale, p_sale)
Exemple #17
0
 def authenticate(self, **kwargs):
     """Allow a forwarded request for authentication.
     """
     # We're accessing attributes that are provided by the  other types
     # pylint: disable = E1101
     _, json = post(self._operations['authenticate'], kwargs)
     if json['authenticated']:
         # Pylint can't see the __call__ implemented in another base class
         # pylint: disable = E1102
         remote_user = self(urljoin(self._url, json['user']['url']),
                            json['user']['display_name'])
         return attach_to_local_user(remote_user)
Exemple #18
0
 def authenticate(self, **kwargs):
     """Allow a forwarded request for authentication.
     """
     # We're accessing attributes that are provided by the  other types
     # pylint: disable = E1101
     _, json = post(self._operations['authenticate'], kwargs)
     if json['authenticated']:
         # Pylint can't see the __call__ implemented in another base class
         # pylint: disable = E1102
         remote_user = self(urljoin(self._url, json['user']['url']),
             json['user']['display_name'])
         return attach_to_local_user(remote_user)
Exemple #19
0
 def create(self, **kwargs):
     """Implements the client side for the model `create` operator.
     """
     url = urljoin(self._url, self._operations['create'])
     _, json = post(url, kwargs)
     return get_instance_from_data(url, json)
Exemple #20
0
 def test_no_post_expectation(self, expect):
     post('/', {})
Exemple #21
0
 def test_no_expectated_get_got_post(self, expect):
     expect.get('/', {})
     post('/', {})
Exemple #22
0
 def test_404_allowed_for_fake(self):
     response, json = post('/slumber/does-not-exist/', {}, [404])
     self.assertEqual(response.status_code, 404)
Exemple #23
0
 def test_expect_wrong_post_data(self, expect):
     expect.post('/', {'data': True}, {})
     post('/', {'data': False})
 def test_expect_wrong_post_data(self, expect):
     expect.post('/', {'data': True}, {})
     post('/', {'data': False})
Exemple #25
0
 def test_fake(self):
     def _post(self, url, data, **kw):
         return _response_fake()
     with patch('slumber.connector.ua.FakeClient.post', _post):
         response, json = post('/local/', {})
     self.assertEqual(json, 123)
 def test_no_post_expectation(self, expect):
     post('/', {})
 def test_no_expectated_get_got_post(self, expect):
     expect.get('/', {})
     post('/', {})
Exemple #28
0
 def create(self, **kwargs):
     """Implements the client side for the model `create` operator.
     """
     url = urljoin(self._url, self._operations['create'])
     _, json = post(url, kwargs)
     return get_instance_from_data(url, json)
Exemple #29
0
 def test_404_allowed_for_fake(self):
     response, json = post('/slumber/does-not-exist/', {}, [404])
     self.assertEqual(response.status_code, 404)
Exemple #30
0
 def do_post():
     with patch('slumber.connector.ua._calculate_signature',
                self.signature_with_username):
         post('/slumber/', {})
Exemple #31
0
 def update(self, instance_connector, **kwargs):
     """Implements the client side for the model 'update' operator.
     """
     url = urljoin(self._url, instance_connector._operations['update'])
     _, json = post(url, kwargs)
     return json
Exemple #32
0
 def update(self, instance_connector, **kwargs):
     """Implements the client side for the model 'update' operator.
     """
     url = urljoin(self._url, instance_connector._operations['update'])
     _, json = post(url, kwargs)
     return json
Exemple #33
0
 def test_create_pizza_crust(self):
     response1, json1 = post('/slumber/slumber_examples/PizzaCrust/create/', {
             'code': 'org', 'full_name': 'original crust'})
     self.assertEqual(response1.status_code, 200)
     self.assertTrue(json1['created'], json1)
     self.assertEqual(PizzaCrust.objects.all().count(), 1)
Exemple #34
0
 def do_post():
     with patch('slumber.connector.ua._calculate_signature',
             self.signature_with_username):
         post('/slumber/', {})