kriwil
9/29/2014 - 7:41 AM

test.py

class CreatePaymentTest(TestCase):

    def setUp(self):
        self.user = UserFactory()
        self.payment = PaymentFactory()
        self.product = ProductFactory()
        self.url = reverse('api:create-payment')
        self.headers = get_auth_header(self.user)

    def test_post_new(self):
        UserFactory()
        ProductFactory()
        # list_product = [{"product": 1, "item_count": 10, "month_subscription": 5}]
        list_product = [{'product': 1, 'item_count': 10, 'month_subscription': 5}]
        post_data = {
            "user": self.user.id,
            "payment_type": 'manual',
            "total": '0',
            "list_product": list_product
        }

        response = self.client.post(self.url, json.dumps(post_data), content_type='application/json', **self.headers)
        self.assertEqual(response.status_code, 201)