architv / soccer-cli

:soccer: Football scores for hackers. :computer: A command line interface for all the football scores.
MIT License
1.09k stars 221 forks source link

Adding integration tests #84

Open carlosvargas opened 8 years ago

carlosvargas commented 8 years ago

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 commented 8 years ago

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.

ueg1990 commented 8 years ago

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

carlosvargas commented 8 years ago

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

ueg1990 commented 8 years ago

ah....didnt know that

Saturn commented 8 years ago

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 :+1: