openedx / openedx/openedx-platform

[Flaky test] `lms/djangoapps/email_marketing/tests/test_signals.py::SailthruTests::test_update_course_enrollment`

Open
#36,015 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

flaky-test
Dominant language
Python
Stars
8.2k
Forks
4.4k
Avg merge
6d 18h
Merged PRs (30d)
42

Description

This test fails intermittently and has been deleted according to the Flaky Test Process in https://github.com/openedx/edx-platform/pull/23075

See docs on how to address flaky tests for why this should be fixed and how to go about it.

Failure output:

Run Tests / lms-unit / lms.djangoapps.email_marketing.tests.test_signals.SailthruTests.test_update_course_enrollment (from pytest)

Failing for the past 1 build (Since Failed#14380 )
Took 25 ms.
Error Message
AssertionError: expected call not found. Expected: purchase('test@edx.org', [{'id': 'edX/toy/2012_Fall-audit', 'url': 'http://lms.testserver.fake/courses/edX/toy/2012_Fall/info', 'price': 0, 'vars': {'course_run_id': 'edX/toy/2012_Fall', 'mode': 'audit'}, 'title': 'Course edX/toy/2012_Fall mode: audit', 'qty': 1}], options={}) Actual: purchase('test@edx.org', [{'id': 'edX/toy/2012_Fall-audit', 'url': 'http://lms.testserver.fake/courses/edX/toy/2012_Fall/info', 'price': 0, 'vars': {'course_run_id': 'edX/toy/2012_Fall', 'mode': 'audit'}, 'title': 'Course edX/toy/2012_Fall mode: audit', 'qty': 1}], options={'send_template': 'enroll_template'})
Stacktrace
self = <test_signals.SailthruTests testMethod=test_update_course_enrollment>
mock_sailthru_api_post = <MagicMock name='api_post' id='140687767418192'>
mock_sailthru_api_get = <MagicMock name='api_get' id='140687827763384'>
mock_sailthru_purchase = <MagicMock name='purchase' id='140687763071160'>

    @patch('sailthru.sailthru_client.SailthruClient.purchase')
    @patch('sailthru.sailthru_client.SailthruClient.api_get')
    @patch('sailthru.sailthru_client.SailthruClient.api_post')
    def test_update_course_enrollment(self, mock_sailthru_api_post,
                                      mock_sailthru_api_get, mock_sailthru_purchase):
        """test update sailthru user record"""
    
        # create mocked Sailthru API responses
        mock_sailthru_api_post.return_value = MockSailthruResponse({'ok': True})
        mock_sailthru_api_get.return_value = MockSailthruResponse({'user': {"id": TEST_EMAIL, "fields": {"vars": 1}}})
        mock_sailthru_purchase.return_value = MockSailthruResponse({'ok': True})
        self.user.email = TEST_EMAIL
        CourseEnrollmentFactory(user=self.user, course_id=self.course_id)
        with patch('email_marketing.tasks.build_course_url') as m:
            m.return_value = self.course_url
            update_course_enrollment(TEST_EMAIL, self.course_id, 'audit')
        item = [{
            'vars': {'course_run_id': u'edX/toy/2012_Fall', 'mode': 'audit'},
            'url': self.course_url,
            'price': 0,
            'qty': 1,
            'id': 'edX/toy/2012_Fall-audit',
            'title': 'Course edX/toy/2012_Fall mode: audit'
        }]
>       mock_sailthru_purchase.assert_called_with(TEST_EMAIL, item, options={})

lms/djangoapps/email_marketing/tests/test_signals.py:644: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../edx-venv-3.5/edx-venv/lib/python3.5/site-packages/mock/mock.py:944: in assert_called_with
    six.raise_from(AssertionError(_error_message(cause)), cause)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

value = None, from_value = None

>   ???
E   AssertionError: expected call not found.
E   Expected: purchase('test@edx.org', [{'id': 'edX/toy/2012_Fall-audit', 'url': 'http://lms.testserver.fake/courses/edX/toy/2012_Fall/info', 'price': 0, 'vars': {'course_run_id': 'edX/toy/2012_Fall', 'mode': 'audit'}, 'title': 'Course edX/toy/2012_Fall mode: audit', 'qty': 1}], options={})
E   Actual: purchase('test@edx.org', [{'id': 'edX/toy/2012_Fall-audit', 'url': 'http://lms.testserver.fake/courses/edX/toy/2012_Fall/info', 'price': 0, 'vars': {'course_run_id': 'edX/toy/2012_Fall', 'mode': 'audit'}, 'title': 'Course edX/toy/2012_Fall mode: audit', 'qty': 1}], options={'send_template': 'enroll_template'})

<string>:3: AssertionError

Migrated from private ticket https://2u-internal.atlassian.net/issues/CR-1806

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lms/djangoapps/email_marketing/tests/test_signals.py::SailthruTests::test_update_course_enrollment and compare the failing and passing builds linked in the issue. Read the flaky-test process and the email marketing enrollment path to determine why the mocked purchase options differ; done means the test is restored or its replacement reliably verifies the intended call.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.