Ejemplo n.º 1
0
	def test_should_follow_url_for_follow_action(self):
		selector = "div[class=content]|a[1]"
		xform = transform.FollowTransform(owner=fixtures.a_user, selector=selector, host_match='localhost', name='blah')
		html = """
			<body>
				<div class="content">
					<a href="http://not_this">blah</a>
					<a href="http://linked_url">blah</a>
					<a href="http://or_this">blah</a>
				</div>
			</body>
			"""
		page = mock('page').with_children(host='')
		expect(page).use_content_url('http://linked_url')
		xform.apply(page, b_soup(html))
		page._fetch_raw_content()
Ejemplo n.º 2
0
	def assertExtraction(self, content, selector, expected_results):
		soup = b_soup(content)
		results = transform.apply_selector(soup, selector)
		string_results = map(str, results)
		self.assertEqual(string_results, expected_results)
Ejemplo n.º 3
0
	def test_should_not_follow_url_when_selection_fails(self):
		selector = "div[class=content]|a[1]"
		xform = transform.FollowTransform(owner=fixtures.a_user, action='follow', selector=selector, host_match='localhost', name='test_transform')
		html = """
			<body>
				<div class="not_content">
					<a href="http://not_this">blah</a>
				</div>
			</body>
			"""
		page = mock('page').with_children(raw_content=html)
		expect(page).use_content_url.never()
		expect(page).error("transform FollowTransform failed: no links found")
		self.assertRaises(transform.TransformError, lambda: transform.Transform.apply_transform(xform, page, b_soup(html)))