def test_perform_get_scores_empty(): fake_scores = defer.Deferred() results = None fake_scores.callback(results) fake_get_scores = mock.Mock(return_value = fake_scores) fake_responder = mock.Mock() with mock.patch('scores_db.scores.get_match_scores', fake_get_scores): options = { '<match-id>': 1, '<tla>': 'ABC' } # Run the command scores_db.perform_get_scores(fake_responder, options) # Assert that the right things were called fake_get_scores.assert_called_once_with(1) # Check that the right text was output fake_responder.assert_called_once('No scores available for match 1')
def test_perform_get_scores_yaml(): fake_scores = defer.Deferred() results = {'ABC':1, 'DEF':4} fake_scores.callback(results) fake_get_scores = mock.Mock(return_value = fake_scores) fake_responder = mock.Mock() with mock.patch('scores_db.scores.get_match_scores', fake_get_scores): options = { '<match-id>': 1, '<tla>': 'ABC', '--yaml': True } # Run the command scores_db.perform_get_scores(fake_responder, options) # Assert that the right things were called fake_get_scores.assert_called_once_with(1) # Check that the right text was output fake_responder.assert_called_once_with(yaml.dump({'scores':results}))
def test_perform_get_scores(): fake_scores = defer.Deferred() results = {'ABC':1, 'DEF':4} fake_scores.callback(results) fake_get_scores = mock.Mock(return_value = fake_scores) fake_responder = mock.Mock() with mock.patch('scores_db.scores.get_match_scores', fake_get_scores): options = { '<match-id>': 1, '<tla>': 'ABC' } # Run the command scores_db.perform_get_scores(fake_responder, options) # Assert that the right things were called fake_get_scores.assert_called_once_with(1) # Check that the right text was output fake_responder.assert_has_calls([mock.call('Team ABC scored 1 in match 1'), mock.call('Team DEF scored 4 in match 1')], any_order = True)