test_configure_commerce.py 2.01 KB
Newer Older
1 2 3 4
"""
Tests for management command for enabling commerce configuration.
"""
from django.core.management import call_command
5
from django.test import TestCase
6

7
from ....models import CommerceConfiguration
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58


class TestCommerceConfigurationCommand(TestCase):
    """
    Test django management command for enabling commerce configuration.
    """
    def test_commerce_configuration(self):
        """
        Test that commerce configuration is created properly.
        """
        call_command(
            "configure_commerce",
        )

        # Verify commerce configuration is enabled with appropriate values
        commerce_configuration = CommerceConfiguration.current()

        self.assertTrue(commerce_configuration.enabled)
        self.assertTrue(commerce_configuration.checkout_on_ecommerce_service)
        self.assertEqual(commerce_configuration.single_course_checkout_page, "/basket/single-item/")
        self.assertEqual(commerce_configuration.cache_ttl, 0)

        # Verify commerce configuration can be disabled from command
        call_command(
            "configure_commerce",
            '--disable',
        )

        commerce_configuration = CommerceConfiguration.current()
        self.assertFalse(commerce_configuration.enabled)

        # Verify commerce configuration can be disabled from command
        call_command(
            "configure_commerce",
            '--disable-checkout-on-ecommerce',
        )

        commerce_configuration = CommerceConfiguration.current()
        self.assertFalse(commerce_configuration.checkout_on_ecommerce_service)

    def test_site_associated_commerce_configuration(self):
        """
        This test is added here to fail when site_id field is added.

        This is done to make sure that this command gets updated once site_id field is added to
        CommerceConfiguration model.
        """
        self.assertFalse(
            hasattr(CommerceConfiguration, "site"),
            "Update configure_commerce command to account for site specific configurations.",
        )