Blame tests/test_pagure_flask_ui_issues_acl_checks.py

Vivek Anand 6f20f8
#!/usr/bin/env python
Vivek Anand 6f20f8
# coding=utf-8
Vivek Anand 6f20f8
Vivek Anand 6f20f8
"""
Vivek Anand 6f20f8
 (c) 2017 - Copyright Red Hat Inc
Vivek Anand 6f20f8
Vivek Anand 6f20f8
 Authors:
Vivek Anand 6f20f8
   Vivek Anand <vivekanand1101@gmail.com></vivekanand1101@gmail.com>
Vivek Anand 6f20f8
Vivek Anand 6f20f8
"""
Vivek Anand 6f20f8
Aurélien Bompard dcf6f6
from __future__ import unicode_literals
Aurélien Bompard dcf6f6
Vivek Anand 6f20f8
__requires__ = ['SQLAlchemy >= 0.8']
Vivek Anand 6f20f8
import pkg_resources
Vivek Anand 6f20f8
Vivek Anand 6f20f8
from unittest.case import SkipTest
Vivek Anand 6f20f8
import json
Vivek Anand 6f20f8
import unittest
Vivek Anand 6f20f8
import shutil
Vivek Anand 6f20f8
import sys
Vivek Anand 6f20f8
import os
Vivek Anand 6f20f8
try:
Vivek Anand 6f20f8
    import pyclamd
Abhijeet Kasurde f4bf50
except ImportError:
Vivek Anand 6f20f8
    pyclamd = None
Vivek Anand 6f20f8
import tempfile
Vivek Anand 6f20f8
Vivek Anand 6f20f8
import pygit2
Vivek Anand 6f20f8
from mock import patch
Vivek Anand 6f20f8
Vivek Anand 6f20f8
sys.path.insert(0, os.path.join(os.path.dirname(
Vivek Anand 6f20f8
    os.path.abspath(__file__)), '..'))
Vivek Anand 6f20f8
Pierre-Yves Chibon b130e5
import pagure.config
Vivek Anand 6f20f8
import pagure.lib
Vivek Anand 6f20f8
import tests
Vivek Anand 6f20f8
Vivek Anand 6f20f8
Vivek Anand 6f20f8
class PagureFlaskIssuesACLtests(tests.Modeltests):
Vivek Anand 6f20f8
    """ Tests for flask issues controller of pagure for acls """
Vivek Anand 6f20f8
Vivek Anand 6f20f8
    @patch('pagure.lib.git.update_git')
Vivek Anand 6f20f8
    @patch('pagure.lib.notify.send_email')
Vivek Anand 6f20f8
    def test_view_issue_no_access(self, p_send_email, p_ugt):
Vivek Anand 6f20f8
        """ Test the view_issue endpoint. when a user has no access on repo """
Vivek Anand 6f20f8
        p_send_email.return_value = True
Vivek Anand 6f20f8
        p_ugt.return_value = True
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/foo/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        tests.create_projects(self.session)
Vivek Anand 6f20f8
        tests.create_projects_git(
Patrick Uiterwijk 170974
            os.path.join(self.path, 'repos'), bare=True)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Create issues to play with
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
        msg = pagure.lib.new_issue(
Vivek Anand 6f20f8
            session=self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            title='Test issue',
Vivek Anand 6f20f8
            content='We should work on this',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            ticketfolder=None
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
        self.assertEqual(msg.title, 'Test issue')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Add milestone
Vivek Anand 6f20f8
        repo.milestones = {'77': None}
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
        issue = pagure.lib.search_issues(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            issueid=1
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        pagure.lib.edit_issue(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            issue,
Pierre-Yves Chibon b130e5
            pagure.config.config.get('TICKETS_FOLDER'),
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            milestone='77'
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
        self.session.add(issue)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        msg = pagure.lib.set_custom_key_fields(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            project=repo,
Vivek Anand 6f20f8
            fields=['abc', 'xyz'],
Vivek Anand 6f20f8
            types=['boolean', 'boolean'],
Vivek Anand 6f20f8
            data=[None, None],
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.assertEqual(msg, 'List of custom fields updated')
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        msg = pagure.lib.set_custom_key_value(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            issue=issue,
Vivek Anand 6f20f8
            key=pagure.lib.get_custom_key(self.session, repo, 'abc'),
Vivek Anand 6f20f8
            value=1
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.add(issue)
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
        # Not authentified = No edit
Vivek Anand 6f20f8
        self.assertNotIn(
Vivek Anand 6f20f8
            '
Vivek Anand 6f20f8
            'title="Edit this issue">',
Aurélien Bompard 626417
            output.get_data(as_text=True))
Vivek Anand 6f20f8
        self.assertTrue(
Vivek Anand 6f20f8
            ''
Vivek Anand 6f20f8
            'Login\n            to comment on this ticket.'
Aurélien Bompard 626417
            in output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
            # Not author nor admin = No edit
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                output.get_data(as_text=True))
Aurélien Bompard 626417
            self.assertNotIn('title="Delete this ticket">', output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch eef090
                '
Vivek Anand 6f20f8
                ' editmetadatatoggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertFalse(
Vivek Anand 6f20f8
                'Login to comment on this ticket.'
Aurélien Bompard 626417
                in output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<label>Milestone</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 5a20a3
                '\n                  77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            # but can't edit them
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                ' name="milestone"><option value=""></option>
Vivek Anand 6f20f8
                'selected value="77">77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '<label>Depending on</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can't edit depending on
Vivek Anand 6f20f8
            self.assertNotIn(
Pierre-Yves Chibon 215f54
                '
Pierre-Yves Chibon 215f54
                                placeholder="issue depending" name="depending"\n\
Vivek Anand 6f20f8
                                value="" />',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no toggle option for custom fields
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'issue-custom-display edit_custom_toggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no checkbox for private
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '<input id="private" name="private" type="checkbox" value="y">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        user.username = 'foo'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                output.get_data(as_text=True))
Aurélien Bompard 626417
            self.assertNotIn('title="Delete this ticket">', output.get_data(as_text=True))
Vivek Anand 6f20f8
Aurélien Bompard 626417
            csrf_token = output.get_data(as_text=True).split(
Vivek Anand 6f20f8
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch eef090
                '
Vivek Anand 6f20f8
                ' editmetadatatoggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertFalse(
Vivek Anand 6f20f8
                'Login to comment on this ticket.'
Aurélien Bompard 626417
                in output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no toggle option for custom fields
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'issue-custom-display edit_custom_toggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can't see the custom field as a checkbox
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'class="form-control" name="abc" id="abc"checked/>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<label>Milestone</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 5a20a3
                '\n                  77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # but can't edit them
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                ' name="milestone"><option value=""></option>
Vivek Anand 6f20f8
                'selected value="77">77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '<label>Depending on</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can't edit depending on
Vivek Anand 6f20f8
            self.assertNotIn(
Pierre-Yves Chibon 215f54
                '
Pierre-Yves Chibon 215f54
                                placeholder="issue depending" name="depending"\n\
Vivek Anand 6f20f8
                                value="" />',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no checkbox for private
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '<input id="private" name="private" type="checkbox" value="y">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Create private issue
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
        msg = pagure.lib.new_issue(
Vivek Anand 6f20f8
            session=self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            title='Test issue',
Vivek Anand 6f20f8
            content='We should work on this',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            ticketfolder=None,
Vivek Anand 6f20f8
            private=True,
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
        self.assertEqual(msg.title, 'Test issue')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Not logged in
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 97f498
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Wrong user
Vivek Anand 6f20f8
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 97f498
            self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # reporter
Vivek Anand 6f20f8
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/2')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<title>Issue #2: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                'title="Private issue">', output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/2/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
    @patch('pagure.lib.git.update_git')
Vivek Anand 6f20f8
    @patch('pagure.lib.notify.send_email')
Vivek Anand 6f20f8
    def test_view_issue_ticket_access(self, p_send_email, p_ugt):
Vivek Anand 6f20f8
        """ Test the view_issue endpoint. when a user has ticket access on repo """
Vivek Anand 6f20f8
        p_send_email.return_value = True
Vivek Anand 6f20f8
        p_ugt.return_value = True
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/foo/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        tests.create_projects(self.session)
Vivek Anand 6f20f8
        tests.create_projects_git(
Patrick Uiterwijk 170974
            os.path.join(self.path, 'repos'), bare=True)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Create issues to play with
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Add user 'foo' with ticket access on repo
Vivek Anand 6f20f8
        msg = pagure.lib.add_user_to_project(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            repo,
Vivek Anand 6f20f8
            new_user='foo',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            access='ticket',
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.assertEqual(msg, 'User added')
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
        msg = pagure.lib.new_issue(
Vivek Anand 6f20f8
            session=self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            title='Test issue',
Vivek Anand 6f20f8
            content='We should work on this',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            ticketfolder=None
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
        self.assertEqual(msg.title, 'Test issue')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Add milestone
Vivek Anand 6f20f8
        repo.milestones = {'77': None}
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
        issue = pagure.lib.search_issues(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            issueid=1
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        pagure.lib.edit_issue(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            issue,
Pierre-Yves Chibon b130e5
            pagure.config.config.get('TICKETS_FOLDER'),
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            milestone='77'
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
        self.session.add(issue)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        msg = pagure.lib.set_custom_key_fields(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            project=repo,
Vivek Anand 6f20f8
            fields=['abc', 'xyz'],
Vivek Anand 6f20f8
            types=['boolean', 'boolean'],
Vivek Anand 6f20f8
            data=[None, None],
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.assertEqual(msg, 'List of custom fields updated')
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        msg = pagure.lib.set_custom_key_value(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            issue=issue,
Vivek Anand 6f20f8
            key=pagure.lib.get_custom_key(self.session, repo, 'abc'),
Vivek Anand 6f20f8
            value=1
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.add(issue)
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
        # Not authentified = No edit
Vivek Anand 6f20f8
        self.assertNotIn(
Vivek Anand 6f20f8
            '
Vivek Anand 6f20f8
            'title="Edit this issue">',
Aurélien Bompard 626417
            output.get_data(as_text=True))
Vivek Anand 6f20f8
        self.assertTrue(
Vivek Anand 6f20f8
            ''
Vivek Anand 6f20f8
            'Login\n            to comment on this ticket.'
Aurélien Bompard 626417
            in output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
            # Not author nor admin = No edit
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                output.get_data(as_text=True))
Aurélien Bompard 626417
            self.assertNotIn('title="Delete this ticket">', output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch eef090
                '
Vivek Anand 6f20f8
                ' editmetadatatoggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertFalse(
Vivek Anand 6f20f8
                'Login to comment on this ticket.'
Aurélien Bompard 626417
                in output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<label>Milestone</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 5a20a3
                '\n                  77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            # but can't edit them
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                ' name="milestone"><option value=""></option>
Vivek Anand 6f20f8
                'selected value="77">77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '<label>Depending on</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can't edit depending on
Vivek Anand 6f20f8
            self.assertNotIn(
Pierre-Yves Chibon 215f54
                '
Pierre-Yves Chibon 215f54
                                placeholder="issue depending" name="depending"\n\
Vivek Anand 6f20f8
                                value="" />',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no toggle option for custom fields
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'issue-custom-display edit_custom_toggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no checkbox for private
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '<input id="private" name="private" type="checkbox" value="y">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        user.username = 'foo'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can't edit the issue
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user still can't delete the ticket
Aurélien Bompard 626417
            self.assertNotIn('title="Delete this ticket">', output.get_data(as_text=True))
Vivek Anand 6f20f8
Aurélien Bompard 626417
            csrf_token = output.get_data(as_text=True).split(
Vivek Anand 6f20f8
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can do the following things
Vivek Anand 6f20f8
            # edit metadata
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch eef090
                '
Vivek Anand 6f20f8
                ' editmetadatatoggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # toggle option for custom fields
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'issue-custom-display edit_custom_toggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<label>Milestone</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 5a20a3
                '\n                  77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can edit them
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'name="milestone"><option value=""></option>
Vivek Anand 6f20f8
                'value="77">77\n      
\n',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '<label>Depending on</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can edit depending on
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '
Pierre-Yves Chibon 215f54
                '\n                placeholder="issue depending" name="depending"\n',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user should be able to do public -> private
Vivek Anand 6f20f8
            # the other way round won't be possible since GET and POST
Vivek Anand 6f20f8
            # to this endpoint for this user will be blocked
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # checkbox for private
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<input id="private" name="private" type="checkbox" value="y">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Create private issue
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
        msg = pagure.lib.new_issue(
Vivek Anand 6f20f8
            session=self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            title='Test issue',
Vivek Anand 6f20f8
            content='We should work on this',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            ticketfolder=None,
Vivek Anand 6f20f8
            private=True,
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
        self.assertEqual(msg.title, 'Test issue')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Not logged in
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 97f498
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Wrong user
Vivek Anand 6f20f8
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 97f498
            self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # reporter
Vivek Anand 6f20f8
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/2')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<title>Issue #2: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                'title="Private issue">', output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/2/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
    @patch('pagure.lib.git.update_git')
Vivek Anand 6f20f8
    @patch('pagure.lib.notify.send_email')
Vivek Anand 6f20f8
    def test_view_issue_commit_access(self, p_send_email, p_ugt):
Vivek Anand 6f20f8
        """ Test the view_issue endpoint. when a user has commit access on repo """
Vivek Anand 6f20f8
        p_send_email.return_value = True
Vivek Anand 6f20f8
        p_ugt.return_value = True
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/foo/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        tests.create_projects(self.session)
Vivek Anand 6f20f8
        tests.create_projects_git(
Patrick Uiterwijk 170974
            os.path.join(self.path, 'repos'), bare=True)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Create issues to play with
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Add user 'foo' with ticket access on repo
Vivek Anand 6f20f8
        msg = pagure.lib.add_user_to_project(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            repo,
Vivek Anand 6f20f8
            new_user='foo',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            access='commit',
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.assertEqual(msg, 'User added')
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
        msg = pagure.lib.new_issue(
Vivek Anand 6f20f8
            session=self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            title='Test issue',
Vivek Anand 6f20f8
            content='We should work on this',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            ticketfolder=None
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
        self.assertEqual(msg.title, 'Test issue')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Add milestone
Vivek Anand 6f20f8
        repo.milestones = {'77': None}
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
        issue = pagure.lib.search_issues(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            issueid=1
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        pagure.lib.edit_issue(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            issue,
Pierre-Yves Chibon b130e5
            pagure.config.config.get('TICKETS_FOLDER'),
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            milestone='77'
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
        self.session.add(issue)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        msg = pagure.lib.set_custom_key_fields(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            project=repo,
Vivek Anand 6f20f8
            fields=['abc', 'xyz'],
Vivek Anand 6f20f8
            types=['boolean', 'boolean'],
Vivek Anand 6f20f8
            data=[None, None],
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.assertEqual(msg, 'List of custom fields updated')
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        msg = pagure.lib.set_custom_key_value(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            issue=issue,
Vivek Anand 6f20f8
            key=pagure.lib.get_custom_key(self.session, repo, 'abc'),
Vivek Anand 6f20f8
            value=1
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.add(issue)
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
        # Not authentified = No edit
Vivek Anand 6f20f8
        self.assertNotIn(
Vivek Anand 6f20f8
            '
Vivek Anand 6f20f8
            'title="Edit this issue">',
Aurélien Bompard 626417
            output.get_data(as_text=True))
Vivek Anand 6f20f8
        self.assertTrue(
Vivek Anand 6f20f8
            ''
Vivek Anand 6f20f8
            'Login\n            to comment on this ticket.'
Aurélien Bompard 626417
            in output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
            # Not author nor admin = No edit
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                output.get_data(as_text=True))
Aurélien Bompard 626417
            self.assertNotIn('title="Delete this ticket">', output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch eef090
                '
Vivek Anand 6f20f8
                ' editmetadatatoggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertFalse(
Vivek Anand 6f20f8
                'Login to comment on this ticket.'
Aurélien Bompard 626417
                in output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<label>Milestone</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 5a20a3
                '\n                  77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            # but can't edit them
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                ' name="milestone"><option value=""></option>
Vivek Anand 6f20f8
                'selected value="77">77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '<label>Depending on</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can't edit depending on
Vivek Anand 6f20f8
            self.assertNotIn(
Pierre-Yves Chibon 215f54
                '
Pierre-Yves Chibon 215f54
                                placeholder="issue depending" name="depending"\n\
Vivek Anand 6f20f8
                                value="" />',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no toggle option for custom fields
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'issue-custom-display edit_custom_toggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no checkbox for private
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '<input id="private" name="private" type="checkbox" value="y">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        user.username = 'foo'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can edit the issue
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can delete the ticket
Aurélien Bompard 626417
            self.assertIn('title="Delete this ticket">', output.get_data(as_text=True))
Vivek Anand 6f20f8
Aurélien Bompard 626417
            csrf_token = output.get_data(as_text=True).split(
Vivek Anand 6f20f8
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can do the following things
Vivek Anand 6f20f8
            # edit metadata
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch eef090
                '
Vivek Anand 6f20f8
                ' editmetadatatoggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # toggle option for custom fields
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'issue-custom-display edit_custom_toggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<label>Milestone</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 5a20a3
                '\n                  77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can edit them
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'name="milestone"><option value=""></option>
Vivek Anand 6f20f8
                'value="77">77\n      
\n',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '<label>Depending on</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can edit depending on
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '
Pierre-Yves Chibon 215f54
                '\n                placeholder="issue depending" name="depending"\n',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user should be able to do public -> private
Vivek Anand 6f20f8
            # the other way round won't be possible since GET and POST
Vivek Anand 6f20f8
            # to this endpoint for this user will be blocked
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # checkbox for private
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<input id="private" name="private" type="checkbox" value="y">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Create private issue
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
        msg = pagure.lib.new_issue(
Vivek Anand 6f20f8
            session=self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            title='Test issue',
Vivek Anand 6f20f8
            content='We should work on this',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            ticketfolder=None,
Vivek Anand 6f20f8
            private=True,
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
        self.assertEqual(msg.title, 'Test issue')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Not logged in
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 97f498
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Wrong user
Vivek Anand 6f20f8
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 97f498
            self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # reporter
Vivek Anand 6f20f8
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/2')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<title>Issue #2: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                'title="Private issue">', output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/2/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
    @patch('pagure.lib.git.update_git')
Vivek Anand 6f20f8
    @patch('pagure.lib.notify.send_email')
Vivek Anand 6f20f8
    def test_view_issue_admin_access(self, p_send_email, p_ugt):
Vivek Anand 6f20f8
        """ Test the view_issue endpoint. when a user has admin access on repo """
Vivek Anand 6f20f8
        p_send_email.return_value = True
Vivek Anand 6f20f8
        p_ugt.return_value = True
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/foo/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        tests.create_projects(self.session)
Vivek Anand 6f20f8
        tests.create_projects_git(
Patrick Uiterwijk 170974
            os.path.join(self.path, 'repos'), bare=True)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Create issues to play with
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Add user 'foo' with ticket access on repo
Vivek Anand 6f20f8
        msg = pagure.lib.add_user_to_project(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            repo,
Vivek Anand 6f20f8
            new_user='foo',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            access='admin',
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.assertEqual(msg, 'User added')
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
        msg = pagure.lib.new_issue(
Vivek Anand 6f20f8
            session=self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            title='Test issue',
Vivek Anand 6f20f8
            content='We should work on this',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            ticketfolder=None
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
        self.assertEqual(msg.title, 'Test issue')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Add milestone
Vivek Anand 6f20f8
        repo.milestones = {'77': None}
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
        issue = pagure.lib.search_issues(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            issueid=1
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        pagure.lib.edit_issue(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            issue,
Pierre-Yves Chibon b130e5
            pagure.config.config.get('TICKETS_FOLDER'),
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            milestone='77'
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
        self.session.add(issue)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        msg = pagure.lib.set_custom_key_fields(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            project=repo,
Vivek Anand 6f20f8
            fields=['abc', 'xyz'],
Vivek Anand 6f20f8
            types=['boolean', 'boolean'],
Vivek Anand 6f20f8
            data=[None, None],
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.assertEqual(msg, 'List of custom fields updated')
Vivek Anand 6f20f8
        self.session.add(repo)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        msg = pagure.lib.set_custom_key_value(
Vivek Anand 6f20f8
            self.session,
Vivek Anand 6f20f8
            issue=issue,
Vivek Anand 6f20f8
            key=pagure.lib.get_custom_key(self.session, repo, 'abc'),
Vivek Anand 6f20f8
            value=1
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.add(issue)
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
        self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
        # Not authentified = No edit
Vivek Anand 6f20f8
        self.assertNotIn(
Vivek Anand 6f20f8
            '
Vivek Anand 6f20f8
            'title="Edit this issue">',
Aurélien Bompard 626417
            output.get_data(as_text=True))
Vivek Anand 6f20f8
        self.assertTrue(
Vivek Anand 6f20f8
            ''
Vivek Anand 6f20f8
            'Login\n            to comment on this ticket.'
Aurélien Bompard 626417
            in output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
            # Not author nor admin = No edit
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                output.get_data(as_text=True))
Aurélien Bompard 626417
            self.assertNotIn('title="Delete this ticket">', output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch eef090
                '
Vivek Anand 6f20f8
                ' editmetadatatoggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertFalse(
Vivek Anand 6f20f8
                'Login to comment on this ticket.'
Aurélien Bompard 626417
                in output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<label>Milestone</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 5a20a3
                '\n                  77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            # but can't edit them
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                ' name="milestone"><option value=""></option>
Vivek Anand 6f20f8
                'selected value="77">77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '<label>Depending on</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can't edit depending on
Vivek Anand 6f20f8
            self.assertNotIn(
Pierre-Yves Chibon 215f54
                '
Pierre-Yves Chibon 215f54
                                placeholder="issue depending" name="depending"\n\
Vivek Anand 6f20f8
                                value="" />',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no toggle option for custom fields
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'issue-custom-display edit_custom_toggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no checkbox for private
Vivek Anand 6f20f8
            self.assertNotIn(
Vivek Anand 6f20f8
                '<input id="private" name="private" type="checkbox" value="y">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        user.username = 'foo'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/1')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can edit the issue
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user still can delete the ticket
Aurélien Bompard 626417
            self.assertIn('title="Delete this ticket">', output.get_data(as_text=True))
Vivek Anand 6f20f8
Aurélien Bompard 626417
            csrf_token = output.get_data(as_text=True).split(
Vivek Anand 6f20f8
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can do the following things
Vivek Anand 6f20f8
            # edit metadata
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch eef090
                '
Vivek Anand 6f20f8
                ' editmetadatatoggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # toggle option for custom fields
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'issue-custom-display edit_custom_toggle">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<label>Milestone</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 5a20a3
                '\n                  77',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can edit them
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'name="milestone"><option value=""></option>
Vivek Anand 6f20f8
                'value="77">77\n      
\n',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '<label>Depending on</label>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can edit depending on
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 215f54
                '
Pierre-Yves Chibon 215f54
                '\n                placeholder="issue depending" name="depending"\n',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user should be able to do public -> private
Vivek Anand 6f20f8
            # the other way round won't be possible since GET and POST
Vivek Anand 6f20f8
            # to this endpoint for this user will be blocked
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # checkbox for private
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<input id="private" name="private" type="checkbox" value="y">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Create private issue
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 6f20f8
        msg = pagure.lib.new_issue(
Vivek Anand 6f20f8
            session=self.session,
Vivek Anand 6f20f8
            repo=repo,
Vivek Anand 6f20f8
            title='Test issue',
Vivek Anand 6f20f8
            content='We should work on this',
Vivek Anand 6f20f8
            user='pingou',
Vivek Anand 6f20f8
            ticketfolder=None,
Vivek Anand 6f20f8
            private=True,
Vivek Anand 6f20f8
        )
Vivek Anand 6f20f8
        self.session.commit()
Vivek Anand 6f20f8
        self.assertEqual(msg.title, 'Test issue')
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Not logged in
Vivek Anand 6f20f8
        output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 97f498
        self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # Wrong user
Vivek Anand 6f20f8
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 97f498
            self.assertEqual(output.status_code, 404)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
        # reporter
Vivek Anand 6f20f8
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Vivek Anand 6f20f8
            output = self.app.get('/test/issue/2')
Vivek Anand 6f20f8
            self.assertEqual(output.status_code, 200)
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<title>Issue #2: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Aurélien Bompard 626417
                'title="Private issue">', output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '
Vivek Anand 6f20f8
                'href="/test/issue/2/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
Vivek Anand 6f20f8
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)