def test_result_object_failed_with_element_def_not_matching_any_element(self): html_src = """ <html> <p>Content found</p> </html> """ heading_not_found_def = text('Heading not found') text_not_found_def = text('Text not found') spec = html( heading_not_found_def, text('Content found'), text_not_found_def ) result = html_match(spec, html_src) self.assertEquals(spec, result.spec) self.assertEquals(html_src, result.html_src) self.assertIsNotNone(result.root_element) self.assertFalse(result.passed) self.assertTrue(result.failed) self.assertEquals(2, len(result.element_defs_not_found)) self.assertIn(heading_not_found_def, result.element_defs_not_found) self.assertIn(text_not_found_def, result.element_defs_not_found) self.assertEquals(heading_not_found_def, result.failed_on_def)
def test_result_object_passing(self): html_src = """ <html> <p>Content found</p> </html> """ spec = html(text('Content found')) result = html_match(spec, html_src) self.assertEquals(spec, result.spec) self.assertEquals(html_src, result.html_src) self.assertIsNotNone(result.root_element) self.assertTrue(result.passed) self.assertFalse(result.failed) self.assertEquals(0, len(result.element_defs_not_found)) self.assertIsNone(result.failed_on_def)
def test_index(self, ec2idmock): # the available ec2ids ec2idmock.return_value = ['ec2ida', 'ec2idb'] # That a request for the root resource response = self.test_client.get('/') # Is successful self.assertEqual(response.status_code, 200) # and returns valid HTML self.assertTrue(svalid(response.data)) spec = pha.html(pha.option("ec2ida"), pha.option("ec2idb")) # and contains the two EC2 instance IDs results = pha.html_match(spec, response.data) self.assertTrue(results.passed)
def test_result_object_failed_with_matcher_not_matched_because_html_out_of_order(self): html_src = """ <html> <p>Content found</p> <h1>Heading not found</h1> </html> """ heading_not_found_def = text('Heading not found') spec = html( heading_not_found_def, text('Content found'), ) result = html_match(spec, html_src) self.assertEquals(spec, result.spec) self.assertEquals(html_src, result.html_src) self.assertIsNotNone(result.root_element) self.assertFalse(result.passed) self.assertTrue(result.failed) self.assertEquals(0, len(result.element_defs_not_found)) self.assertEquals(heading_not_found_def, result.failed_on_def)
def test_result_object_failed_with_matcher_not_matched_because_html_out_of_order( self): html_src = """ <html> <p>Content found</p> <h1>Heading not found</h1> </html> """ heading_not_found_def = text('Heading not found') spec = html( heading_not_found_def, text('Content found'), ) result = html_match(spec, html_src) self.assertEquals(spec, result.spec) self.assertEquals(html_src, result.html_src) self.assertIsNotNone(result.root_element) self.assertFalse(result.passed) self.assertTrue(result.failed) self.assertEquals(0, len(result.element_defs_not_found)) self.assertEquals(heading_not_found_def, result.failed_on_def)
def test_result_object_failed_with_element_def_not_matching_any_element( self): html_src = """ <html> <p>Content found</p> </html> """ heading_not_found_def = text('Heading not found') text_not_found_def = text('Text not found') spec = html(heading_not_found_def, text('Content found'), text_not_found_def) result = html_match(spec, html_src) self.assertEquals(spec, result.spec) self.assertEquals(html_src, result.html_src) self.assertIsNotNone(result.root_element) self.assertFalse(result.passed) self.assertTrue(result.failed) self.assertEquals(2, len(result.element_defs_not_found)) self.assertIn(heading_not_found_def, result.element_defs_not_found) self.assertIn(text_not_found_def, result.element_defs_not_found) self.assertEquals(heading_not_found_def, result.failed_on_def)
def assert_match(self, html_src, spec): result = html_match(spec, html_src) print(unicode(result)) self.assertTrue(result.passed)