Skip to content

Commit 7ea0837

Browse files
author
Reijonen Pekka
committed
A task to mocking requests.get function
1 parent 5f02d2a commit 7ea0837

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

pipeLine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
def getData():
1919
# url = 'http://web.mta.info/developers/turnstile.html'
2020
url = 'http://api.worldbank.org/v2/country/all/indicator/SP.POP.TOTL?format=json'
21-
response = requests.get(url)
21+
response = requests.get(url) # task: mock this function. if applicable use with your own data source (URL)
2222
return response
2323

2424

tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import awesome
44
import example_pkg
5+
import pipeLine
56

7+
url = 'http://api.worldbank.org/v2/country/all/indicator/SP.POP.TOTL?format=json'
68

79
class TestMethods(unittest.TestCase):
810
def test_add(self):
11+
# call to function changing some "global" data structure
12+
# assert function is checking that the change you expected happens properly.
913
self.assertEqual(awesome.smile(), ":)")
1014

1115
def test_anotherOne(self):
@@ -14,6 +18,10 @@ def test_anotherOne(self):
1418
bazres = example_pkg.baz_func()
1519
self.assertRegexpMatches(barres,".*bar.*")
1620

21+
def test_pipeline(self):
22+
result = pipeLine.getData(url)
23+
self.assertRegexpMatches(barres,".*bar.*")
24+
1725

1826
if __name__ == '__main__':
1927
unittest.main()

0 commit comments

Comments
 (0)