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
        )
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,
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(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
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)
Pierre-Yves Chibon 4c5425
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
            # Not author nor admin = No edit
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                '                title="Delete this ticket">\n',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Ryan Lerch e85d33
                '',
Pierre-Yves Chibon 0541ed
                output_text)
Pierre-Yves Chibon 0541ed
            self.assertNotIn(
Pierre-Yves Chibon 0541ed
                'Login to comment on this ticket.',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Milestone',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 4c5425
                '\n                '
Pierre-Yves Chibon 4c5425
                '\n                  77\n', output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Depending on',
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="" />',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
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">',
Pierre-Yves Chibon 0541ed
                output_text)
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)
Pierre-Yves Chibon 4c5425
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                '                title="Delete this ticket">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 0541ed
            csrf_token = self.get_csrf(output=output)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Ryan Lerch e85d33
                '',
Pierre-Yves Chibon 0541ed
                output_text)
Pierre-Yves Chibon 0541ed
            self.assertNotIn(
Pierre-Yves Chibon 0541ed
                'Login to comment on this ticket.',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
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/>',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Milestone',
Aurélien Bompard 626417
                output.get_data(as_text=True))
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 4c5425
                '\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',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Depending on',
Pierre-Yves Chibon 0541ed
                output_text)
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="" />',
Pierre-Yves Chibon 0541ed
                output_text)
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">',
Pierre-Yves Chibon 0541ed
                output_text)
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
            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)
Pierre-Yves Chibon 0541ed
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<title>Issue #2: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 3a8ee8
                '
Pierre-Yves Chibon 3a8ee8
                'fa fa-fw fa-lock">', output_text)
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/2/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
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
        )
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,
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)
Pierre-Yves Chibon 0541ed
        output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
        # Not authentified = No edit
Vivek Anand 6f20f8
        self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
            output_text)
Pierre-Yves Chibon 0541ed
        self.assertIn(
Vivek Anand 6f20f8
            ''
Pierre-Yves Chibon 0541ed
            'Login\n            to comment on this ticket.',
Pierre-Yves Chibon 0541ed
            output_text)
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)
Pierre-Yves Chibon 4c5425
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
            # Not author nor admin = No edit
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                '                title="Delete this ticket">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Ryan Lerch e85d33
                '',
Pierre-Yves Chibon 0541ed
                output_text)
Pierre-Yves Chibon 0541ed
            self.assertNotIn(
Pierre-Yves Chibon 0541ed
                'Login to comment on this ticket.',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Milestone',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 4c5425
                '\n                  77',
Pierre-Yves Chibon 4c5425
                output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Depending on',
Pierre-Yves Chibon 0541ed
                output_text)
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="" />',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
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">',
Pierre-Yves Chibon 0541ed
                output_text)
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)
Pierre-Yves Chibon 4c5425
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can't edit the issue
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user still can't delete the ticket
Ryan Lerch e85d33
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                '                title="Delete this ticket">\n',
Ryan Lerch e85d33
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 0541ed
            csrf_token = self.get_csrf(output=output)
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 e85d33
                '
Ryan Lerch e85d33
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Ryan Lerch e85d33
                '',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Milestone',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 4c5425
                '\n                  77',
Pierre-Yves Chibon 4c5425
                output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Depending on',
Pierre-Yves Chibon 0541ed
                output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
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">',
Pierre-Yves Chibon 0541ed
                output_text)
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
            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)
Pierre-Yves Chibon 0541ed
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<title>Issue #2: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 3a8ee8
                '
Pierre-Yves Chibon 3a8ee8
                'fa fa-fw fa-lock">', output_text)
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/2/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
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
        )
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,
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)
Pierre-Yves Chibon 0541ed
        output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
        # Not authentified = No edit
Vivek Anand 6f20f8
        self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
            output_text)
Vivek Anand 6f20f8
        self.assertTrue(
Vivek Anand 6f20f8
            ''
Pierre-Yves Chibon 0541ed
            'Login\n            to comment on this ticket.',
Pierre-Yves Chibon 0541ed
            output_text)
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)
Pierre-Yves Chibon 4c5425
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
            # Not author nor admin = No edit
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                '                title="Delete this ticket">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Ryan Lerch e85d33
                '',
Pierre-Yves Chibon 0541ed
                output_text)
Pierre-Yves Chibon 0541ed
            self.assertNotIn(
Pierre-Yves Chibon 0541ed
                'Login to comment on this ticket.',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Milestone',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 4c5425
                '\n                  77',
Pierre-Yves Chibon 4c5425
                output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Depending on',
Pierre-Yves Chibon 0541ed
                output_text)
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="" />',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
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">',
Pierre-Yves Chibon 0541ed
                output_text)
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)
Pierre-Yves Chibon 4c5425
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can edit the issue
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can delete the ticket
Ryan Lerch e85d33
            self.assertIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                '                title="Delete this ticket">\n',
Ryan Lerch e85d33
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 0541ed
            csrf_token = self.get_csrf(output=output)
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 e85d33
                '
Ryan Lerch e85d33
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Ryan Lerch e85d33
                '',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Milestone',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 4c5425
                '\n                  77',
Pierre-Yves Chibon 4c5425
                output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Depending on',
Pierre-Yves Chibon 0541ed
                output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
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">',
Pierre-Yves Chibon 0541ed
                output_text)
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
            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)
Pierre-Yves Chibon 0541ed
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<title>Issue #2: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 3a8ee8
                '
Pierre-Yves Chibon 3a8ee8
                'fa fa-fw fa-lock">', output_text)
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/2/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
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
        )
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,
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(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
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)
Pierre-Yves Chibon 4c5425
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
            # Not author nor admin = No edit
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                '                title="Delete this ticket">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # no edit metadata
Vivek Anand 6f20f8
            self.assertNotIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Ryan Lerch e85d33
                '',
Pierre-Yves Chibon 0541ed
                output_text)
Pierre-Yves Chibon 0541ed
            self.assertNotIn(
Pierre-Yves Chibon 0541ed
                'Login to comment on this ticket.',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Milestone',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 4c5425
                '\n                  77',
Pierre-Yves Chibon 4c5425
                output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Depending on',
Pierre-Yves Chibon 0541ed
                output_text)
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="" />',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
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">',
Pierre-Yves Chibon 0541ed
                output_text)
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)
Pierre-Yves Chibon 4c5425
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # the user can edit the issue
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/1/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                '                title="Delete this ticket">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 0541ed
            csrf_token = self.get_csrf(output=output)
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 e85d33
                '
Ryan Lerch e85d33
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Ryan Lerch e85d33
                '',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
            # can view the milestone
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Milestone',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 4c5425
                '\n                  77',
Pierre-Yves Chibon 4c5425
                output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Pierre-Yves Chibon 215f54
            # can view depending
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                'Depending on',
Pierre-Yves Chibon 0541ed
                output_text)
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',
Pierre-Yves Chibon 0541ed
                output_text)
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">',
Pierre-Yves Chibon 0541ed
                output_text)
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
            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)
Pierre-Yves Chibon 0541ed
            output_text = output.get_data(as_text=True)
Vivek Anand 6f20f8
            self.assertIn(
Vivek Anand 6f20f8
                '<title>Issue #2: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
            self.assertIn(
Pierre-Yves Chibon 3a8ee8
                '
Pierre-Yves Chibon 3a8ee8
                'fa fa-fw fa-lock">', output_text)
Vivek Anand 6f20f8
            self.assertIn(
Ryan Lerch e85d33
                '
Ryan Lerch e85d33
                'href="/test/issue/2/edit" title="Edit this issue">\n',
Pierre-Yves Chibon 0541ed
                output_text)
Vivek Anand 6f20f8
Vivek Anand 6f20f8
Vivek Anand 6f20f8
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)