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

fix: Fix stripe invoice time bounding param names #966

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

@codecov-staging
Copy link

codecov-staging bot commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Nov 8, 2024

❌ 3 Tests Failed:

Tests completed Failed Passed Skipped
2660 3 2657 6
View the top 3 failed tests by shortest run time
services/tests/test_billing.py::StripeServiceTests::test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_with_grace_year_refund_if_valid_plan
Stack Traces | 0.041s run time
self = <MagicMock name='list' id='139652343642544'>, args = ()
kwargs = {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}, 'status': 'paid', 'subscription': 'sub_1K77Y5GlVGuVgOrkJrLjRnne'}
expected = call(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
actual = call(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f0344ea9120>
cause = None

    def assert_called_with(self, /, *args, **kwargs):
        """assert that the last call was made with the specified arguments.
    
        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\n  Actual: %s'
                    % (expected, actual))
            raise AssertionError(error_message)
    
        def _error_message():
            msg = self._format_mock_failure_message(args, kwargs)
            return msg
        expected = self._call_matcher(_Call((args, kwargs), two=True))
        actual = self._call_matcher(self.call_args)
        if actual != expected:
            cause = expected if isinstance(expected, Exception) else None
>           raise AssertionError(_error_message()) from cause
E           AssertionError: expected call not found.
E           Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
E             Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})

.../local/lib/python3.12/unittest/mock.py:949: AssertionError

During handling of the above exception, another exception occurred:

self = <MagicMock name='list' id='139652343642544'>, args = ()
kwargs = {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}, 'status': 'paid', 'subscription': 'sub_1K77Y5GlVGuVgOrkJrLjRnne'}

    def assert_called_once_with(self, /, *args, **kwargs):
        """assert that the mock was called exactly once and that that call was
        with the specified arguments."""
        if not self.call_count == 1:
            msg = ("Expected '%s' to be called once. Called %s times.%s"
                   % (self._mock_name or 'mock',
                      self.call_count,
                      self._calls_repr()))
            raise AssertionError(msg)
>       return self.assert_called_with(*args, **kwargs)
E       AssertionError: expected call not found.
E       Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
E         Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
E       
E       pytest introspection follows:
E       
E       Kwargs:
E       assert {'created': {...gOrkJrLjRnne'} == {'created': {...gOrkJrLjRnne'}
E         
E         Omitting 2 identical items, use -vv to show
E         Differing items:
E         {'created': {'gte': 1458263420, 'lt': 1489799420}} != {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}}
E         Use -v to get more diff

.../local/lib/python3.12/unittest/mock.py:961: AssertionError

During handling of the above exception, another exception occurred:

self = <services.tests.test_billing.StripeServiceTests testMethod=test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_with_grace_year_refund_if_valid_plan>
schedule_release_mock = <MagicMock name='release' id='139652341664512'>
retrieve_subscription_mock = <MagicMock name='retrieve' id='139652343130416'>
cancel_sub_mock = <MagicMock name='cancel' id='139652344307376'>
list_invoice_mock = <MagicMock name='list' id='139652343642544'>
create_refund_mock = <MagicMock name='create' id='139652341717648'>
modify_customer_mock = <MagicMock name='modify' id='139652341721728'>
modify_sub_mock = <MagicMock name='modify' id='139652344304784'>
retrieve_customer_mock = <MagicMock name='retrieve' id='139652341184848'>

    @freeze_time("2017-03-19T00:00:00")
    @patch("services.billing.stripe.Customer.retrieve")
    @patch("services.billing.stripe.Subscription.modify")
    @patch("services.billing.stripe.Customer.modify")
    @patch("services.billing.stripe.Refund.create")
    @patch("services.billing.stripe.Invoice.list")
    @patch("services.billing.stripe.Subscription.cancel")
    @patch("services.billing.stripe.Subscription.retrieve")
    @patch("services.billing.stripe.SubscriptionSchedule.release")
    def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_with_grace_year_refund_if_valid_plan(
        self,
        schedule_release_mock,
        retrieve_subscription_mock,
        cancel_sub_mock,
        list_invoice_mock,
        create_refund_mock,
        modify_customer_mock,
        modify_sub_mock,
        retrieve_customer_mock,
    ):
        with open("..../tests/samples/stripe_invoice.json") as f:
            stripe_invoice_response = json.load(f)
        list_invoice_mock.return_value = stripe_invoice_response
        plan = PlanName.CODECOV_PRO_YEARLY.value
        stripe_subscription_id = "sub_1K77Y5GlVGuVgOrkJrLjRnne"
        stripe_schedule_id = "sub_sched_sch1K77Y5GlVGuVgOrkJrLjRnne"
        customer_id = "cus_HF6p8Zx7JdRS7A"
        owner = OwnerFactory(
            stripe_subscription_id=stripe_subscription_id,
            plan=plan,
            plan_activated_users=[4, 6, 3],
            plan_user_count=9,
            stripe_customer_id=customer_id,
        )
        subscription_params = {
            "schedule_id": stripe_schedule_id,
            "start_date": 1489799420,
            "end_date": 1492477820,
            "quantity": 10,
            "name": plan,
            "id": 215,
            "plan": {
                "new_plan": "plan_H6P3KZXwmAbqPS",
                "new_quantity": 7,
                "subscription_id": "sub_123",
                "interval": "year",
            },
        }
    
        retrieve_subscription_mock.return_value = MockSubscription(subscription_params)
        retrieve_customer_mock.return_value = {
            "id": "cus_HF6p8Zx7JdRS7A",
            "metadata": {"autorefunds_remaining": "1"},
        }
        self.stripe.delete_subscription(owner)
        schedule_release_mock.assert_called_once_with(stripe_schedule_id)
        retrieve_customer_mock.assert_called_once_with(owner.stripe_customer_id)
        cancel_sub_mock.assert_called_once_with(stripe_subscription_id)
>       list_invoice_mock.assert_called_once_with(
            subscription=stripe_subscription_id,
            status="paid",
            created={"created.gte": 1458263420, "created.lt": 1489799420},
        )
E       AssertionError: expected call not found.
E       Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
E         Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
E       
E       pytest introspection follows:
E       
E       Kwargs:
E       assert {'created': {...gOrkJrLjRnne'} == {'created': {...gOrkJrLjRnne'}
E         
E         Omitting 2 identical items, use -vv to show
E         Differing items:
E         {'created': {'gte': 1458263420, 'lt': 1489799420}} != {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}}
E         Use -v to get more diff

services/tests/test_billing.py:523: AssertionError
services/tests/test_billing.py::StripeServiceTests::test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_immediately_with_grace_year_but_no_invoices_to_refund
Stack Traces | 0.054s run time
self = <MagicMock name='list' id='139652344072672'>, args = ()
kwargs = {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}, 'status': 'paid', 'subscription': 'sub_1K77Y5GlVGuVgOrkJrLjRnne'}
expected = call(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
actual = call(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f035880bd80>
cause = None

    def assert_called_with(self, /, *args, **kwargs):
        """assert that the last call was made with the specified arguments.
    
        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\n  Actual: %s'
                    % (expected, actual))
            raise AssertionError(error_message)
    
        def _error_message():
            msg = self._format_mock_failure_message(args, kwargs)
            return msg
        expected = self._call_matcher(_Call((args, kwargs), two=True))
        actual = self._call_matcher(self.call_args)
        if actual != expected:
            cause = expected if isinstance(expected, Exception) else None
>           raise AssertionError(_error_message()) from cause
E           AssertionError: expected call not found.
E           Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
E             Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})

.../local/lib/python3.12/unittest/mock.py:949: AssertionError

During handling of the above exception, another exception occurred:

self = <MagicMock name='list' id='139652344072672'>, args = ()
kwargs = {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}, 'status': 'paid', 'subscription': 'sub_1K77Y5GlVGuVgOrkJrLjRnne'}

    def assert_called_once_with(self, /, *args, **kwargs):
        """assert that the mock was called exactly once and that that call was
        with the specified arguments."""
        if not self.call_count == 1:
            msg = ("Expected '%s' to be called once. Called %s times.%s"
                   % (self._mock_name or 'mock',
                      self.call_count,
                      self._calls_repr()))
            raise AssertionError(msg)
>       return self.assert_called_with(*args, **kwargs)
E       AssertionError: expected call not found.
E       Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
E         Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
E       
E       pytest introspection follows:
E       
E       Kwargs:
E       assert {'created': {...gOrkJrLjRnne'} == {'created': {...gOrkJrLjRnne'}
E         
E         Omitting 2 identical items, use -vv to show
E         Differing items:
E         {'created': {'gte': 1458263420, 'lt': 1489799420}} != {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}}
E         Use -v to get more diff

.../local/lib/python3.12/unittest/mock.py:961: AssertionError

During handling of the above exception, another exception occurred:

self = <services.tests.test_billing.StripeServiceTests testMethod=test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_immediately_with_grace_year_but_no_invoices_to_refund>
schedule_release_mock = <MagicMock name='release' id='139652343134160'>
retrieve_subscription_mock = <MagicMock name='retrieve' id='139652342701264'>
cancel_sub_mock = <MagicMock name='cancel' id='139652341408752'>
list_invoice_mock = <MagicMock name='list' id='139652344072672'>
create_refund_mock = <MagicMock name='create' id='139652342996224'>
modify_customer_mock = <MagicMock name='modify' id='139652344080256'>
modify_sub_mock = <MagicMock name='modify' id='139652344084144'>
retrieve_customer_mock = <MagicMock name='retrieve' id='139652341319200'>

    @freeze_time("2017-03-19T00:00:00")
    @patch("services.billing.stripe.Customer.retrieve")
    @patch("services.billing.stripe.Subscription.modify")
    @patch("services.billing.stripe.Customer.modify")
    @patch("services.billing.stripe.Refund.create")
    @patch("services.billing.stripe.Invoice.list")
    @patch("services.billing.stripe.Subscription.cancel")
    @patch("services.billing.stripe.Subscription.retrieve")
    @patch("services.billing.stripe.SubscriptionSchedule.release")
    def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_immediately_with_grace_year_but_no_invoices_to_refund(
        self,
        schedule_release_mock,
        retrieve_subscription_mock,
        cancel_sub_mock,
        list_invoice_mock,
        create_refund_mock,
        modify_customer_mock,
        modify_sub_mock,
        retrieve_customer_mock,
    ):
        with open("..../tests/samples/stripe_invoice.json") as f:
            stripe_invoice_response = json.load(f)
        for invoice in stripe_invoice_response["data"]:
            invoice["charge"] = None
        list_invoice_mock.return_value = stripe_invoice_response
        plan = PlanName.CODECOV_PRO_YEARLY.value
        stripe_subscription_id = "sub_1K77Y5GlVGuVgOrkJrLjRnne"
        stripe_schedule_id = "sub_sched_sch1K77Y5GlVGuVgOrkJrLjRnne"
        customer_id = "cus_HF6p8Zx7JdRS7A"
        owner = OwnerFactory(
            stripe_subscription_id=stripe_subscription_id,
            plan=plan,
            plan_activated_users=[4, 6, 3],
            plan_user_count=9,
            stripe_customer_id=customer_id,
        )
        subscription_params = {
            "schedule_id": stripe_schedule_id,
            "start_date": 1489799420,
            "end_date": 1492477820,
            "quantity": 10,
            "name": plan,
            "id": 215,
            "plan": {
                "new_plan": "plan_H6P3KZXwmAbqPS",
                "new_quantity": 7,
                "subscription_id": "sub_123",
                "interval": "year",
            },
        }
    
        retrieve_subscription_mock.return_value = MockSubscription(subscription_params)
        retrieve_customer_mock.return_value = {
            "id": "cus_HF6p8Zx7JdRS7A",
            "metadata": {"autorefunds_remaining": "1"},
        }
        self.stripe.delete_subscription(owner)
        schedule_release_mock.assert_called_once_with(stripe_schedule_id)
        retrieve_customer_mock.assert_called_once_with(owner.stripe_customer_id)
        cancel_sub_mock.assert_called_once_with(stripe_subscription_id)
>       list_invoice_mock.assert_called_once_with(
            subscription=stripe_subscription_id,
            status="paid",
            created={"created.gte": 1458263420, "created.lt": 1489799420},
        )
E       AssertionError: expected call not found.
E       Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
E         Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
E       
E       pytest introspection follows:
E       
E       Kwargs:
E       assert {'created': {...gOrkJrLjRnne'} == {'created': {...gOrkJrLjRnne'}
E         
E         Omitting 2 identical items, use -vv to show
E         Differing items:
E         {'created': {'gte': 1458263420, 'lt': 1489799420}} != {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}}
E         Use -v to get more diff

services/tests/test_billing.py:600: AssertionError
upload/tests/test_serializers.py::test_upload_serializer_contains_expected_fields_with_flags
Stack Traces | 0.358s run time
transactional_db = None
mocker = <pytest_mock.plugin.MockerFixture object at 0x7ef67742fb90>

    def test_upload_serializer_contains_expected_fields_with_flags(
        transactional_db, mocker
    ):
        mocker.patch(
            "services.archive.StorageService.create_presigned_put",
            return_value="presigned put",
        )
        upload = get_fake_upload_with_flags()
        serializer = UploadSerializer(instance=upload)
        repo = upload.report.commit.repository
        expected_data = {
            "external_id": str(upload.external_id),
            "created_at": upload.created_at.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
            "raw_upload_location": "presigned put",
            "state": upload.state,
            "provider": upload.provider,
            "upload_type": upload.upload_type,
            "ci_url": upload.build_url,
            "flags": ["flag1", "flag2"],
            "job_code": upload.job_code,
            "env": upload.env,
            "name": upload.name,
            "url": f"{settings.CODECOV_DASHBOARD_URL}/{repo.author.service}/{repo.author.username}/{repo.name}/commit/{upload.report.commit.commitid}",
        }
>       assert serializer.data == expected_data
E       AssertionError: assert {'external_id...b_code': None} == {'ci_url': No...da8a03d', ...}
E         
E         Omitting 11 identical items, use -vv to show
E         Differing items:
E         {'flags': ['flag2', 'flag1']} != {'flags': ['flag1', 'flag2']}
E         Use -v to get more diff

upload/tests/test_serializers.py:112: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
Got feedback? Let us know on Github

Copy link

codecov-public-qa bot commented Nov 8, 2024

Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time.

❌ Failed Test Results:

Completed 2666 tests with 3 failed, 2657 passed and 6 skipped.

View the full list of failed tests

pytest

  • Class name: services.tests.test_billing.StripeServiceTests
    Test name: test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_immediately_with_grace_year_but_no_invoices_to_refund

    self = <MagicMock name='list' id='139652344072672'>, args = ()
    kwargs = {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}, 'status': 'paid', 'subscription': 'sub_1K77Y5GlVGuVgOrkJrLjRnne'}
    expected = call(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
    actual = call(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
    _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f035880bd80>
    cause = None

    def assert_called_with(self, /, *args, **kwargs):
    """assert that the last call was made with the specified arguments.

    Raises an AssertionError if the args and keyword args passed in are
    different to the last call to the mock."""
    if self.call_args is None:
    expected = self._format_mock_call_signature(args, kwargs)
    actual = 'not called.'
    error_message = ('expected call not found.\nExpected: %s\n Actual: %s'
    % (expected, actual))
    raise AssertionError(error_message)

    def _error_message():
    msg = self._format_mock_failure_message(args, kwargs)
    return msg
    expected = self._call_matcher(_Call((args, kwargs), two=True))
    actual = self._call_matcher(self.call_args)
    if actual != expected:
    cause = expected if isinstance(expected, Exception) else None
    > raise AssertionError(_error_message()) from cause
    E AssertionError: expected call not found.
    E Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
    E Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})

    .../local/lib/python3.12/unittest/mock.py:949: AssertionError

    During handling of the above exception, another exception occurred:

    self = <MagicMock name='list' id='139652344072672'>, args = ()
    kwargs = {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}, 'status': 'paid', 'subscription': 'sub_1K77Y5GlVGuVgOrkJrLjRnne'}

    def assert_called_once_with(self, /, *args, **kwargs):
    """assert that the mock was called exactly once and that that call was
    with the specified arguments."""
    if not self.call_count == 1:
    msg = ("Expected '%s' to be called once. Called %s times.%s"
    % (self._mock_name or 'mock',
    self.call_count,
    self._calls_repr()))
    raise AssertionError(msg)
    > return self.assert_called_with(*args, **kwargs)
    E AssertionError: expected call not found.
    E Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
    E Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
    E
    E pytest introspection follows:
    E
    E Kwargs:
    E assert {'created': {...gOrkJrLjRnne'} == {'created': {...gOrkJrLjRnne'}
    E
    E Omitting 2 identical items, use -vv to show
    E Differing items:
    E {'created': {'gte': 1458263420, 'lt': 1489799420}} != {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}}
    E Use -v to get more diff

    .../local/lib/python3.12/unittest/mock.py:961: AssertionError

    During handling of the above exception, another exception occurred:

    self = <services.tests.test_billing.StripeServiceTests testMethod=test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_immediately_with_grace_year_but_no_invoices_to_refund>
    schedule_release_mock = <MagicMock name='release' id='139652343134160'>
    retrieve_subscription_mock = <MagicMock name='retrieve' id='139652342701264'>
    cancel_sub_mock = <MagicMock name='cancel' id='139652341408752'>
    list_invoice_mock = <MagicMock name='list' id='139652344072672'>
    create_refund_mock = <MagicMock name='create' id='139652342996224'>
    modify_customer_mock = <MagicMock name='modify' id='139652344080256'>
    modify_sub_mock = <MagicMock name='modify' id='139652344084144'>
    retrieve_customer_mock = <MagicMock name='retrieve' id='139652341319200'>

    @freeze_time("2017-03-19T00:00:00")
    @patch("services.billing.stripe.Customer.retrieve")
    @patch("services.billing.stripe.Subscription.modify")
    @patch("services.billing.stripe.Customer.modify")
    @patch("services.billing.stripe.Refund.create")
    @patch("services.billing.stripe.Invoice.list")
    @patch("services.billing.stripe.Subscription.cancel")
    @patch("services.billing.stripe.Subscription.retrieve")
    @patch("services.billing.stripe.SubscriptionSchedule.release")
    def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_immediately_with_grace_year_but_no_invoices_to_refund(
    self,
    schedule_release_mock,
    retrieve_subscription_mock,
    cancel_sub_mock,
    list_invoice_mock,
    create_refund_mock,
    modify_customer_mock,
    modify_sub_mock,
    retrieve_customer_mock,
    ):
    with open("..../tests/samples/stripe_invoice.json") as f:
    stripe_invoice_response = json.load(f)
    for invoice in stripe_invoice_response["data"]:
    invoice["charge"] = None
    list_invoice_mock.return_value = stripe_invoice_response
    plan = PlanName.CODECOV_PRO_YEARLY.value
    stripe_subscription_id = "sub_1K77Y5GlVGuVgOrkJrLjRnne"
    stripe_schedule_id = "sub_sched_sch1K77Y5GlVGuVgOrkJrLjRnne"
    customer_id = "cus_HF6p8Zx7JdRS7A"
    owner = OwnerFactory(
    stripe_subscription_id=stripe_subscription_id,
    plan=plan,
    plan_activated_users=[4, 6, 3],
    plan_user_count=9,
    stripe_customer_id=customer_id,
    )
    subscription_params = {
    "schedule_id": stripe_schedule_id,
    "start_date": 1489799420,
    "end_date": 1492477820,
    "quantity": 10,
    "name": plan,
    "id": 215,
    "plan": {
    "new_plan": "plan_H6P3KZXwmAbqPS",
    "new_quantity": 7,
    "subscription_id": "sub_123",
    "interval": "year",
    },
    }

    retrieve_subscription_mock.return_value = MockSubscription(subscription_params)
    retrieve_customer_mock.return_value = {
    "id": "cus_HF6p8Zx7JdRS7A",
    "metadata": {"autorefunds_remaining": "1"},
    }
    self.stripe.delete_subscription(owner)
    schedule_release_mock.assert_called_once_with(stripe_schedule_id)
    retrieve_customer_mock.assert_called_once_with(owner.stripe_customer_id)
    cancel_sub_mock.assert_called_once_with(stripe_subscription_id)
    > list_invoice_mock.assert_called_once_with(
    subscription=stripe_subscription_id,
    status="paid",
    created={"created.gte": 1458263420, "created.lt": 1489799420},
    )
    E AssertionError: expected call not found.
    E Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
    E Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
    E
    E pytest introspection follows:
    E
    E Kwargs:
    E assert {'created': {...gOrkJrLjRnne'} == {'created': {...gOrkJrLjRnne'}
    E
    E Omitting 2 identical items, use -vv to show
    E Differing items:
    E {'created': {'gte': 1458263420, 'lt': 1489799420}} != {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}}
    E Use -v to get more diff

    services/tests/test_billing.py:600: AssertionError
  • Class name: services.tests.test_billing.StripeServiceTests
    Test name: test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_with_grace_year_refund_if_valid_plan

    self = <MagicMock name='list' id='139652343642544'>, args = ()
    kwargs = {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}, 'status': 'paid', 'subscription': 'sub_1K77Y5GlVGuVgOrkJrLjRnne'}
    expected = call(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
    actual = call(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
    _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f0344ea9120>
    cause = None

    def assert_called_with(self, /, *args, **kwargs):
    """assert that the last call was made with the specified arguments.

    Raises an AssertionError if the args and keyword args passed in are
    different to the last call to the mock."""
    if self.call_args is None:
    expected = self._format_mock_call_signature(args, kwargs)
    actual = 'not called.'
    error_message = ('expected call not found.\nExpected: %s\n Actual: %s'
    % (expected, actual))
    raise AssertionError(error_message)

    def _error_message():
    msg = self._format_mock_failure_message(args, kwargs)
    return msg
    expected = self._call_matcher(_Call((args, kwargs), two=True))
    actual = self._call_matcher(self.call_args)
    if actual != expected:
    cause = expected if isinstance(expected, Exception) else None
    > raise AssertionError(_error_message()) from cause
    E AssertionError: expected call not found.
    E Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
    E Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})

    .../local/lib/python3.12/unittest/mock.py:949: AssertionError

    During handling of the above exception, another exception occurred:

    self = <MagicMock name='list' id='139652343642544'>, args = ()
    kwargs = {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}, 'status': 'paid', 'subscription': 'sub_1K77Y5GlVGuVgOrkJrLjRnne'}

    def assert_called_once_with(self, /, *args, **kwargs):
    """assert that the mock was called exactly once and that that call was
    with the specified arguments."""
    if not self.call_count == 1:
    msg = ("Expected '%s' to be called once. Called %s times.%s"
    % (self._mock_name or 'mock',
    self.call_count,
    self._calls_repr()))
    raise AssertionError(msg)
    > return self.assert_called_with(*args, **kwargs)
    E AssertionError: expected call not found.
    E Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
    E Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
    E
    E pytest introspection follows:
    E
    E Kwargs:
    E assert {'created': {...gOrkJrLjRnne'} == {'created': {...gOrkJrLjRnne'}
    E
    E Omitting 2 identical items, use -vv to show
    E Differing items:
    E {'created': {'gte': 1458263420, 'lt': 1489799420}} != {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}}
    E Use -v to get more diff

    .../local/lib/python3.12/unittest/mock.py:961: AssertionError

    During handling of the above exception, another exception occurred:

    self = <services.tests.test_billing.StripeServiceTests testMethod=test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_with_grace_year_refund_if_valid_plan>
    schedule_release_mock = <MagicMock name='release' id='139652341664512'>
    retrieve_subscription_mock = <MagicMock name='retrieve' id='139652343130416'>
    cancel_sub_mock = <MagicMock name='cancel' id='139652344307376'>
    list_invoice_mock = <MagicMock name='list' id='139652343642544'>
    create_refund_mock = <MagicMock name='create' id='139652341717648'>
    modify_customer_mock = <MagicMock name='modify' id='139652341721728'>
    modify_sub_mock = <MagicMock name='modify' id='139652344304784'>
    retrieve_customer_mock = <MagicMock name='retrieve' id='139652341184848'>

    @freeze_time("2017-03-19T00:00:00")
    @patch("services.billing.stripe.Customer.retrieve")
    @patch("services.billing.stripe.Subscription.modify")
    @patch("services.billing.stripe.Customer.modify")
    @patch("services.billing.stripe.Refund.create")
    @patch("services.billing.stripe.Invoice.list")
    @patch("services.billing.stripe.Subscription.cancel")
    @patch("services.billing.stripe.Subscription.retrieve")
    @patch("services.billing.stripe.SubscriptionSchedule.release")
    def test_delete_subscription_with_schedule_releases_schedule_and_cancels_subscription_with_grace_year_refund_if_valid_plan(
    self,
    schedule_release_mock,
    retrieve_subscription_mock,
    cancel_sub_mock,
    list_invoice_mock,
    create_refund_mock,
    modify_customer_mock,
    modify_sub_mock,
    retrieve_customer_mock,
    ):
    with open("..../tests/samples/stripe_invoice.json") as f:
    stripe_invoice_response = json.load(f)
    list_invoice_mock.return_value = stripe_invoice_response
    plan = PlanName.CODECOV_PRO_YEARLY.value
    stripe_subscription_id = "sub_1K77Y5GlVGuVgOrkJrLjRnne"
    stripe_schedule_id = "sub_sched_sch1K77Y5GlVGuVgOrkJrLjRnne"
    customer_id = "cus_HF6p8Zx7JdRS7A"
    owner = OwnerFactory(
    stripe_subscription_id=stripe_subscription_id,
    plan=plan,
    plan_activated_users=[4, 6, 3],
    plan_user_count=9,
    stripe_customer_id=customer_id,
    )
    subscription_params = {
    "schedule_id": stripe_schedule_id,
    "start_date": 1489799420,
    "end_date": 1492477820,
    "quantity": 10,
    "name": plan,
    "id": 215,
    "plan": {
    "new_plan": "plan_H6P3KZXwmAbqPS",
    "new_quantity": 7,
    "subscription_id": "sub_123",
    "interval": "year",
    },
    }

    retrieve_subscription_mock.return_value = MockSubscription(subscription_params)
    retrieve_customer_mock.return_value = {
    "id": "cus_HF6p8Zx7JdRS7A",
    "metadata": {"autorefunds_remaining": "1"},
    }
    self.stripe.delete_subscription(owner)
    schedule_release_mock.assert_called_once_with(stripe_schedule_id)
    retrieve_customer_mock.assert_called_once_with(owner.stripe_customer_id)
    cancel_sub_mock.assert_called_once_with(stripe_subscription_id)
    > list_invoice_mock.assert_called_once_with(
    subscription=stripe_subscription_id,
    status="paid",
    created={"created.gte": 1458263420, "created.lt": 1489799420},
    )
    E AssertionError: expected call not found.
    E Expected: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'created.gte': 1458263420, 'created.lt': 1489799420})
    E Actual: list(subscription='sub_1K77Y5GlVGuVgOrkJrLjRnne', status='paid', created={'gte': 1458263420, 'lt': 1489799420})
    E
    E pytest introspection follows:
    E
    E Kwargs:
    E assert {'created': {...gOrkJrLjRnne'} == {'created': {...gOrkJrLjRnne'}
    E
    E Omitting 2 identical items, use -vv to show
    E Differing items:
    E {'created': {'gte': 1458263420, 'lt': 1489799420}} != {'created': {'created.gte': 1458263420, 'created.lt': 1489799420}}
    E Use -v to get more diff

    services/tests/test_billing.py:523: AssertionError
  • Class name: upload.tests.test_serializers
    Test name: test_upload_serializer_contains_expected_fields_with_flags

    transactional_db = None
    mocker = <pytest_mock.plugin.MockerFixture object at 0x7ef67742fb90>

    def test_upload_serializer_contains_expected_fields_with_flags(
    transactional_db, mocker
    ):
    mocker.patch(
    "services.archive.StorageService.create_presigned_put",
    return_value="presigned put",
    )
    upload = get_fake_upload_with_flags()
    serializer = UploadSerializer(instance=upload)
    repo = upload.report.commit.repository
    expected_data = {
    "external_id": str(upload.external_id),
    "created_at": upload.created_at.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
    "raw_upload_location": "presigned put",
    "state": upload.state,
    "provider": upload.provider,
    "upload_type": upload.upload_type,
    "ci_url": upload.build_url,
    "flags": ["flag1", "flag2"],
    "job_code": upload.job_code,
    "env": upload.env,
    "name": upload.name,
    "url": f"{settings.CODECOV_DASHBOARD_URL}/{repo.author.service}/{repo.author.username}/{repo.name}/commit/{upload.report.commit.commitid}",
    }
    > assert serializer.data == expected_data
    E AssertionError: assert {'external_id...b_code': None} == {'ci_url': No...da8a03d', ...}
    E
    E Omitting 11 identical items, use -vv to show
    E Differing items:
    E {'flags': ['flag2', 'flag1']} != {'flags': ['flag1', 'flag2']}
    E Use -v to get more diff

    upload/tests/test_serializers.py:112: AssertionError

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.25%. Comparing base (136300e) to head (3255777).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #966   +/-   ##
=======================================
  Coverage   96.25%   96.25%           
=======================================
  Files         827      827           
  Lines       19090    19090           
=======================================
  Hits        18376    18376           
  Misses        714      714           
Flag Coverage Δ
unit 92.52% <ø> (ø)
unit-latest-uploader 92.52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented Nov 8, 2024

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@calvin-codecov calvin-codecov force-pushed the cy/stripe_refund_invoice_list_fix branch from 38e94ed to 3255777 Compare November 8, 2024 19:39
@calvin-codecov calvin-codecov added this pull request to the merge queue Nov 8, 2024
Merged via the queue into main with commit 001c804 Nov 8, 2024
18 of 19 checks passed
@calvin-codecov calvin-codecov deleted the cy/stripe_refund_invoice_list_fix branch November 8, 2024 21:15
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

Successfully merging this pull request may close these issues.

2 participants