Skip to content

Instantly share code, notes, and snippets.

@guyjacks
Created September 15, 2017 19:50
Show Gist options
  • Save guyjacks/0c54ba57ce013acfe416fc85071493c7 to your computer and use it in GitHub Desktop.
Save guyjacks/0c54ba57ce013acfe416fc85071493c7 to your computer and use it in GitHub Desktop.
@pytest.fixture
def mock_user_fixtures():
u1 = UserFactory()
u2 = UserFactory()
return (u1, u2,)
@pytest.fixture
def mock_organization_fixtures():
o1 = OrganizationFactory()
o2 = OrganizationFactory()
return (o1, o2,)
@pytest.fixture
def mock_badge_fixtures(mock_organization_fixtures):
o1, o2 = mock_organization_fixtures
# organization 1 #
# This badge can be earned an UNLIMITED number of times
b1 = BadgeFactory(organization=o1, limit=None, limit_period=None)
# This badge can be earned only ONCE per MONTH
b2 = BadgeFactory(organization=o1, limit=1, limit_period=Badge.MONTHLY)
# This badge can be earned only TWICE per MONTH
b3 = BadgeFactory(organization=o1, limit=2, limit_period=Badge.MONTHLY)
# organization 2 #
# This badge can be earned an UNLIMITED number of times
b4 = BadgeFactory(organization=o2, limit=None, limit_period=None)
# This badge can be earned only ONCE per MONTH
b5 = BadgeFactory(organization=o2, limit=1, limit_period=Badge.MONTHLY)
return (b1, b2, b3, b4, b5,)
@pytest.fixture
def mock_badge_user_fixtures(mock_badge_fixtures, mock_user_fixtures):
u1, u2 = mock_user_fixtures
b1, b2, b3, b4, b5 = mock_badge_fixtures
#### User 1 - Organization 1 - January 2017 ####
# The user CAN earn this badge unlimited times
bu1 = BadgeUserFactory(badge=b1, user=u1, created=datetime.datetime(2017, 1, 1))
# The user canNOT earn this badge again in January
bu2 = BadgeUserFactory(badge=b2, user=u1, created=datetime.datetime(2017, 1, 10))
# The user CAN earn this badge ONCE MORE in January
bu3 = BadgeUserFactory(badge=b3, user=u1, created=datetime.datetime(2017, 1, 31))
#### User 1 - Organization 2 - January 2017 ####
# The user CAN earn this badge unlimited times
bu4 = BadgeUserFactory(badge=b4, user=u1, created=datetime.datetime(2017, 1, 27))
# The user canNOT earn this badge again in January
bu5 = BadgeUserFactory(badge=b5, user=u1, created=datetime.datetime(2017, 1, 29))
#### User 1 - Organization 1 - February 2017 ####
# The user CAN earn this badge ONCE MORE in February
bu6 = BadgeUserFactory(badge=b3, user=u1, created=datetime.datetime(2017, 2, 10))
#### User 2 - Organization 1 - January 2017 ####
# The user CAN earn this badge unlimited times
bu7 = BadgeUserFactory(badge=b1, user=u2, created=datetime.datetime(2017, 1, 1))
# The user canNOT earn this badge again in January
bu8 = BadgeUserFactory(badge=b2, user=u2, created=datetime.datetime(2017, 1, 31))
#### User 2 - Organization 2 - January 2017 ####
# The user canNOT earn this badge again in February
bu9 = BadgeUserFactory(badge=b5, user=u2, created=datetime.datetime(2017, 1, 29))
return (bu1, bu2, bu3, bu4, bu5, bu6, bu7, bu8, bu9,)
@pytest.mark.django_db
def test_earned_during_month(mock_user_fixtures, mock_badge_user_fixtures):
u1, u2 = mock_user_fixtures
bu1, bu2, bu3, bu4, bu5, bu6, bu7, bu8, bu9 = mock_badge_user_fixtures
month, year = 1, 2017,
#actual = u1.badges.earned_during_month(month, year)
actual = Badge.objects.earned_during_month(month, year)
print(list(actual))
assert False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment