Beispiel #1
0
    def test_get_awardings_of_unawarded_badge(self):
        with self.app.app_context():
            badge = user_badge_service.create_badge('Certificate of Awesomeness', 'awesomeness.svg')

            actual = user_badge_service.get_awardings_of_badge(badge.id)

            self.assertEqual(actual, set())
Beispiel #2
0
    def test_get_awardings_of_unknown_badge(self):
        unknown_badge_id = '00000000-0000-0000-0000-000000000000'

        with self.app.app_context():
            actual = user_badge_service.get_awardings_of_badge(unknown_badge_id)

        self.assertEqual(actual, set())
Beispiel #3
0
def test_award_badge(api_client, api_client_authz_header, user, admin):
    badge = badge_command_service.create_badge('supporter', 'Supporter',
                                               'supporter.svg')

    before = badge_service.get_awardings_of_badge(badge.id)
    assert before == set()

    url = f'/api/user_badges/awardings'
    headers = [api_client_authz_header]
    json_data = {
        'badge_slug': 'supporter',
        'user_id': str(user.id),
        'initiator_id': str(admin.id),
    }

    response = api_client.post(url, headers=headers, json=json_data)
    assert response.status_code == 204

    actual = badge_service.get_awardings_of_badge(badge.id)
    assert actual == {QuantifiedBadgeAwarding(badge.id, user.id, 1)}
Beispiel #4
0
def test_get_awardings_of_badge(app, user1, user2, badge1, awardings_scope):
    badge = badge1

    badge_command_service.award_badge_to_user(badge.id, user1.id)
    badge_command_service.award_badge_to_user(badge.id, user1.id)
    badge_command_service.award_badge_to_user(badge.id, user2.id)

    actual = badge_service.get_awardings_of_badge(badge.id)

    assert actual == {
        QuantifiedBadgeAwarding(badge.id, user1.id, 2),
        QuantifiedBadgeAwarding(badge.id, user2.id, 1),
    }
Beispiel #5
0
    def test_get_awardings_of_badge(self):
        user1 = self.create_user(1)
        user2 = self.create_user(2)

        with self.app.app_context():
            badge = user_badge_service.create_badge('Certificate of Awesomeness', 'awesomeness.svg')

            user_badge_service.award_badge_to_user(badge.id, user1.id)
            user_badge_service.award_badge_to_user(badge.id, user1.id)
            user_badge_service.award_badge_to_user(badge.id, user2.id)

            actual = user_badge_service.get_awardings_of_badge(badge.id)

            self.assertEqual(actual, {
                QuantifiedBadgeAwardingTuple(badge.id, user1.id, 2),
                QuantifiedBadgeAwardingTuple(badge.id, user2.id, 1),
            })
Beispiel #6
0
    def test_get_awardings_of_badge(self):
        user1 = create_user('User1')
        user2 = create_user('User2')

        with self.app.app_context():
            badge = user_badge_service.create_badge(
                'awesomeness', 'Certificate of Awesomeness', 'awesomeness.svg')

            user_badge_service.award_badge_to_user(badge.id, user1.id)
            user_badge_service.award_badge_to_user(badge.id, user1.id)
            user_badge_service.award_badge_to_user(badge.id, user2.id)

            actual = user_badge_service.get_awardings_of_badge(badge.id)

            assert actual == {
                QuantifiedBadgeAwarding(badge.id, user1.id, 2),
                QuantifiedBadgeAwarding(badge.id, user2.id, 1),
            }
Beispiel #7
0
def test_get_awardings_of_unawarded_badge(app, badge3):
    badge = badge3

    actual = badge_service.get_awardings_of_badge(badge.id)

    assert actual == set()
Beispiel #8
0
def test_get_awardings_of_unknown_badge(app):
    unknown_badge_id = '00000000-0000-0000-0000-000000000000'

    actual = badge_service.get_awardings_of_badge(unknown_badge_id)

    assert actual == set()