Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_non_recursive_save (resources.test_refunds.ChargeRefundTest) is failing #189

Closed
ghost opened this issue Dec 4, 2015 · 6 comments
Closed

Comments

@ghost
Copy link

ghost commented Dec 4, 2015

When running the test suite, following test fails on all versions of library for up to 1 year back in history:

======================================================================
FAIL: test_non_recursive_save (resources.test_refunds.ChargeRefundTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/toriningen/Projects/stripe-python/stripe/test/resources/test_refunds.py", line 98, in test_non_recursive_save
    self.requestor_mock.request.assert_not_called()
  File "/usr/local/lib/python2.7/site-packages/mock/mock.py", line 915, in assert_not_called
    raise AssertionError(msg)
AssertionError: Expected 'request' to not have been called. Called 1 times.

Testcase itself looks like this:

def test_non_recursive_save(self):
    charge = stripe.Charge.construct_from({
        'id': 'ch_nested_update',
        'customer': {
            'object': 'customer',
            'description': 'foo',
        },
        'refunds': {
            'object': 'list',
            'url': '/v1/charges/ch_foo/refunds',
            'data': [{
                'id': 'ref_123',
            }],
        },
    }, 'api_key')

    charge.customer.description = 'bar'
    charge.refunds.has_more = True
    charge.refunds.data[0].description = 'bar'
    charge.save()

    self.requestor_mock.request.assert_not_called()

When request is being called (while it shouldn't), it tries to perform following query:

POST /v1/charges/ch_nested_update
{
    "refunds": {
        "has_more": true
    }
}

Also, this does not reproduce on Python 3, because of #188.

@agentcoops
Copy link

Hi @alex-downtown, thanks for the report, but I'm having trouble reproducing this issue. Could you clarify whether you tried the latest master, which versions of Python you're running this test with, in what OS environment and how you're executing it? If I run

tox -- --test-suite stripe.test.resources.test_refunds.ChargeRefundTest.test_non_recursive_save

on the the latest version of the library, I find that, apart from problems relating to #188, the test passes for all Python versions checked (py26, py27, pypy, py31).

@ghost
Copy link
Author

ghost commented Dec 4, 2015

@agentcoops I had just tracked it down, and it seems that the root of problems is mock-1.3.0 library. If you install it, builds start failing on python2 and python3 in these two tests only (#189 and #190).

@ghost
Copy link
Author

ghost commented Dec 4, 2015

But actually, this still renders testcase failing. It's not valid — instead, mock-1.0.1 has a bug in it that prevents call from being registered. If you replace test case with following:

def test_non_recursive_save(self):
    charge = stripe.Charge.construct_from({
        'id': 'ch_nested_update',
        'customer': {
            'object': 'customer',
            'description': 'foo',
        },
        'refunds': {
            'object': 'list',
            'url': '/v1/charges/ch_foo/refunds',
            'data': [{
                'id': 'ref_123',
            }],
        },
    }, 'api_key')

    charge.customer.description = 'bar'
    charge.refunds.has_more = True
    charge.refunds.data[0].description = 'bar'

    ##########
    def foo(*args, **kwargs):
        raise RuntimeError(r'/!\ NO WAY %r %r' % (args, kwargs))
    self.requestor_mock.request = foo
    ##########

    charge.save()

    self.requestor_mock.request.assert_not_called()

You will see exception raising, e.g. request is being called, despite mock-1.0.1 does not think so.

@ghost
Copy link
Author

ghost commented Dec 4, 2015

Even worse, self.requestor_mock.request.call_args has this:

call('post', '/v1/charges/ch_nested_update', {'refunds': {'has_more': True}}, None)

despite assert_not_called() does not fail.

@ghost
Copy link
Author

ghost commented Dec 4, 2015

Same stands for #190, as I had just checked it. This all is tested on latest master (commit e62fe4b2deb54efce4c1f9fd1022414b390a04fe), Python versions 2.6.9, 2.7.10, 3.1.0, 3.1.5, 3.2.0, 3.2.6, 3.3.0, 3.3.6, 3.4.0, 3.4.3, 3.5.0, on OS X 10.11, tests were run via

$ ~/.pyenv/versions/3.2.6/bin/python setup.py test --test-suite stripe.test.resources.test_refunds.ChargeRefundTest.test_non_recursive_save

@agentcoops
Copy link

Thanks! I've been able to duplicate the issue and will investigate further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant