Exemplo n.º 1
0
    def test_get_coupon_info(self):
        """
        Test Edit Coupon Info Scenarios. Handle all the HttpResponses return by edit_coupon_info view
        """
        coupon = Coupon(
            code='AS452', description='asdsadsa', course_id=self.course.id.to_deprecated_string(),
            percentage_discount=10, created_by=self.instructor
        )
        coupon.save()
        # URL for edit_coupon_info
        edit_url = reverse('get_coupon_info', kwargs={'course_id': self.course.id.to_deprecated_string()})
        response = self.client.post(edit_url, {'id': coupon.id})
        self.assertTrue('coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id) in response.content)

        response = self.client.post(edit_url, {'id': 444444})
        self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=444444) in response.content)

        response = self.client.post(edit_url, {'id': ''})
        self.assertTrue('coupon id not found"' in response.content)

        coupon.is_active = False
        coupon.save()

        response = self.client.post(edit_url, {'id': coupon.id})
        self.assertTrue("coupon with the coupon id ({coupon_id}) is already inactive".format(coupon_id=coupon.id) in response.content)
Exemplo n.º 2
0
    def test_delete_coupon(self):
        """
        Test Delete Coupon Scenarios. Handle all the HttpResponses return by remove_coupon view
        """
        coupon = Coupon(
            code='AS452', description='asdsadsa', course_id=self.course.id.to_deprecated_string(),
            percentage_discount=10, created_by=self.instructor
        )

        coupon.save()

        response = self.client.post(self.url)
        self.assertTrue('<td>AS452</td>' in response.content)

        # URL for remove_coupon
        delete_coupon_url = reverse('remove_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()})
        response = self.client.post(delete_coupon_url, {'id': coupon.id})
        self.assertTrue('coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id) in response.content)

        coupon.is_active = False
        coupon.save()

        response = self.client.post(delete_coupon_url, {'id': coupon.id})
        self.assertTrue('coupon with the coupon id ({coupon_id}) is already inactive'.format(coupon_id=coupon.id) in response.content)

        response = self.client.post(delete_coupon_url, {'id': 24454})
        self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=24454) in response.content)

        response = self.client.post(delete_coupon_url, {'id': ''})
        self.assertTrue('coupon id is None' in response.content)
Exemplo n.º 3
0
    def test_get_coupon_info(self):
        """
        Test Edit Coupon Info Scenarios. Handle all the HttpResponses return by edit_coupon_info view
        """
        coupon = Coupon(code='AS452',
                        description='asdsadsa',
                        course_id=self.course.id.to_deprecated_string(),
                        percentage_discount=10,
                        created_by=self.instructor)
        coupon.save()
        # URL for edit_coupon_info
        edit_url = reverse(
            'get_coupon_info',
            kwargs={'course_id': self.course.id.to_deprecated_string()})
        response = self.client.post(edit_url, {'id': coupon.id})
        self.assertTrue(
            'coupon with the coupon id ({coupon_id}) updated successfully'.
            format(coupon_id=coupon.id) in response.content)

        response = self.client.post(edit_url, {'id': 444444})
        self.assertTrue(
            'coupon with the coupon id ({coupon_id}) DoesNotExist'.format(
                coupon_id=444444) in response.content)

        response = self.client.post(edit_url, {'id': ''})
        self.assertTrue('coupon id not found"' in response.content)

        coupon.is_active = False
        coupon.save()

        response = self.client.post(edit_url, {'id': coupon.id})
        self.assertTrue(
            "coupon with the coupon id ({coupon_id}) is already inactive".
            format(coupon_id=coupon.id) in response.content)
Exemplo n.º 4
0
    def test_delete_coupon(self):
        """
        Test Delete Coupon Scenarios. Handle all the HttpResponses return by remove_coupon view
        """
        coupon = Coupon(
            code='AS452', description='asdsadsa', course_id=self.course.id.to_deprecated_string(),
            percentage_discount=10, created_by=self.instructor
        )

        coupon.save()

        response = self.client.post(self.url)
        self.assertTrue('<td>AS452</td>' in response.content)

        # URL for remove_coupon
        delete_coupon_url = reverse('remove_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()})
        response = self.client.post(delete_coupon_url, {'id': coupon.id})
        self.assertTrue('coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id) in response.content)

        coupon.is_active = False
        coupon.save()

        response = self.client.post(delete_coupon_url, {'id': coupon.id})
        self.assertTrue('coupon with the coupon id ({coupon_id}) is already inactive'.format(coupon_id=coupon.id) in response.content)

        response = self.client.post(delete_coupon_url, {'id': 24454})
        self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=24454) in response.content)

        response = self.client.post(delete_coupon_url, {'id': ''})
        self.assertTrue('coupon id is None' in response.content)
Exemplo n.º 5
0
    def test_get_coupon_info(self):
        """
        Test Edit Coupon Info Scenarios. Handle all the HttpResponses return by edit_coupon_info view
        """
        coupon = Coupon(code='AS452',
                        description='asdsadsa',
                        course_id=text_type(self.course.id),
                        percentage_discount=10,
                        created_by=self.instructor,
                        expiration_date=datetime.datetime.now(pytz.UTC) +
                        datetime.timedelta(days=2))
        coupon.save()
        # URL for edit_coupon_info
        edit_url = reverse('get_coupon_info',
                           kwargs={'course_id': text_type(self.course.id)})
        response = self.client.post(edit_url, {'id': coupon.id})
        self.assertContains(
            response,
            u'coupon with the coupon id ({coupon_id}) updated successfully'.
            format(coupon_id=coupon.id),
        )
        self.assertContains(response, coupon.display_expiry_date)

        response = self.client.post(edit_url, {'id': 444444})
        self.assertContains(
            response,
            u'coupon with the coupon id ({coupon_id}) DoesNotExist'.format(
                coupon_id=444444),
            status_code=400,
        )

        response = self.client.post(edit_url, {'id': ''})
        self.assertContains(response, 'coupon id not found"', status_code=400)

        coupon.is_active = False
        coupon.save()

        response = self.client.post(edit_url, {'id': coupon.id})
        self.assertContains(
            response,
            u"coupon with the coupon id ({coupon_id}) is already inactive".
            format(coupon_id=coupon.id),
            status_code=400,
        )
Exemplo n.º 6
0
    def test_get_coupon_info(self):
        """
        Test Edit Coupon Info Scenarios. Handle all the HttpResponses return by edit_coupon_info view
        """
        coupon = Coupon(
            code="AS452",
            description="asdsadsa",
            course_id=self.course.id.to_deprecated_string(),
            percentage_discount=10,
            created_by=self.instructor,
            expiration_date=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=2),
        )
        coupon.save()
        # URL for edit_coupon_info
        edit_url = reverse("get_coupon_info", kwargs={"course_id": self.course.id.to_deprecated_string()})
        response = self.client.post(edit_url, {"id": coupon.id})
        self.assertTrue(
            "coupon with the coupon id ({coupon_id}) updated successfully".format(coupon_id=coupon.id)
            in response.content
        )
        self.assertIn(coupon.display_expiry_date, response.content)

        response = self.client.post(edit_url, {"id": 444444})
        self.assertTrue(
            "coupon with the coupon id ({coupon_id}) DoesNotExist".format(coupon_id=444444) in response.content
        )

        response = self.client.post(edit_url, {"id": ""})
        self.assertTrue('coupon id not found"' in response.content)

        coupon.is_active = False
        coupon.save()

        response = self.client.post(edit_url, {"id": coupon.id})
        self.assertTrue(
            "coupon with the coupon id ({coupon_id}) is already inactive".format(coupon_id=coupon.id)
            in response.content
        )
Exemplo n.º 7
0
    def test_get_coupon_info(self):
        """
        Test Edit Coupon Info Scenarios. Handle all the HttpResponses return by edit_coupon_info view
        """
        coupon = Coupon(
            code='AS452', description='asdsadsa', course_id=text_type(self.course.id),
            percentage_discount=10, created_by=self.instructor,
            expiration_date=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=2)
        )
        coupon.save()
        # URL for edit_coupon_info
        edit_url = reverse('get_coupon_info', kwargs={'course_id': text_type(self.course.id)})
        response = self.client.post(edit_url, {'id': coupon.id})
        self.assertIn(
            'coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id),
            response.content
        )
        self.assertIn(coupon.display_expiry_date, response.content)

        response = self.client.post(edit_url, {'id': 444444})
        self.assertIn(
            'coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=444444),
            response.content
        )

        response = self.client.post(edit_url, {'id': ''})
        self.assertIn('coupon id not found"', response.content)

        coupon.is_active = False
        coupon.save()

        response = self.client.post(edit_url, {'id': coupon.id})
        self.assertIn(
            "coupon with the coupon id ({coupon_id}) is already inactive".format(coupon_id=coupon.id),
            response.content
        )