|
Pierre-Yves Chibon |
19656f |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
"""
|
|
Pierre-Yves Chibon |
9fae46 |
(c) 2015-2016 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
Authors:
|
|
Pierre-Yves Chibon |
19656f |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
"""
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
19656f |
import pkg_resources
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
import unittest
|
|
Pierre-Yves Chibon |
19656f |
import shutil
|
|
Pierre-Yves Chibon |
19656f |
import sys
|
|
Pierre-Yves Chibon |
19656f |
import os
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
import json
|
|
Pierre-Yves Chibon |
19656f |
from mock import patch
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
19656f |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
import pagure.lib
|
|
Pierre-Yves Chibon |
19656f |
import tests
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
class PagureFlaskGroupstests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
19656f |
""" Tests for flask groups controller of pagure """
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
def setUp(self):
|
|
Pierre-Yves Chibon |
19656f |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
19656f |
super(PagureFlaskGroupstests, self).setUp()
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
19656f |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
19656f |
pagure.ui.SESSION = self.session
|
|
Pierre-Yves Chibon |
19656f |
pagure.ui.groups.SESSION = self.session
|
|
Pierre-Yves Chibon |
19656f |
pagure.ui.repo.SESSION = self.session
|
|
Pierre-Yves Chibon |
9fae46 |
pagure.ui.filters.SESSION = self.session
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
pagure.APP.config['GIT_FOLDER'] = tests.HERE
|
|
Pierre-Yves Chibon |
19656f |
pagure.APP.config['FORK_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
19656f |
tests.HERE, 'forks')
|
|
Pierre-Yves Chibon |
19656f |
pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
19656f |
tests.HERE, 'tickets')
|
|
Pierre-Yves Chibon |
19656f |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
19656f |
tests.HERE, 'docs')
|
|
Pierre-Yves Chibon |
19656f |
pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
19656f |
tests.HERE, 'requests')
|
|
Pierre-Yves Chibon |
19656f |
self.app = pagure.APP.test_client()
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
def test_group_lists(self):
|
|
Pierre-Yves Chibon |
19656f |
""" Test the group_lists endpoint. """
|
|
Pierre-Yves Chibon |
19656f |
output = self.app.get('/groups')
|
|
Pierre-Yves Chibon |
0a88aa |
self.assertIn(
|
|
Pierre-Yves Chibon |
0a88aa |
'\n'
|
|
Pierre-Yves Chibon |
0a88aa |
' Groups 0',
|
|
Pierre-Yves Chibon |
0a88aa |
output.data)
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
860f53 |
def test_add_group(self):
|
|
Pierre-Yves Chibon |
860f53 |
""" Test the add_group endpoint. """
|
|
Pierre-Yves Chibon |
860f53 |
output = self.app.get('/group/add')
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
860f53 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
860f53 |
output = self.app.get('/group/add')
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
860f53 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
860f53 |
output = self.app.get('/group/add')
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertIn('Create group', output.data)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
860f53 |
'<option value="admin">admin</option>', output.data)
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
860f53 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
data = {
|
|
Pierre-Yves Chibon |
860f53 |
}
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
# Insufficient input
|
|
Pierre-Yves Chibon |
860f53 |
output = self.app.post('/group/add', data=data)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertIn('Create group', output.data)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.data.count(
|
|
Pierre-Yves Chibon |
860f53 |
'This field is required.'), 1)
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
data = {
|
|
Pierre-Yves Chibon |
b53d8c |
'group_name': 'test_group',
|
|
Pierre-Yves Chibon |
860f53 |
}
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
# Missing CSRF
|
|
Pierre-Yves Chibon |
860f53 |
output = self.app.post('/group/add', data=data)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertIn('Create group', output.data)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.data.count(
|
|
Pierre-Yves Chibon |
860f53 |
'This field is required.'), 0)
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
# All good
|
|
Pierre-Yves Chibon |
860f53 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
860f53 |
'/group/add', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n User `pingou` added to '
|
|
Pierre-Yves Chibon |
eaef3a |
'the group `test_group`.', output.data)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n Group `test_group` created.',
|
|
Pierre-Yves Chibon |
860f53 |
output.data)
|
|
Pierre-Yves Chibon |
0a88aa |
self.assertIn(
|
|
Pierre-Yves Chibon |
0a88aa |
'\n'
|
|
Pierre-Yves Chibon |
0a88aa |
' Groups 1',
|
|
Pierre-Yves Chibon |
0a88aa |
output.data)
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
user = tests.FakeUser(
|
|
Pierre-Yves Chibon |
860f53 |
username='pingou',
|
|
Pierre-Yves Chibon |
860f53 |
groups=pagure.APP.config['ADMIN_GROUP'])
|
|
Pierre-Yves Chibon |
860f53 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
860f53 |
output = self.app.get('/group/add')
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertIn('Create group', output.data)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertIn('<option value="admin">admin</option>', output.data)
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
data = {
|
|
Pierre-Yves Chibon |
a3df4f |
'group_name': 'test_admin_group',
|
|
Pierre-Yves Chibon |
860f53 |
'group_type': 'admin',
|
|
Pierre-Yves Chibon |
860f53 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
860f53 |
}
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
860f53 |
# All good
|
|
Pierre-Yves Chibon |
860f53 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
860f53 |
'/group/add', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n User `pingou` added to '
|
|
Pierre-Yves Chibon |
eaef3a |
'the group `test_admin_group`.', output.data)
|
|
Pierre-Yves Chibon |
860f53 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n Group `test_admin_group` '
|
|
Pierre-Yves Chibon |
eaef3a |
'created.',output.data)
|
|
Pierre-Yves Chibon |
0a88aa |
self.assertIn(
|
|
Pierre-Yves Chibon |
0a88aa |
'\n'
|
|
Pierre-Yves Chibon |
0a88aa |
' Groups 2',
|
|
Pierre-Yves Chibon |
0a88aa |
output.data)
|
|
Pierre-Yves Chibon |
860f53 |
|
|
Pierre-Yves Chibon |
f297f4 |
def test_group_delete(self):
|
|
Pierre-Yves Chibon |
f297f4 |
""" Test the group_delete endpoint. """
|
|
Pierre-Yves Chibon |
f297f4 |
output = self.app.post('/group/foo/delete')
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
f297f4 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
f297f4 |
output = self.app.post('/group/foo/delete', follow_redirects=True)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertIn(
|
|
Pierre-Yves Chibon |
f297f4 |
'No groups have been created on this pagure instance '
|
|
Pierre-Yves Chibon |
f297f4 |
'yet', output.data)
|
|
Pierre-Yves Chibon |
0a88aa |
self.assertIn(
|
|
Pierre-Yves Chibon |
0a88aa |
'\n'
|
|
Pierre-Yves Chibon |
0a88aa |
' Groups 0',
|
|
Pierre-Yves Chibon |
0a88aa |
output.data)
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
self.test_add_group()
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
f297f4 |
output = self.app.post('/group/foo/delete', follow_redirects=True)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0a88aa |
self.assertIn(
|
|
Pierre-Yves Chibon |
0a88aa |
'\n'
|
|
Pierre-Yves Chibon |
0a88aa |
' Groups 1',
|
|
Pierre-Yves Chibon |
0a88aa |
output.data)
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
f297f4 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
f297f4 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
data = {
|
|
Pierre-Yves Chibon |
f297f4 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
f297f4 |
}
|
|
Pierre-Yves Chibon |
f297f4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f297f4 |
'/group/bar/delete', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n No group `bar` found',
|
|
Pierre-Yves Chibon |
eaef3a |
output.data)
|
|
Pierre-Yves Chibon |
0a88aa |
self.assertIn(
|
|
Pierre-Yves Chibon |
0a88aa |
'\n'
|
|
Pierre-Yves Chibon |
0a88aa |
' Groups 1',
|
|
Pierre-Yves Chibon |
0a88aa |
output.data)
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_group/delete', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n You are not allowed to '
|
|
Pierre-Yves Chibon |
eaef3a |
'delete the group test_group', output.data)
|
|
Pierre-Yves Chibon |
0a88aa |
self.assertIn(
|
|
Pierre-Yves Chibon |
0a88aa |
'\n'
|
|
Pierre-Yves Chibon |
0a88aa |
' Groups 1',
|
|
Pierre-Yves Chibon |
0a88aa |
output.data)
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
user.username = 'bar'
|
|
Pierre-Yves Chibon |
f297f4 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_group/delete', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
f297f4 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
f297f4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_group/delete', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
f297f4 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n Group `test_group` has '
|
|
Pierre-Yves Chibon |
eaef3a |
'been deleted', output.data)
|
|
Pierre-Yves Chibon |
0a88aa |
self.assertIn(
|
|
Pierre-Yves Chibon |
0a88aa |
'\n'
|
|
Pierre-Yves Chibon |
0a88aa |
' Groups 0',
|
|
Pierre-Yves Chibon |
0a88aa |
output.data)
|
|
Pierre-Yves Chibon |
f297f4 |
|
|
Pierre-Yves Chibon |
8abb7d |
def test_view_group(self):
|
|
Pierre-Yves Chibon |
8abb7d |
""" Test the view_group endpoint. """
|
|
Pierre-Yves Chibon |
8abb7d |
output = self.app.get('/group/foo')
|
|
Pierre-Yves Chibon |
8abb7d |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
8abb7d |
self.test_add_group()
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
8abb7d |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
8abb7d |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
a3df4f |
output = self.app.get('/group/test_group')
|
|
Pierre-Yves Chibon |
8abb7d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_group', output.data)
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
a3df4f |
output = self.app.get('/group/test_admin_group')
|
|
Pierre-Yves Chibon |
8abb7d |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
8abb7d |
user = tests.FakeUser(
|
|
Pierre-Yves Chibon |
8abb7d |
username='pingou',
|
|
Pierre-Yves Chibon |
8abb7d |
groups=pagure.APP.config['ADMIN_GROUP'])
|
|
Pierre-Yves Chibon |
8abb7d |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
8abb7d |
# Admin can see group of type admins
|
|
Pierre-Yves Chibon |
a3df4f |
output = self.app.get('/group/test_admin_group')
|
|
Pierre-Yves Chibon |
8abb7d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_admin_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
8abb7d |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
8abb7d |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
8abb7d |
# No CSRF
|
|
Pierre-Yves Chibon |
8abb7d |
data = {
|
|
Pierre-Yves Chibon |
8abb7d |
'user': 'bar'
|
|
Pierre-Yves Chibon |
8abb7d |
}
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
a3df4f |
output = self.app.post('/group/test_admin_group', data=data)
|
|
Pierre-Yves Chibon |
8abb7d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_admin_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
8abb7d |
# Invalid user
|
|
Pierre-Yves Chibon |
8abb7d |
data = {
|
|
Pierre-Yves Chibon |
8abb7d |
'user': 'bar',
|
|
Pierre-Yves Chibon |
8abb7d |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
8abb7d |
}
|
|
Pierre-Yves Chibon |
8abb7d |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_admin_group', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
8abb7d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8abb7d |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n No user `bar` found',
|
|
Pierre-Yves Chibon |
eaef3a |
output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_admin_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
8abb7d |
# All good
|
|
Pierre-Yves Chibon |
8abb7d |
data = {
|
|
Pierre-Yves Chibon |
8abb7d |
'user': 'foo',
|
|
Pierre-Yves Chibon |
8abb7d |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
8abb7d |
}
|
|
Pierre-Yves Chibon |
a3df4f |
output = self.app.post('/group/test_admin_group', data=data)
|
|
Pierre-Yves Chibon |
8abb7d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8abb7d |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n User `foo` added to the '
|
|
Pierre-Yves Chibon |
eaef3a |
'group `test_admin_group`.', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_admin_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
8abb7d |
|
|
Pierre-Yves Chibon |
fa37e7 |
def test_group_user_delete(self):
|
|
Pierre-Yves Chibon |
fa37e7 |
""" Test the group_user_delete endpoint. """
|
|
Pierre-Yves Chibon |
fa37e7 |
output = self.app.post('/group/foo/bar/delete')
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
fa37e7 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
fa37e7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
fa37e7 |
'/group/foo/bar/delete', follow_redirects=True)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
self.test_add_group()
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
fa37e7 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
fa37e7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_group/bar/delete', follow_redirects=True)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
9cc24e |
output = self.app.get('/new/')
|
|
Pierre-Yves Chibon |
fa37e7 |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
fa37e7 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
data = {'csrf_token': csrf_token}
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_group/bar/delete', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n No user `bar` found',
|
|
Pierre-Yves Chibon |
eaef3a |
output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_group/foo/delete', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n Could not find user '
|
|
Pierre-Yves Chibon |
eaef3a |
'username', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
fa37e7 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
fa37e7 |
# User not in the group
|
|
Pierre-Yves Chibon |
fa37e7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_group/foo/delete', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n User `foo` could not be '
|
|
Pierre-Yves Chibon |
eaef3a |
'found in the group `test_group`', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
# Cannot delete creator
|
|
Pierre-Yves Chibon |
fa37e7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_group/foo/delete', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n User `foo` could not be '
|
|
Pierre-Yves Chibon |
eaef3a |
'found in the group `test_group`', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
# Add user foo
|
|
Pierre-Yves Chibon |
fa37e7 |
data = {
|
|
Pierre-Yves Chibon |
fa37e7 |
'user': 'foo',
|
|
Pierre-Yves Chibon |
fa37e7 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
fa37e7 |
}
|
|
Pierre-Yves Chibon |
a3df4f |
output = self.app.post('/group/test_group', data=data)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n User `foo` added to the '
|
|
Pierre-Yves Chibon |
eaef3a |
'group `test_group`.', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
fa37e7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a3df4f |
'/group/test_group/foo/delete', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fa37e7 |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
'\n User `foo` removed from '
|
|
Pierre-Yves Chibon |
eaef3a |
'the group `test_group`', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertIn(
|
|
Pierre-Yves Chibon |
eaef3a |
' '
|
|
Pierre-Yves Chibon |
eaef3a |
'test_group', output.data)
|
|
Pierre-Yves Chibon |
eaef3a |
self.assertEqual(output.data.count('
|
|
Pierre-Yves Chibon |
fa37e7 |
|
|
Pierre-Yves Chibon |
19656f |
|
|
Pierre-Yves Chibon |
19656f |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
19656f |
SUITE = unittest.TestLoader().loadTestsFromTestCase(
|
|
Pierre-Yves Chibon |
19656f |
PagureFlaskGroupstests)
|
|
Pierre-Yves Chibon |
19656f |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|