def test_newest_waiver_taken(self, matching_memberships):
        """ If an old membership has an active waiver, use it! """
        one_month_later = local_date() + timedelta(days=30)
        memberships_by_email = {
            '*****@*****.**': {
                'membership': {
                    'expires': date(2011, 1, 1),
                    'active': False,
                    'email': '*****@*****.**',
                },
                'waiver': {
                    'expires': None,
                    'active': False
                },
                'status': 'Expired',
            },
            '*****@*****.**': {
                'membership': {
                    'expires': date(2012, 2, 2),
                    'active': False,
                    'email': '*****@*****.**',
                },
                'waiver': {
                    'expires': None,
                    'active': False
                },
                'status': 'Expired',
            },
            '*****@*****.**': {
                'membership': {
                    'expires': date(2013, 3, 3),
                    'active': False,
                    'email': '*****@*****.**',
                },
                'waiver': {
                    'expires': None,
                    'active': False
                },
                'status': 'Expired',
            },
        }
        matching_memberships.return_value = memberships_by_email

        # All waivers are expired or missing, so we take the newest membership
        self.assertEqual(
            geardb.membership_expiration(list(memberships_by_email)),
            memberships_by_email['*****@*****.**'],
        )

        # Give the middle membership an active waiver, even though it's not the newest
        middle = memberships_by_email['*****@*****.**']
        middle['waiver'].update(expires=one_month_later, active=True)
        middle['status'] = 'Membership Expired'

        # '*****@*****.**' is not the newest membership, but it has an active waiver
        # (and all other memberships do not have an active waiver)
        self.assertEqual(
            geardb.membership_expiration(list(memberships_by_email)),
            memberships_by_email['*****@*****.**'],
        )
Example #2
0
    def test_newest_waiver_taken(self, matching_memberships):
        """ If an old membership has an active waiver, use it! """
        one_month_later = local_date() + timedelta(days=30)
        memberships_by_email = {
            '*****@*****.**': {
                'membership': {
                    'expires': date(2011, 1, 1),
                    'active': False,
                    'email': '*****@*****.**',
                },
                'waiver': {'expires': None, 'active': False},
                'status': 'Expired',
            },
            '*****@*****.**': {
                'membership': {
                    'expires': date(2012, 2, 2),
                    'active': False,
                    'email': '*****@*****.**',
                },
                'waiver': {'expires': None, 'active': False},
                'status': 'Expired',
            },
            '*****@*****.**': {
                'membership': {
                    'expires': date(2013, 3, 3),
                    'active': False,
                    'email': '*****@*****.**',
                },
                'waiver': {'expires': None, 'active': False},
                'status': 'Expired',
            },
        }
        matching_memberships.return_value = memberships_by_email

        # All waivers are expired or missing, so we take the newest membership
        self.assertEqual(
            geardb.membership_expiration(list(memberships_by_email)),
            memberships_by_email['*****@*****.**'],
        )

        # Give the middle membership an active waiver, even though it's not the newest
        middle = memberships_by_email['*****@*****.**']
        middle['waiver'].update(expires=one_month_later, active=True)
        middle['status'] = 'Membership Expired'

        # '*****@*****.**' is not the newest membership, but it has an active waiver
        # (and all other memberships do not have an active waiver)
        self.assertEqual(
            geardb.membership_expiration(list(memberships_by_email)),
            memberships_by_email['*****@*****.**'],
        )
Example #3
0
    def test_split_membership(self, matching_memberships):
        """ We handle a membership and waiver split across two emails. """
        memberships_by_email = {
            '*****@*****.**': {
                'membership': {
                    'expires': None,
                    'active': False,
                    'email': '*****@*****.**'
                },
                'waiver': {
                    'expires': date(2019, 6, 12),
                    'active': True
                },
                'status': 'Missing Membership'
            },
            '*****@*****.**': {
                'membership': {
                    'expires': date(2019, 1, 5),
                    'active': True,
                    'email': '*****@*****.**'
                },
                'waiver': {
                    'expires': None,
                    'active': False
                },
                'status': 'Missing Waiver'
            }
        }

        # All else held equal, most recent memberships are returned first
        matching_memberships.return_value = memberships_by_email
        self.assertEqual(
            geardb.membership_expiration(list(memberships_by_email)),
            memberships_by_email['*****@*****.**'])
Example #4
0
    def test_split_membership(self, matching_memberships):
        """ We handle a membership and waiver split across two emails. """
        memberships_by_email = {
            '*****@*****.**': {
                'membership': {
                    'expires': None,
                    'active': False,
                    'email': '*****@*****.**',
                },
                'waiver': {'expires': date(2019, 6, 12), 'active': True},
                'status': 'Missing Membership',
            },
            '*****@*****.**': {
                'membership': {
                    'expires': date(2019, 1, 5),
                    'active': True,
                    'email': '*****@*****.**',
                },
                'waiver': {'expires': None, 'active': False},
                'status': 'Missing Waiver',
            },
        }

        # All else held equal, most recent memberships are returned first
        matching_memberships.return_value = memberships_by_email
        self.assertEqual(
            geardb.membership_expiration(list(memberships_by_email)),
            memberships_by_email['*****@*****.**'],
        )
Example #5
0
def update_membership_cache(participant):
    """ Use results from the gear database to update membership cache. """
    # If something is found, this method automatically updates the cache
    most_recent = membership_expiration(verified_emails(participant.user))

    # However, if nothing is found, we'll need to set that ourselves
    if not most_recent['membership']['email']:
        participant.update_membership(membership_expires=None, waiver_expires=None)
Example #6
0
def update_membership_cache(participant):
    """ Use results from the gear database to update membership cache. """
    # If something is found, this method automatically updates the cache
    most_recent = membership_expiration(verified_emails(participant.user))

    # However, if nothing is found, we'll need to set that ourselves
    if not most_recent['membership']['email']:
        participant.update_membership(membership_expires=None,
                                      waiver_expires=None)
Example #7
0
    def test_just_most_recent(self, matching_memberships):
        """ When multiple memberships are found, only newest is used. """
        match_tuples = []

        # Mock matching_memberships: a list of matches, newest last
        for i in range(1, 4):
            email = 'member_{}@example.com'.format(i)
            expires = self.tomorrow + timedelta(weeks=1)
            person = self._format_membership(expires, expires, email)
            match_tuples.append((email, person))

        matches = OrderedDict(match_tuples)
        matching_memberships.return_value = matches
        emails = matches.keys()
        newest_membership = match_tuples[-1][1]
        self.assertEqual(newest_membership,
                         geardb_utils.membership_expiration(emails))
Example #8
0
 def test_no_emails_given(self):
     """ Test behavior when we're asking for membership under 0 emails. """
     self.assertEqual(geardb_utils.repr_blank_membership(),
                      geardb_utils.membership_expiration([]))
Example #9
0
 def test_no_membership_found(self, matching_memberships):
     matching_memberships.return_value = OrderedDict()
     emails = ['*****@*****.**', '*****@*****.**']
     self.assertEqual(geardb_utils.repr_blank_membership(),
                      geardb_utils.membership_expiration(emails))