Weird failure behavior with TestCase for payment app ?

7 views
Skip to first unread message

Darren Hollenbeck

unread,
May 17, 2012, 4:31:18 PM5/17/12
to satchmo-d...@googlegroups.com
In the minimum order test case for the payment app, I am getting a failure when testing under my development store setup. What's weird is that the assertion failure will happen in different spots (2 of them), but putting a pdb trace point in and stepping through the test case code results in success. I suspect there's some kind of timing thing going on where some of the transactions are not occurring before the next assertion test is done, thus causing a failure. I cannot reproduce this when using a fresh demo/skeleton store setup (clonesatchmo).

Error text and trace point insertion below...

Sometimes this one:
Creating test database for alias 'default'...
Skipping creation of NoticeTypes as notification app not found
F.........
======================================================================
FAIL: test_checkout_minimums (payment.tests.TestMinimumOrder)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/Satchmo-0.9.3-py2.6.egg/payment/tests.py", line 184, in test_checkout_minimums
    self.assertContains(response, "Billing Information", count=1, status_code=200)
  File "/usr/lib/python2.6/site-packages/django/test/testcases.py", line 427, in assertContains
    " (expected %d)" % (real_count, text, count))
AssertionError: 0 != 1 : Found 0 instances of 'Billing Information' in response (expected 1)
----------------------------------------------------------------------
Ran 10 tests in 9.917s
FAILED (failures=1)
Destroying test database for alias 'default'...

Other times I get this:
Creating test database for alias 'default'...
Skipping creation of NoticeTypes as notification app not found
F.........
======================================================================
FAIL: test_checkout_minimums (payment.tests.TestMinimumOrder)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/Satchmo-0.9.3-py2.6.egg/payment/tests.py", line 174, in test_checkout_minimums
    self.assertContains(response, "This store requires a minimum order", count=1, status_code=200)
  File "/usr/lib/python2.6/site-packages/django/test/testcases.py", line 427, in assertContains
    " (expected %d)" % (real_count, text, count))
AssertionError: 0 != 1 : Found 0 instances of 'This store requires a minimum order' in response (expected 1)
----------------------------------------------------------------------
Ran 10 tests in 9.576s
FAILED (failures=1)
Destroying test database for alias 'default'...


TestCase code:
class TestMinimumOrder(TestCase):
    fixtures = ['l10n-data.yaml', 'sample-store-data.yaml', 'products.yaml', 'test-config.yaml']

    def setUp(self):
        # Every test needs a client
        self.client = Client()
        self.old_language_code = settings.LANGUAGE_CODE
        settings.LANGUAGE_CODE = 'en-us'

    def tearDown(self):
        keyedcache.cache_delete()
        settings.LANGUAGE_CODE = self.old_language_code

    def test_checkout_minimums(self):
        """
        Validate we can add some items to the cart
        """
        min_order = config_get('PAYMENT', 'MINIMUM_ORDER')

        #start with no min.
        min_order.update("0.00")
        producturl = urlresolvers.reverse("satchmo_product", kwargs={'product_slug' : 'dj-rocks'})
        response = self.client.get(producturl)
        self.assertContains(response, "Django Rocks shirt", count=2, status_code=200)
        cartadd = urlresolvers.reverse('satchmo_cart_add')
        response = self.client.post(cartadd, { "productname" : "dj-rocks",
                                                      "1" : "L",
                                                      "2" : "BL",
                                                      "quantity" : '2'})
        carturl = urlresolvers.reverse('satchmo_cart')
        self.assertRedirects(response, carturl,
            status_code=302, target_status_code=200)
        response = self.client.get(carturl)
        self.assertContains(response, "Django Rocks shirt (Large/Blue)", count=1, status_code=200)
        response = self.client.get(url('satchmo_checkout-step1'))
        self.assertContains(response, "Billing Information", count=1, status_code=200)

        # now check for min order not met
        min_order.update("100.00")
        response = self.client.get(url('satchmo_checkout-step1'))

        import pdb; pdb.set_trace()

        self.assertContains(response, "This store requires a minimum order", count=1, status_code=200)

        # add a bunch of shirts, to make the min order
        response = self.client.post(cartadd, { "productname" : "dj-rocks",
                                                      "1" : "L",
                                                      "2" : "BL",
                                                      "quantity" : '10'})
        self.assertRedirects(response, carturl,
            status_code=302, target_status_code=200)
        response = self.client.get(url('satchmo_checkout-step1'))
        self.assertContains(response, "Billing Information", count=1, status_code=200)

Reply all
Reply to author
Forward
0 new messages