Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)