-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthew Shirtliffe
committed
Aug 5, 2019
1 parent
ae434b8
commit c0bca14
Showing
7 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import requests | ||
|
||
|
||
def print_header(): | ||
""" Print header | ||
""" | ||
header_text = '' | ||
TEXT = f' Who\'s in space? \n' | ||
line = '-' * len(TEXT) | ||
line += '\n' | ||
|
||
header_text += line | ||
header_text += TEXT | ||
header_text += line | ||
print(header_text) | ||
|
||
|
||
def get_who_is_in_space(): | ||
response = requests.get('http://api.open-notify.org/astros.json') | ||
# response.raise_for_status | ||
if response.ok: | ||
return response | ||
|
||
def print_people_in_space(json): | ||
people = json['people'] | ||
print(f'The are {len(people)} people in space right now:\n') | ||
print('Name | Craft') | ||
for value in people: | ||
name = value['name'] | ||
craft = value['craft'] | ||
print(f'{name} | {craft}') | ||
|
||
if __name__ == "__main__": | ||
print_header() | ||
response = get_who_is_in_space() | ||
json = response.json() | ||
print_people_in_space(json) |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from unittest import TestCase | ||
from unittest.mock import patch, call | ||
import app | ||
|
||
class AppTest(TestCase): | ||
|
||
def test_print_header(self): | ||
|
||
expected = '------------------\n Who\'s in space? \n------------------\n' | ||
with patch('builtins.print') as mocked_print: | ||
app.print_header() | ||
mocked_print.assert_called_with(expected) | ||
|
||
|
||
def test_get_who_is_in_space(self): | ||
|
||
response_json = {'message': 'success', 'people': [{'name': 'Alexey Ovchinin', 'craft': 'ISS'}, {'name': 'Nick Hague', 'craft': 'ISS'}, {'name': 'Christina Koch', 'craft': 'ISS'}, {'name': 'Alexander Skvortsov', 'craft': 'ISS'}, {'name': 'Luca Parmitano', 'craft': 'ISS'}, {'name': 'Andrew Morgan', 'craft': 'ISS'}], 'number': 6} | ||
with patch('requests.get') as mocked_request_get: | ||
mocked_request_get.return_value.status_code = 200 | ||
mocked_request_get.return_value.json.return_value = response_json | ||
response = app.get_who_is_in_space() | ||
self.assertEqual(response.status_code, 200) | ||
mocked_request_get.assert_called_with('http://api.open-notify.org/astros.json') | ||
self.assertEqual(response.json(), response_json) | ||
|
||
|
||
def test_print_people_in_space(self): | ||
|
||
expected = [ | ||
call('The are 6 people in space right now:\n'), | ||
call('Name | Craft'), | ||
call('Alexey Ovchinin | ISS'), | ||
call('Nick Hague | ISS'), | ||
call('Christina Koch | ISS'), | ||
call('Alexander Skvortsov | ISS'), | ||
call('Luca Parmitano | ISS'), | ||
call('Andrew Morgan | ISS') | ||
] | ||
with patch('builtins.print') as mocked_print: | ||
response_json = {'message': 'success', 'people': [{'name': 'Alexey Ovchinin', 'craft': 'ISS'}, {'name': 'Nick Hague', 'craft': 'ISS'}, {'name': 'Christina Koch', 'craft': 'ISS'}, {'name': 'Alexander Skvortsov', 'craft': 'ISS'}, {'name': 'Luca Parmitano', 'craft': 'ISS'}, {'name': 'Andrew Morgan', 'craft': 'ISS'}], 'number': 6} | ||
app.print_people_in_space(response_json) | ||
mocked_print.assert_has_calls(expected) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from unittest import TestCase | ||
import app | ||
|
||
class FilteringRecordsTest(TestCase): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
badger badger badger badger mushroom mushroom | ||
snake badger badger badger |