Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding integration tests #84

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Adding integration tests #84

wants to merge 5 commits into from

Conversation

carlosvargas
Copy link
Collaborator

This adds some integration tests for the most basic commands by comparing the stdout output after we have parsed it. This is to help prevent changes to formatting, unicode text not displaying, etc.

It uses Betamax to modify reqests so that we can save the request body to a file. It will then use this file in any subsequent calls so that the "response" for a specific endpoint is always the same.

I'm also using click.testing.CliRunner.isolation function (src) so that I can easily get a hold of the stdout output.

@carlosvargas
Copy link
Collaborator Author

Bah, just realized that I could have written:

with self.recorder.use_cassette(cassette_name):
           with self.cli_runner.isolation() as runner:

like

with self.recorder.use_cassette(cassette_name) as cassette, self.cli_runner.isolation() as runner:

if anyone wants to, I could change it to the latter.

soccer.main.get_team_scores(team, time, self.writer, upcoming, use12hour)
assert self.get_output(runner) == '\nArsenal FC - vs - Crystal Palace FC Sun 17, 08:00\n'

def test_team_upcoming_games_with_local_time(self):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh just realized this would completely fail in any machine with a different timezone than me 😛

@ueg1990
Copy link
Collaborator

ueg1990 commented Apr 15, 2016

@carlosvargas for nested context managers...you can use contextlib.nested
http://stackoverflow.com/a/3025119/1510751

@@ -65,7 +70,7 @@ def load_config_key():

def _get(url):
"""Handles api.football-data.org requests"""
req = requests.get(BASE_URL+url, headers=headers)
req = session.get(BASE_URL+url, headers=headers)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not concatenate BASE_URL and url....use urlparse library

@carlosvargas
Copy link
Collaborator Author

carlosvargas commented Apr 15, 2016

@ueg1990 contextlib.nested has been deprecated since 2.7 (https://docs.python.org/2/library/contextlib.html#contextlib.nested)

@ueg1990
Copy link
Collaborator

ueg1990 commented Apr 15, 2016

ah....didnt know that

@Saturn
Copy link
Collaborator

Saturn commented Apr 22, 2016

I wrote some unit tests a while ago using https://github.com/patrys/httmock

I manually saved the json data.

Never ended up trying to merge them. I think I had forgot about it...

I will have a look at all these changes when I get time. Looks interesting 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants