コード例 #1
0
def test_register_existing_badge():
    b = BadgePrototype("test.testbadge3")
    register_badge(b)

    b2 = BadgePrototype("test.testbadge3")

    register_badge(b2)
コード例 #2
0
def test_award_fail_precond():
    ds = Mock()

    badge_id = "test.testbadge2"
    badge = BadgePrototype(badge_id)
    badge._precondition = Mock(return_value=False)

    user = Mock()
    user.operant_id.return_value = 1010

    callback = Mock()

    badge.award(ds, user, callback)
    badge._precondition.assert_called_once()
    callback.assert_called_once_with(False)
コード例 #3
0
def test_award():
    ds = Mock()
    ds.add_badge.side_effect = lambda user, badge, cb: cb(True)

    badge_id = "test.testbadge2"
    badge = BadgePrototype(badge_id)

    callback = Mock()

    user = Mock()
    user.operant_id.return_value = 1010

    badge.award(ds, user, callback)
    callback.assert_called_once_with(badge)

    ds.track_event.assert_called_once_with('badge.awarded.test.testbadge2',1010)
コード例 #4
0
def test_no_dupes():
    ds = dprovider()
    ds.add_badge.side_effect = lambda user, badge, cb: cb(False)

    user = Mock()
    user.operant_id.return_value = 1010

    badge_id = "test.testbadge1"
    badge = BadgePrototype(badge_id)

    callback = Mock()
    badge.award(ds, user, callback)

    callback.assert_called_once_with(False)

    # not added to logs
    eq_(len(ds.track_event.mock_calls),0)
コード例 #5
0
def test_register_badge():
    b = BadgePrototype("test.testbadge4")
    register_badge(b)

    eq_(get_badge("test.testbadge4"),b)