Beispiel #1
0
	def login(self, username, password):
		url = "https://elearning.uni-heidelberg.de/login/index.php"
		auth = { "username" : username, "password" : password }
		response = self.web.post(url, auth)
		content = response.read()
		markup = parse(content)
		self.logged_in = "Sie sind angemeldet als" in markup.getText()
Beispiel #2
0
	def test_should_find_all_anchors_in_markup(self):
		html = """<div id="content">
				<a href="#">Link 1</a>
				<a href="#">Link 2</a>
			</div>"""
		markup = parse(html)
		page = Page(markup, None)
		anchors = page.find_links_in_content(markup)
		self.assertEqual(len(anchors), 2)
Beispiel #3
0
	def test_should_not_find_anchors_outside_of_the_content_container(self):
		html = """<div id="content">
					<a href="#">Link 1</a>
				</div>
				<a href="#">Link 2</a>"""

		markup = parse(html)
		page = Page(markup, None)
		anchors = page.find_links_in_content(markup)
		self.assertEqual(len(anchors), 1)
Beispiel #4
0
	def test_should_return_recursive_results_when_the_content_type_contains_encoding(self):
		html = """<div id="content">
				<a href="view.php?id=1111">Page</a>
			</div>
		"""
		web = FakeWebResponses()
		markup = parse(html)
		page = Page(markup, web)
		file = page.resources()[0]

		self.assertEqual("File 1", file.name)
		self.assertEqual("http://elearning.uni-heidelberg.de/mod/resource/view.php?id=123", file.url)
Beispiel #5
0
	def test_print_the_appropriate_pages(self):
		html = """<div id="content">
			<a href="view.php?id=123">File</a>
			<a href="view.php?id=345">Page</a>
			<a href="view.php?id=567">File</a>
			</div>
		"""
		web = FakeWebResponses()
		markup = parse(html)
		page = Page(markup, web)
		file = page.resources()[0]

		self.assertEqual("File", file.name)
		self.assertEqual("http://elearning.uni-heidelberg.de/mod/resource/view.php?id=123", file.url)
Beispiel #6
0
	def test_the_weasel_recursive(self):
		html = """<div id="content">
			<a href="view.php?id=123">File</a>
			<a href="view.php?id=345">Page</a>
			<a href="view.php?id=567">File</a>
			</div>
		"""
		web = FakeWebResponses()

		markup = parse(html)
		page = Page(markup, web)

		files = page.resources()
		self.assertEqual(4, len(files))
Beispiel #7
0
def anchor(text):
	return parse(text).findAll("a").pop()
Beispiel #8
0
	def material_page_for(self, course_id):
		url = ("http://elearning.uni-heidelberg.de/mod/resource/index.php?id=%s" % course_id)
		response = self.web.get(url)
		content = response.read()
		markup = parse(content)
		return Page(markup, self.web)
Beispiel #9
0
	def my_courses(self):
		url = "http://elearning.uni-heidelberg.de/my/index.php"
		response = self.web.get(url)
		content = response.read()
		markup = parse(content)
		return Courses(markup).all()
Beispiel #10
0
	def test_should_initialize_page_with_markup_that_has_been_parsed_already(self):
		markup = parse("")
		page = Page(markup, None)
		self.assertTrue(isinstance(page.markup, BeautifulSoup))
Beispiel #11
0
	def __init__(self, markup, web=None):
		if isinstance(markup, basestring):
			markup = parse(markup)
		self.markup = markup
		self.web = web