def test_admin_page_contains_title_url_and_category(self): #Populate database populate_rango.populate() url = self.live_server_url url = url.replace('localhost', '127.0.0.1') self.browser.get(url + reverse('admin:index')) # Log in the admin page test_utils.login(self) # Click in Pages pages_link = self.browser.find_element_by_link_text('Pages') pages_link.click() body = self.browser.find_element_by_tag_name('body') # Get all pages pages = Page.objects.all() # Check all pages title, category and url are displayed for page in pages: self.assertIn(page.title, body.text) # self.assertIn(page.category.name, body.text) self.assertIn(page.url, body.text) # Check for the Github account and PythonAnywhere account body = self.browser.find_element_by_tag_name('body') self.assertIn('http://www.djangorocks.com/', body.text) self.assertIn('http://flask.pocoo.org', body.text)
def test_population_script(self): #Populate database populate_rango.populate() url = self.live_server_url #url = url.replace('localhost', '127.0.0.1') self.browser.get(url + reverse('admin:index')) # Log in the admin page test_utils.login(self) # # Check if is there link to categories # category_link = self.browser.find_elements_by_partial_link_text('Categor') # print(category_link[0].text) # category_link[0].click() # Check for the categories saved by the population script # self.browser.find_elements_by_partial_link_text('Other Frameworks') # self.browser.find_elements_by_partial_link_text('Django') # self.browser.find_elements_by_partial_link_text('Python') # Check the pages saved by the population script self.browser.get(url + reverse('admin:rango_page_changelist')) self.browser.find_elements_by_partial_link_text('Flask') self.browser.find_elements_by_partial_link_text('Bottle') self.browser.find_elements_by_partial_link_text( 'How to Tango with Django') self.browser.find_elements_by_partial_link_text( 'Official Django Tutorial') self.browser.find_elements_by_partial_link_text('Django Rocks') self.browser.find_elements_by_partial_link_text( 'Learn Python in 10 Minutes') self.browser.find_elements_by_partial_link_text( 'How to Think like a Computer Scientist') self.browser.find_elements_by_partial_link_text( 'Official Python Tutorial')
def test_can_create_new_category_via_admin_site(self): #Access admin page url = self.live_server_url url = url.replace('localhost', '127.0.0.1') self.browser.get(url + reverse('admin:index')) # Check if it display admin message body = self.browser.find_element_by_tag_name('body') self.assertIn('Django administration', body.text) # Log in the admin page test_utils.login(self) # the Site Administration page body = self.browser.find_element_by_tag_name('body') self.assertIn('Site administration', body.text) # Check if is there link to categories category_link = self.browser.find_elements_by_partial_link_text( 'Categor') self.assertEquals(len(category_link), 1) # Click in the link category_link[0].click() # Empty, so check for the empty message body = self.browser.find_element_by_tag_name('body') self.assertIn('0 categor', body.text.lower()) # Add a category by clicking on 'Add category # new_poll_link = self.browser.find_element_by_link_text('Add category') new_poll_link = self.browser.find_element_by_class_name('addlink') new_poll_link.click() # Check for input field body = self.browser.find_element_by_tag_name('body') self.assertIn('Name:'.lower(), body.text.lower()) # Input category name category_field = self.browser.find_element_by_name('name') category_field.send_keys("Test Driven Development") # Leave likes and views as 0 # Gertrude clicks the save button save_button = self.browser.find_element_by_css_selector( "input[value='Save']") save_button.click()
def test_admin_contains_user_profile(self): # Access admin page url = self.live_server_url url = url.replace('localhost', '127.0.0.1') self.browser.get(url + reverse('admin:index')) # Log in the admin page test_utils.login(self) # Check exists a link to user profiles self.browser.find_element_by_link_text('User profiles').click() # Check it is empty body = self.browser.find_element_by_tag_name('body') self.assertIn('0 user profiles', body.text) # create a user user, user_profile = test_utils.create_user() self.browser.refresh() # Check there is one profile body = self.browser.find_element_by_tag_name('body')