class test_executions(): def setUp(self): self.page = Page('This page only contains text content.') def test_page_should_be_runnable_even_without_a_script(self): assert self.page.run() def test_should_puke_when_scripts_error(self): self.page.script = Script('assert False == True') assert False in self.page.run() def test_script_should_have_access_to_page(self): script_body = 'assert page.content == "This page only contains text content."' self.page.script = Script(script_body) assert self.page.run() == True def test_script_should_be_able_to_modify_page_content(self): self.page.script = Script( 'page.content = page.content.replace("only", "just")') self.page.run() assert self.page.content == 'This page just contains text content.'
def crawl_general_page_info(self): print("Get general page info for", self.page_name) log.info("Get general page info for", self.page_name) def get_instagram_field_number(expression): # Get instagram field from regular expression num_info = regex.search(expression, self.browser.page_source).group() field_number = int(regex.findall(r'\d+', num_info)[0]) return field_number # create new page new_page = PageComponent( page_name=self.page_name, directory=self.directory ) # go to page self.go_to_page(new_page) if not new_page.is_hash_tag(): following = get_instagram_field_number(config.USER_FOLLOWING_REGEX) followers = get_instagram_field_number(config.USER_FOLLOWERS_REGEX) # update page info new_page.set_followers(followers) new_page.set_following(following) # Get total number of posts in page num_of_posts = get_instagram_field_number(config.USER_POST_COUNT_REGEX) # validate post number self.posts_number = min(self.posts_number, num_of_posts) new_page.set_posts(self.posts_number) # set current page attribute self.page = new_page print("Obtained general page info for", self.page_name) log.info("Obtained general page info for", self.page_name)
def setUp(self): self.page = Page('This page only contains text content.')