def test_branch_is_a_link(self, pr_util):
        pull_request = pr_util.create_pull_request()
        pull_request.source_ref = 'branch:origin:1234567890abcdef'
        pull_request.target_ref = 'branch:target:abcdef1234567890'
        Session().add(pull_request)
        Session().commit()

        response = self.app.get(url(
            controller='pullrequests', action='show',
            repo_name=pull_request.target_repo.scm_instance().name,
            pull_request_id=str(pull_request.pull_request_id)))
        assert response.status_int == 200
        assert_response = AssertResponse(response)

        origin = assert_response.get_element('.pr-origininfo .tag')
        origin_children = origin.getchildren()
        assert len(origin_children) == 1
        target = assert_response.get_element('.pr-targetinfo .tag')
        target_children = target.getchildren()
        assert len(target_children) == 1

        expected_origin_link = url(
            'changelog_home',
            repo_name=pull_request.source_repo.scm_instance().name,
            branch='origin')
        expected_target_link = url(
            'changelog_home',
            repo_name=pull_request.target_repo.scm_instance().name,
            branch='target')
        assert origin_children[0].attrib['href'] == expected_origin_link
        assert origin_children[0].text == 'branch: origin'
        assert target_children[0].attrib['href'] == expected_target_link
        assert target_children[0].text == 'branch: target'
    def test_tag_is_not_a_link(self, pr_util):
        pull_request = pr_util.create_pull_request()
        pull_request.source_ref = 'tag:origin:1234567890abcdef'
        pull_request.target_ref = 'tag:target:abcdef1234567890'
        Session().add(pull_request)
        Session().commit()

        response = self.app.get(url(
            controller='pullrequests', action='show',
            repo_name=pull_request.target_repo.scm_instance().name,
            pull_request_id=str(pull_request.pull_request_id)))
        assert response.status_int == 200
        assert_response = AssertResponse(response)

        origin = assert_response.get_element('.pr-origininfo .tag')
        assert origin.text.strip() == 'tag: origin'
        assert origin.getchildren() == []

        target = assert_response.get_element('.pr-targetinfo .tag')
        assert target.text.strip() == 'tag: target'
        assert target.getchildren() == []
 def test_logout_form_contains_csrf(self, autologin_user, csrf_token):
     response = self.app.get(url('my_account'))
     assert_response = AssertResponse(response)
     element = assert_response.get_element('.logout #csrf_token')
     assert element.value == csrf_token