def test_add_category_when_logged(self):
        # Access login page
        url = self.live_server_url
        url = url.replace('localhost', '127.0.0.1')
        try:
            self.browser.get(url + reverse('login'))
        except:
            try:
                self.browser.get(url + reverse('rango:login'))
            except:
                return False

        # Log in
        test_utils.user_login(self)

        # Click category
        self.browser.find_element_by_partial_link_text(
            'Add a New Category').click()

        # Types new category name
        username_field = self.browser.find_element_by_name('name')
        username_field.send_keys('New Category')

        # Click on Create Category
        self.browser.find_element_by_css_selector(
            "input[type='submit']").click()

        body = self.browser.find_element_by_tag_name('body')

        # Check if New Category appears in the index page
        self.assertIn('New Category', body.text)
    def test_links_in_index_page_when_logged(self):
        # Access login page
        url = self.live_server_url
        url = url.replace('localhost', '127.0.0.1')
        try:
            self.browser.get(url + reverse('login'))
        except:
            try:
                self.browser.get(url + reverse('rango:login'))
            except:
                return False

        # Log in
        test_utils.user_login(self)

        #Check links that appear for logged person only
        self.browser.find_element_by_link_text('Add a New Category')
        self.browser.find_element_by_link_text('Restricted Page')
        self.browser.find_element_by_link_text('Logout')
        self.browser.find_element_by_link_text('About')

        # Check that links does not appears for logged users
        body = self.browser.find_element_by_tag_name('body')
        self.assertNotIn('Sign In', body.text)
        self.assertNotIn('Sign Up', body.text)
    def test_logged_user_message_in_index(self):
        # Access login page
        url = self.live_server_url
        url = url.replace('localhost', '127.0.0.1')
        try:
            self.browser.get(url + reverse('login'))
        except:
            try:
                self.browser.get(url + reverse('rango:login'))
            except:
                return False

        # Log in
        test_utils.user_login(self)

        # Check for the username in the message
        body = self.browser.find_element_by_tag_name('body')
        self.assertIn('admin', body.text)
    def test_add_page_when_logged(self):
        #Create categories
        test_utils.create_categories()

        # Access login page
        url = self.live_server_url
        url = url.replace('localhost', '127.0.0.1')
        try:
            self.browser.get(url + reverse('login'))
        except:
            try:
                self.browser.get(url + reverse('rango:login'))
            except:
                return False

        # Log in
        test_utils.user_login(self)

        # Click category
        self.browser.find_element_by_partial_link_text('Category').click()

        # Click add page
        try:
            self.browser.find_element_by_partial_link_text("Add").click()
        except:
            self.browser.find_element_by_partial_link_text("add").click()

        # Types new page name
        username_field = self.browser.find_element_by_name('title')
        username_field.send_keys('New Page')

        # Types url for the page
        username_field = self.browser.find_element_by_name('url')
        username_field.send_keys('http://www.newpage.com')

        # Click on Create Page
        self.browser.find_element_by_css_selector(
            "input[type='submit']").click()

        body = self.browser.find_element_by_tag_name('body')

        # Check if New Page appears in the category page
        self.assertIn('New Page', body.text)
    def test_logout_link(self):
        # Access login page
        url = self.live_server_url
        url = url.replace('localhost', '127.0.0.1')
        try:
            self.browser.get(url + reverse('login'))
        except:
            try:
                self.browser.get(url + reverse('rango:login'))
            except:
                return False

        # Log in
        test_utils.user_login(self)

        #Clicks to logout
        self.browser.find_element_by_link_text('Logout').click()

        # Check if it see log in link, thus it is logged out
        self.browser.find_element_by_link_text('Sign In')
    def test_access_restricted_page_when_logged(self):
        # Access login page
        url = self.live_server_url
        url = url.replace('localhost', '127.0.0.1')
        try:
            self.browser.get(url + reverse('login'))
        except:
            try:
                self.browser.get(url + reverse('rango:login'))
            except:
                return False

        # Log in
        test_utils.user_login(self)

        # Access restricted page
        self.browser.find_element_by_link_text('Restricted Page').click()

        # Check that a message is displayed
        body = self.browser.find_element_by_tag_name('body')
        self.assertIn("Since you're logged in, you can see this text!".lower(),
                      body.text.lower())