|
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 |
|
|
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 |
|
|
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 |
def setUp(self):
|
|
Vivek Anand |
6f20f8 |
""" Set up the environnment, run before every tests. """
|
|
Vivek Anand |
6f20f8 |
super(PagureFlaskIssuesACLtests, self).setUp()
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
pagure.APP.config['TESTING'] = True
|
|
Vivek Anand |
6f20f8 |
pagure.SESSION = self.session
|
|
Vivek Anand |
6f20f8 |
pagure.ui.SESSION = self.session
|
|
Vivek Anand |
6f20f8 |
pagure.ui.app.SESSION = self.session
|
|
Vivek Anand |
6f20f8 |
pagure.ui.issues.SESSION = self.session
|
|
Vivek Anand |
6f20f8 |
pagure.ui.repo.SESSION = self.session
|
|
Vivek Anand |
6f20f8 |
pagure.ui.filters.SESSION = self.session
|
|
Vivek Anand |
6f20f8 |
|
|
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
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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,
|
|
Vivek Anand |
6f20f8 |
pagure.APP.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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertTrue(
|
|
Vivek Anand |
6f20f8 |
''
|
|
Vivek Anand |
6f20f8 |
'Login\n to comment on this ticket.'
|
|
Vivek Anand |
6f20f8 |
in output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
user = tests.FakeUser()
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn('title="Delete this ticket">', output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# no edit metadata
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
' editmetadatatoggle">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertFalse(
|
|
Vivek Anand |
6f20f8 |
'Login to comment on this ticket.'
|
|
Vivek Anand |
6f20f8 |
in output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# can view the milestone
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'<label>Milestone</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'77',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Pierre-Yves Chibon |
215f54 |
# can view depending
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
215f54 |
'<label>Depending on</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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="" />',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
user.username = 'foo'
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn('title="Delete this ticket">', output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
csrf_token = output.data.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(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
' editmetadatatoggle">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertFalse(
|
|
Vivek Anand |
6f20f8 |
'Login to comment on this ticket.'
|
|
Vivek Anand |
6f20f8 |
in output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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/>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# can view the milestone
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'<label>Milestone</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'77',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Pierre-Yves Chibon |
215f54 |
# can view depending
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
215f54 |
'<label>Depending on</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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="" />',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# Create private issue
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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()
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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'
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
'title="Private issue">', output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
'href="/test/issue/2/edit" title="Edit this issue">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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 |
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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,
|
|
Vivek Anand |
6f20f8 |
pagure.APP.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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertTrue(
|
|
Vivek Anand |
6f20f8 |
''
|
|
Vivek Anand |
6f20f8 |
'Login\n to comment on this ticket.'
|
|
Vivek Anand |
6f20f8 |
in output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
user = tests.FakeUser()
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn('title="Delete this ticket">', output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# no edit metadata
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
' editmetadatatoggle">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertFalse(
|
|
Vivek Anand |
6f20f8 |
'Login to comment on this ticket.'
|
|
Vivek Anand |
6f20f8 |
in output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# can view the milestone
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'<label>Milestone</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'77',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Pierre-Yves Chibon |
215f54 |
# can view depending
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
215f54 |
'<label>Depending on</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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="" />',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
user.username = 'foo'
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# the user still can't delete the ticket
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn('title="Delete this ticket">', output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
csrf_token = output.data.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(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
' editmetadatatoggle">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# can view the milestone
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'<label>Milestone</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'77',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Pierre-Yves Chibon |
215f54 |
# can view depending
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
215f54 |
'<label>Depending on</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# Create private issue
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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()
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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'
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
'title="Private issue">', output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
'href="/test/issue/2/edit" title="Edit this issue">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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 |
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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,
|
|
Vivek Anand |
6f20f8 |
pagure.APP.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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertTrue(
|
|
Vivek Anand |
6f20f8 |
''
|
|
Vivek Anand |
6f20f8 |
'Login\n to comment on this ticket.'
|
|
Vivek Anand |
6f20f8 |
in output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
user = tests.FakeUser()
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn('title="Delete this ticket">', output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# no edit metadata
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
' editmetadatatoggle">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertFalse(
|
|
Vivek Anand |
6f20f8 |
'Login to comment on this ticket.'
|
|
Vivek Anand |
6f20f8 |
in output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# can view the milestone
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'<label>Milestone</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'77',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Pierre-Yves Chibon |
215f54 |
# can view depending
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
215f54 |
'<label>Depending on</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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="" />',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
user.username = 'foo'
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# the user can delete the ticket
|
|
Vivek Anand |
6f20f8 |
self.assertIn('title="Delete this ticket">', output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
csrf_token = output.data.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(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
' editmetadatatoggle">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# can view the milestone
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'<label>Milestone</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'77',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Pierre-Yves Chibon |
215f54 |
# can view depending
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
215f54 |
'<label>Depending on</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# Create private issue
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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()
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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'
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
'title="Private issue">', output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
'href="/test/issue/2/edit" title="Edit this issue">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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 |
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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,
|
|
Vivek Anand |
6f20f8 |
pagure.APP.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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertTrue(
|
|
Vivek Anand |
6f20f8 |
''
|
|
Vivek Anand |
6f20f8 |
'Login\n to comment on this ticket.'
|
|
Vivek Anand |
6f20f8 |
in output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
user = tests.FakeUser()
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn('title="Delete this ticket">', output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# no edit metadata
|
|
Vivek Anand |
6f20f8 |
self.assertNotIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
' editmetadatatoggle">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertFalse(
|
|
Vivek Anand |
6f20f8 |
'Login to comment on this ticket.'
|
|
Vivek Anand |
6f20f8 |
in output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# can view the milestone
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'<label>Milestone</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'77',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Pierre-Yves Chibon |
215f54 |
# can view depending
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
215f54 |
'<label>Depending on</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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="" />',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
user.username = 'foo'
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# the user still can delete the ticket
|
|
Vivek Anand |
6f20f8 |
self.assertIn('title="Delete this ticket">', output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
csrf_token = output.data.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(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
' editmetadatatoggle">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# can view the milestone
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'<label>Milestone</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'77',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Pierre-Yves Chibon |
215f54 |
# can view depending
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
215f54 |
'<label>Depending on</label>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
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">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
# Create private issue
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.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()
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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'
|
|
Vivek Anand |
6f20f8 |
with tests.user_set(pagure.APP, 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>',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
'title="Private issue">', output.data)
|
|
Vivek Anand |
6f20f8 |
self.assertIn(
|
|
Vivek Anand |
6f20f8 |
'
|
|
Vivek Anand |
6f20f8 |
'href="/test/issue/2/edit" title="Edit this issue">',
|
|
Vivek Anand |
6f20f8 |
output.data)
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
|
|
Vivek Anand |
6f20f8 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|