SuperCoopBerlin / tapir

Member & shift management system for our cooperative supermarket, SuperCoop Berlin eG
GNU Affero General Public License v3.0
31 stars 22 forks source link

Midnight bug: test_share_owner_list_filters #561

Open crosspolar opened 2 months ago

crosspolar commented 2 months ago

Shortly after midnight, Github Actions fails the testing-workflow here:

=================================== FAILURES ===================================
______________________ TestShareOwnerList.test_has_status ______________________

self = <tapir.coop.tests.test_share_owner_list_filters.TestShareOwnerList testMethod=test_has_status>

    def test_has_status(self):
        share_owners_with_status_sold = [
            ShareOwnerFactory.create(),
            TapirUserFactory.create().share_owner,
        ]
        for share_ownership in ShareOwnership.objects.filter(
            share_owner__in=share_owners_with_status_sold
        ):
            share_ownership.end_date = timezone.now() - datetime.timedelta(days=1)
            share_ownership.save()

        share_owners_with_status_investing = [
            ShareOwnerFactory.create(),
            TapirUserFactory.create().share_owner,
        ]
        for share_owner in share_owners_with_status_investing:
            share_owner.is_investing = True
            share_owner.save()

        share_owners_with_status_active = [
            ShareOwnerFactory.create(),
            TapirUserFactory.create().share_owner,
        ]
        for share_owner in share_owners_with_status_active:
            share_owner.is_investing = False
            share_owner.save()

>       self.visit_view(
            {"status": MemberStatus.SOLD},
            must_be_in=share_owners_with_status_sold,
            must_be_out=share_owners_with_status_investing
            + share_owners_with_status_active,
        )

tapir/coop/tests/test_share_owner_list_filters.py:288: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tapir/coop/tests/test_share_owner_list_filters.py:40: in visit_view
    self.assertIn(
E   AssertionError: <ShareOwner: ShareOwner object (243)> not found in <django_tables2.data.TableQuerysetData object at 0x7f68ae6a9700> : Lindsey Hinton #243 should show up in the list filtered by status=sold.

Some hours later it's fine again. I assume it's some timezone and datetime problem

Theophile-Madet commented 2 months ago

Interesting 😅 We'd need to mock the time instead of doing this relative to the actual time.