-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_file.py
29 lines (21 loc) · 905 Bytes
/
test_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import unittest
import requests
from bs4 import BeautifulSoup as BS
from searchurl import search_url
from scraping import scrape
class Testing(unittest.TestCase):
def test_search_url(self):
# Makes sure no url is returned when match for company name is not found
company_name = "random"
url = search_url(company_name)
self.assertIsNone(url)
def test_scrape(self):
# Makes sure empty dicts are returned when neither bse nor nse is found for company. For example: SBI Magnum Express
url = 'http://www.moneycontrol.com/india/stockpricequote/finance-investments/sbimagnumexpress/SBI06'
company_url = requests.get(url)
soup = BS(company_url.text, "html.parser")
b, n = scrape(soup)
self.assertEqual(b, {})
self.assertEqual(n, {})
if __name__ == '__main__':
unittest.main()