Exemplo n.º 1
0
    def test_complete(self):
        """Test is complete timestamp is updated"""
        request = self.factory.post('api/order/cart/update_status/', {
            '_id': str(self.cart3._id),
            'status': 'cmt'
        },
                                    content_type='application/json')

        time = self.time

        # setup mock
        mock = MockModule(models.timezone, mockdatetime(time))
        models.timezone = mock.mock()

        # setup actual, expected with mocked views
        response = view_response.update_status_page(request)
        actual = json.loads(response.content)
        expected = json.loads(
            json.dumps(model_to_dict(self.cart3), cls=BSONEncoder))
        expected['complete_tstmp'] = self.time_str

        # undo
        models.timezone = mock.undo()

        self.assertDictEqual(expected, actual)
Exemplo n.º 2
0
    def test_order_fail(self):
        """Test is appropriate error response is sent upon invalid order"""
        request = self.factory.post('api/order/cart/update_status/', {
            '_id': str(self.cart1._id),
            'status': 'cmt'
        },
                                    content_type='application/json')

        actual = view_response.update_status_page(request).content.decode(
            "utf-8")
        self.assertEqual(str(actual), 'Could not complete order')
Exemplo n.º 3
0
    def test_invalid_form(self):
        """Test if appropriate error response is sent upon invalid status"""
        request = self.factory.post('api/order/cart/update_status/', {
            '_id': str(self.cart1._id),
            'status': 'cmweft'
        },
                                    content_type='application/json')

        actual = view_response.update_status_page(request).content.decode(
            "utf-8")
        self.assertEqual(str(actual),
                         'Invalid request, please check your request')