-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_tests.py
36 lines (25 loc) · 919 Bytes
/
update_tests.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
30
31
32
33
34
35
36
import unittest
import urllib2
from bs4 import BeautifulSoup
from urlparse import urljoin
class RetrieveTest(unittest.TestCase):
BASE_URL = 'http://reutilitza.cat'
VERBOSE = False
def get_url(self, path):
url = urljoin(self.BASE_URL, path)
response = urllib2.urlopen(url)
if self.VERBOSE:
print(response.getcode())
print(response.info())
return response
def get_title(self, content):
# http://www.crummy.com/software/BeautifulSoup/bs4/doc/
soup = BeautifulSoup(content)
return soup.title.string
def test_root(self):
response = self.get_url('/')
self.assertEqual(200, response.getcode())
title = self.get_title(response.read())
self.assertEqual('Projectes socials | reutilitza.cat', title)
if __name__ == '__main__':
unittest.main()