def test_calc_league_points_empty_yaml(): fake_scores = defer.Deferred() match_results = None fake_scores.callback(match_results) fake_get_scores = mock.Mock(return_value = fake_scores) fake_dsqs = defer.Deferred() fake_dsqs.callback([]) fake_get_dsqs = mock.Mock(return_value = fake_dsqs) results = {'ABC':3.0, 'FED': 4.0} fake_ranker = mock.Mock(return_value = results) fake_set_league_pts = mock.Mock() fake_responder = mock.Mock() with mock.patch('ranker.get_ranked_points', fake_ranker), \ mock.patch('scores_db.scores.get_match_scores', fake_get_scores), \ mock.patch('scores_db.scores.set_league_points', fake_set_league_pts), \ mock.patch('scores_db.scores.teams_disqualified_in_match', fake_get_dsqs): options = { '<match-id>': 1, '--yaml': True } # Run the command scores_db.perform_calc_league_points(fake_responder, options) # Assert that the right things were called fake_get_scores.assert_called_once_with(1) assert not fake_get_dsqs.called assert not fake_ranker.called assert not fake_set_league_pts.called # Check that the right text was output fake_responder.assert_called_once_with(yaml.dump({'points':None}))
def test_calc_league_points(): fake_scores = defer.Deferred() match_results = {'ABC':2, 'FED':4, 'GHI':18} dsqs = ['GHI'] fake_scores.callback(match_results) fake_get_scores = mock.Mock(return_value = fake_scores) fake_dsqs = defer.Deferred() fake_dsqs.callback(dsqs) fake_get_dsqs = mock.Mock(return_value = fake_dsqs) results = {'ABC':3.0, 'FED': 4.0} fake_ranker = mock.Mock(return_value = results) fake_set_league_pts = mock.Mock() fake_responder = mock.Mock() with mock.patch('ranker.get_ranked_points', fake_ranker), \ mock.patch('scores_db.scores.get_match_scores', fake_get_scores), \ mock.patch('scores_db.scores.set_league_points', fake_set_league_pts), \ mock.patch('scores_db.scores.teams_disqualified_in_match', fake_get_dsqs): options = { '<match-id>': 1 } # Run the command scores_db.perform_calc_league_points(fake_responder, options) # Assert that the right things were called fake_get_scores.assert_called_once_with(1) fake_get_dsqs.assert_called_once_with(1) fake_ranker.assert_called_once_with(match_results, dsqs) fake_set_league_pts.assert_called_once_with(1, results) # Check that the right text was output fake_responder.assert_has_calls([mock.call('Team ABC earned 3.0 points from match 1'), mock.call('Team FED earned 4.0 points from match 1')], any_order = True)