|
Pierre-Yves Chibon |
cfad13 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
"""
|
|
Pierre-Yves Chibon |
cfad13 |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
Authors:
|
|
Pierre-Yves Chibon |
cfad13 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
"""
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
cfad13 |
import pkg_resources
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
import unittest
|
|
Pierre-Yves Chibon |
cfad13 |
import shutil
|
|
Pierre-Yves Chibon |
cfad13 |
import sys
|
|
Pierre-Yves Chibon |
cfad13 |
import os
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
import json
|
|
Pierre-Yves Chibon |
cfad13 |
from mock import patch
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
cfad13 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
fe5017 |
import pagure.lib
|
|
Pierre-Yves Chibon |
cfad13 |
import tests
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
fe5017 |
class PagureFlaskApptests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Tests for flask app controller of pagure """
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
def setUp(self):
|
|
Pierre-Yves Chibon |
cfad13 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
fe5017 |
super(PagureFlaskApptests, self).setUp()
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.ui.SESSION = self.session
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.ui.app.SESSION = self.session
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.ui.repo.SESSION = self.session
|
|
Pierre-Yves Chibon |
d2d020 |
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['GIT_FOLDER'] = tests.HERE
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['FORK_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
d2d020 |
tests.HERE, 'forks')
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
d2d020 |
tests.HERE, 'tickets')
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
d2d020 |
tests.HERE, 'docs')
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
ed8d1c |
tests.HERE, 'requests')
|
|
Pierre-Yves Chibon |
fe5017 |
self.app = pagure.APP.test_client()
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
def test_index(self):
|
|
Pierre-Yves Chibon |
7827f1 |
""" Test the index endpoint. """
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
output = self.app.get('/')
|
|
Pierre-Yves Chibon |
cfad13 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
daa3de |
self.assertTrue('All Projects (0)' in output.data)
|
|
Pierre-Yves Chibon |
daa3de |
|
|
Pierre-Yves Chibon |
daa3de |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
0ebfa3 |
output = self.app.get('/?page=abc')
|
|
Pierre-Yves Chibon |
0ebfa3 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0ebfa3 |
self.assertTrue('All Projects (2)' in output.data)
|
|
Pierre-Yves Chibon |
0ebfa3 |
|
|
Pierre-Yves Chibon |
c17bfb |
# Add a 3rd project with a long description
|
|
Pierre-Yves Chibon |
fe5017 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
c17bfb |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
c17bfb |
name='test3',
|
|
Pierre-Yves Chibon |
c17bfb |
description='test project #3 with a very long description',
|
|
Pierre-Yves Chibon |
e2259d |
hook_token='aaabbbeee',
|
|
Pierre-Yves Chibon |
c17bfb |
)
|
|
Pierre-Yves Chibon |
c17bfb |
self.session.add(item)
|
|
Pierre-Yves Chibon |
c17bfb |
self.session.commit()
|
|
Pierre-Yves Chibon |
c17bfb |
|
|
Pierre-Yves Chibon |
0ebfa3 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
fe5017 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
0ebfa3 |
output = self.app.get('/?repopage=abc&forkpage=def')
|
|
Pierre-Yves Chibon |
0ebfa3 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
0ebfa3 |
'<section class="project_list" id="repos">' in output.data)</section>
|
|
Pierre-Yves Chibon |
0ebfa3 |
self.assertTrue('My Forks (0)' in output.data)
|
|
Pierre-Yves Chibon |
0ebfa3 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
0ebfa3 |
'<section class="project_list" id="myforks">' in output.data)</section>
|
|
Pierre-Yves Chibon |
0ebfa3 |
self.assertTrue('My Projects (0)' in output.data)
|
|
Pierre-Yves Chibon |
0ebfa3 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
0ebfa3 |
'<section class="project_list" id="myrepos">' in output.data)</section>
|
|
Pierre-Yves Chibon |
c17bfb |
self.assertTrue('All Projects (3)' in output.data)
|
|
Pierre-Yves Chibon |
0ebfa3 |
|
|
Pierre-Yves Chibon |
78d005 |
def test_view_users(self):
|
|
Pierre-Yves Chibon |
7827f1 |
""" Test the view_users endpoint. """
|
|
Pierre-Yves Chibon |
78d005 |
|
|
Pierre-Yves Chibon |
78d005 |
output = self.app.get('/users/?page=abc')
|
|
Pierre-Yves Chibon |
78d005 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
78d005 |
self.assertTrue('2 users registered. ' in output.data)
|
|
Pierre-Yves Chibon |
78d005 |
self.assertTrue('' in output.data)
|
|
Pierre-Yves Chibon |
78d005 |
self.assertTrue('' in output.data)
|
|
Pierre-Yves Chibon |
78d005 |
|
|
Pierre-Yves Chibon |
045b56 |
def test_view_user(self):
|
|
Pierre-Yves Chibon |
7827f1 |
""" Test the view_user endpoint. """
|
|
Pierre-Yves Chibon |
045b56 |
|
|
Pierre-Yves Chibon |
045b56 |
output = self.app.get('/user/pingou?repopage=abc&forkpage=def')
|
|
Pierre-Yves Chibon |
045b56 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
045b56 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
045b56 |
'<section class="project_list" id="repos">' in output.data)</section>
|
|
Pierre-Yves Chibon |
8bcb94 |
self.assertTrue('Projects (0)' in output.data)
|
|
Pierre-Yves Chibon |
045b56 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
045b56 |
'<section class="project_list" id="forks">' in output.data)</section>
|
|
Pierre-Yves Chibon |
8bcb94 |
self.assertTrue('Forks (0)' in output.data)
|
|
Pierre-Yves Chibon |
045b56 |
|
|
Pierre-Yves Chibon |
8bcb94 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
293dcb |
self.gitrepos = tests.create_projects_git(
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['GIT_FOLDER'])
|
|
Pierre-Yves Chibon |
8bcb94 |
|
|
Pierre-Yves Chibon |
8bcb94 |
output = self.app.get('/user/pingou?repopage=abc&forkpage=def')
|
|
Pierre-Yves Chibon |
8bcb94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8bcb94 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
8bcb94 |
'<section class="project_list" id="repos">' in output.data)</section>
|
|
Pierre-Yves Chibon |
8bcb94 |
self.assertTrue('Projects (2)' in output.data)
|
|
Pierre-Yves Chibon |
8bcb94 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
8bcb94 |
'<section class="project_list" id="forks">' in output.data)</section>
|
|
Pierre-Yves Chibon |
8bcb94 |
self.assertTrue('Forks (0)' in output.data)
|
|
Pierre-Yves Chibon |
045b56 |
|
|
Pierre-Yves Chibon |
e5e107 |
def test_new_project(self):
|
|
Pierre-Yves Chibon |
e5e107 |
""" Test the new_project endpoint. """
|
|
Pierre-Yves Chibon |
e5e107 |
# Before
|
|
Pierre-Yves Chibon |
fe5017 |
projects = pagure.lib.search_projects(self.session)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertEqual(len(projects), 0)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertFalse(os.path.exists(
|
|
Pierre-Yves Chibon |
e5e107 |
os.path.join(tests.HERE, 'project#1.git')))
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertFalse(os.path.exists(
|
|
Pierre-Yves Chibon |
e5e107 |
os.path.join(tests.HERE, 'tickets', 'project#1.git')))
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertFalse(os.path.exists(
|
|
Pierre-Yves Chibon |
e5e107 |
os.path.join(tests.HERE, 'docs', 'project#1.git')))
|
|
Pierre-Yves Chibon |
ed8d1c |
self.assertFalse(os.path.exists(
|
|
Pierre-Yves Chibon |
ed8d1c |
os.path.join(tests.HERE, 'requests', 'project#1.git')))
|
|
Pierre-Yves Chibon |
e5e107 |
|
|
Pierre-Yves Chibon |
e5e107 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
fe5017 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
e5e107 |
output = self.app.get('/new/')
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue('New project' in output.data)
|
|
Pierre-Yves Chibon |
e5e107 |
|
|
Pierre-Yves Chibon |
e5e107 |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
e5e107 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
e5e107 |
|
|
Pierre-Yves Chibon |
e5e107 |
data = {
|
|
Pierre-Yves Chibon |
e5e107 |
'description': 'Project #1',
|
|
Pierre-Yves Chibon |
e5e107 |
}
|
|
Pierre-Yves Chibon |
e5e107 |
|
|
Pierre-Yves Chibon |
e5e107 |
output = self.app.post('/new/', data=data)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue('New project' in output.data)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
e5e107 |
'This field is required.'
|
|
Pierre-Yves Chibon |
e5e107 |
in output.data)
|
|
Pierre-Yves Chibon |
e5e107 |
|
|
Pierre-Yves Chibon |
e5e107 |
data['name'] = 'project#1'
|
|
Pierre-Yves Chibon |
e5e107 |
output = self.app.post('/new/', data=data)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue('New project' in output.data)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
e5e107 |
'This field is required.'
|
|
Pierre-Yves Chibon |
e5e107 |
in output.data)
|
|
Pierre-Yves Chibon |
e5e107 |
|
|
Pierre-Yves Chibon |
e5e107 |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
e5e107 |
output = self.app.post('/new/', data=data)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue('New project' in output.data)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
e5e107 |
'No user "username" found'
|
|
Pierre-Yves Chibon |
e5e107 |
in output.data)
|
|
Pierre-Yves Chibon |
e5e107 |
|
|
Pierre-Yves Chibon |
e5e107 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
fe5017 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
e5e107 |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
e5e107 |
output = self.app.post('/new/', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue('Project #1 ' in output.data)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
e5e107 |
'Project "project#1" created'
|
|
Pierre-Yves Chibon |
e5e107 |
in output.data)
|
|
Pierre-Yves Chibon |
e5e107 |
|
|
Pierre-Yves Chibon |
e5e107 |
# After
|
|
Pierre-Yves Chibon |
fe5017 |
projects = pagure.lib.search_projects(self.session)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertEqual(len(projects), 1)
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue(os.path.exists(
|
|
Pierre-Yves Chibon |
e5e107 |
os.path.join(tests.HERE, 'project#1.git')))
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue(os.path.exists(
|
|
Pierre-Yves Chibon |
e5e107 |
os.path.join(tests.HERE, 'tickets', 'project#1.git')))
|
|
Pierre-Yves Chibon |
e5e107 |
self.assertTrue(os.path.exists(
|
|
Pierre-Yves Chibon |
e5e107 |
os.path.join(tests.HERE, 'docs', 'project#1.git')))
|
|
Pierre-Yves Chibon |
ed8d1c |
self.assertTrue(os.path.exists(
|
|
Pierre-Yves Chibon |
ed8d1c |
os.path.join(tests.HERE, 'requests', 'project#1.git')))
|
|
Pierre-Yves Chibon |
e5e107 |
|
|
Pierre-Yves Chibon |
893463 |
@patch('pagure.ui.app.admin_session_timedout')
|
|
Pierre-Yves Chibon |
893463 |
def test_user_settings(self, ast):
|
|
Pierre-Yves Chibon |
7958b1 |
""" Test the user_settings endpoint. """
|
|
Pierre-Yves Chibon |
893463 |
ast.return_value = False
|
|
Pierre-Yves Chibon |
7958b1 |
self.test_new_project()
|
|
Pierre-Yves Chibon |
7958b1 |
|
|
Pierre-Yves Chibon |
7958b1 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
fe5017 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
7958b1 |
output = self.app.get('/settings/')
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertTrue('Page not found (404)' in output.data)
|
|
Pierre-Yves Chibon |
7958b1 |
|
|
Pierre-Yves Chibon |
7958b1 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
fe5017 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
7958b1 |
output = self.app.get('/settings/')
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertTrue("foo's settings" in output.data)
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
7958b1 |
'<textarea id="ssh_key" name="ssh_key"></textarea>'
|
|
Pierre-Yves Chibon |
7958b1 |
in output.data)
|
|
Pierre-Yves Chibon |
7958b1 |
|
|
Pierre-Yves Chibon |
7958b1 |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
7958b1 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
7958b1 |
|
|
Pierre-Yves Chibon |
7958b1 |
data = {
|
|
Pierre-Yves Chibon |
7958b1 |
'ssh_key': 'this is my ssh key',
|
|
Pierre-Yves Chibon |
7958b1 |
}
|
|
Pierre-Yves Chibon |
7958b1 |
|
|
Pierre-Yves Chibon |
7958b1 |
output = self.app.post('/settings/', data=data)
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertTrue("foo's settings" in output.data)
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
7958b1 |
'<textarea id="ssh_key" name="ssh_key">this is my ssh key'</textarea>
|
|
Pierre-Yves Chibon |
7958b1 |
'' in output.data)
|
|
Pierre-Yves Chibon |
7958b1 |
|
|
Pierre-Yves Chibon |
7958b1 |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
7958b1 |
|
|
Pierre-Yves Chibon |
7958b1 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7958b1 |
'/settings/', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
7958b1 |
'Public ssh key updated'
|
|
Pierre-Yves Chibon |
7958b1 |
in output.data)
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
7958b1 |
'<section class="project_list" id="repos">' in output.data)</section>
|
|
Pierre-Yves Chibon |
7958b1 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
7958b1 |
'<section class="project_list" id="forks">' in output.data)</section>
|
|
Pierre-Yves Chibon |
7958b1 |
|
|
Pierre-Yves Chibon |
893463 |
ast.return_value = True
|
|
Pierre-Yves Chibon |
893463 |
output = self.app.get('/settings/')
|
|
Pierre-Yves Chibon |
893463 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
893463 |
|
|
Pierre-Yves Chibon |
1ea2d8 |
def test_markdown_preview(self):
|
|
Pierre-Yves Chibon |
1ea2d8 |
""" Test the markdown_preview endpoint. """
|
|
Pierre-Yves Chibon |
1ea2d8 |
|
|
Pierre-Yves Chibon |
1ea2d8 |
data = {
|
|
Pierre-Yves Chibon |
1ea2d8 |
'content': 'test\n----\n\n * 1\n * item 2'
|
|
Pierre-Yves Chibon |
1ea2d8 |
}
|
|
Pierre-Yves Chibon |
1ea2d8 |
|
|
Pierre-Yves Chibon |
f629ce |
# CSRF missing
|
|
Pierre-Yves Chibon |
f629ce |
output = self.app.post('/markdown/', data=data)
|
|
Pierre-Yves Chibon |
f629ce |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
1ea2d8 |
|
|
Pierre-Yves Chibon |
1ea2d8 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
f629ce |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
fe5017 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
f629ce |
output = self.app.get('/settings/')
|
|
Pierre-Yves Chibon |
1ea2d8 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
f629ce |
self.assertTrue("foo's settings" in output.data)
|
|
Pierre-Yves Chibon |
f629ce |
self.assertTrue(
|
|
Pierre-Yves Chibon |
f629ce |
'<textarea id="ssh_key" name="ssh_key"></textarea>'
|
|
Pierre-Yves Chibon |
f629ce |
in output.data)
|
|
Pierre-Yves Chibon |
f629ce |
|
|
Pierre-Yves Chibon |
f629ce |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
f629ce |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
f629ce |
|
|
Pierre-Yves Chibon |
f629ce |
# With CSRF
|
|
Pierre-Yves Chibon |
f629ce |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
f629ce |
output = self.app.post('/markdown/', data=data)
|
|
Pierre-Yves Chibon |
f629ce |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
f629ce |
exp = """test
|
|
Pierre-Yves Chibon |
1ea2d8 |
|
|
Pierre-Yves Chibon |
1ea2d8 |
1
|
|
Pierre-Yves Chibon |
1ea2d8 |
item 2
|
|
Pierre-Yves Chibon |
1ea2d8 |
"""
|
|
Pierre-Yves Chibon |
f629ce |
self.assertEqual(output.data, exp)
|
|
Pierre-Yves Chibon |
1ea2d8 |
|
|
Pierre-Yves Chibon |
c87f24 |
@patch('pagure.ui.app.admin_session_timedout')
|
|
Pierre-Yves Chibon |
c87f24 |
def test_remove_user_email(self, ast):
|
|
Pierre-Yves Chibon |
c87f24 |
""" Test the remove_user_email endpoint. """
|
|
Pierre-Yves Chibon |
c87f24 |
ast.return_value = False
|
|
Pierre-Yves Chibon |
c87f24 |
self.test_new_project()
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
c87f24 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
c87f24 |
output = self.app.post('/settings/email/drop')
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertTrue('Page not found (404)' in output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
c87f24 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
c87f24 |
output = self.app.post('/settings/')
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertTrue("foo's settings" in output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
c87f24 |
'<textarea id="ssh_key" name="ssh_key"></textarea>'
|
|
Pierre-Yves Chibon |
c87f24 |
in output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
c87f24 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
data = {
|
|
Pierre-Yves Chibon |
c87f24 |
'email': 'foo@pingou.com',
|
|
Pierre-Yves Chibon |
c87f24 |
}
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c87f24 |
'/settings/email/drop', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertTrue("foo's settings" in output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c87f24 |
'You must always have at least one email',
|
|
Pierre-Yves Chibon |
c87f24 |
output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
c87f24 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
c87f24 |
output = self.app.post('/settings/')
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertTrue("pingou's settings" in output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
c87f24 |
'<textarea id="ssh_key" name="ssh_key"></textarea>'
|
|
Pierre-Yves Chibon |
c87f24 |
in output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
c87f24 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
data = {
|
|
Pierre-Yves Chibon |
c87f24 |
'email': 'foo@pingou.com',
|
|
Pierre-Yves Chibon |
c87f24 |
}
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c87f24 |
'/settings/email/drop', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertTrue("pingou's settings" in output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.data.count('foo@pingou.com'), 4)
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
data = {
|
|
Pierre-Yves Chibon |
c87f24 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
c87f24 |
'email': 'foobar@pingou.com',
|
|
Pierre-Yves Chibon |
c87f24 |
}
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c87f24 |
'/settings/email/drop', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertTrue("pingou's settings" in output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c87f24 |
'You do not have the email: foobar@pingou'
|
|
Pierre-Yves Chibon |
c87f24 |
'.com, nothing to remove', output.data)
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
data = {
|
|
Pierre-Yves Chibon |
c87f24 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
c87f24 |
'email': 'foo@pingou.com',
|
|
Pierre-Yves Chibon |
c87f24 |
}
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c87f24 |
'/settings/email/drop', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.data.count('foo@pingou.com'), 0)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.data.count('bar@pingou.com'), 3)
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c87f24 |
'/settings/email/drop', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.data.count('foo@pingou.com'), 0)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.data.count('bar@pingou.com'), 3)
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
c87f24 |
ast.return_value = True
|
|
Pierre-Yves Chibon |
c87f24 |
output = self.app.post('/settings/email/drop', data=data)
|
|
Pierre-Yves Chibon |
c87f24 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
c87f24 |
|
|
Pierre-Yves Chibon |
ca16bb |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
ca16bb |
@patch('pagure.ui.app.admin_session_timedout')
|
|
Pierre-Yves Chibon |
ca16bb |
def test_add_user_email(self, ast, send_email):
|
|
Pierre-Yves Chibon |
ca16bb |
""" Test the add_user_email endpoint. """
|
|
Pierre-Yves Chibon |
ca16bb |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
ca16bb |
ast.return_value = False
|
|
Pierre-Yves Chibon |
ca16bb |
self.test_new_project()
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
ca16bb |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
ca16bb |
output = self.app.post('/settings/email/add')
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertTrue('Page not found (404)' in output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
ca16bb |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
ca16bb |
output = self.app.post('/settings/email/add')
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertTrue('Add new email' in output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertTrue(
|
|
Pierre-Yves Chibon |
ca16bb |
'<input id="email" name="email" type="text" value="">'
|
|
Pierre-Yves Chibon |
ca16bb |
in output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
ca16bb |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
ca16bb |
output = self.app.post('/settings/email/add')
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertTrue("Add new email" in output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertTrue(
|
|
Pierre-Yves Chibon |
ca16bb |
'<input id="email" name="email" type="text" value="">'
|
|
Pierre-Yves Chibon |
ca16bb |
in output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
ca16bb |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
data = {
|
|
Pierre-Yves Chibon |
ca16bb |
'email': 'foo@pingou.com',
|
|
Pierre-Yves Chibon |
ca16bb |
}
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ca16bb |
'/settings/email/add', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertTrue("Add new email" in output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.data.count('foo@pingou.com'), 1)
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
# New email
|
|
Pierre-Yves Chibon |
ca16bb |
data = {
|
|
Pierre-Yves Chibon |
ca16bb |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
ca16bb |
'email': 'foobar@pingou.com',
|
|
Pierre-Yves Chibon |
ca16bb |
}
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ca16bb |
'/settings/email/add', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertTrue('pingou\'s settings' in output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertIn(
|
|
Pierre-Yves Chibon |
ca16bb |
'Email pending validation',
|
|
Pierre-Yves Chibon |
ca16bb |
output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.data.count('foo@pingou.com'), 4)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.data.count('bar@pingou.com'), 4)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.data.count('foobar@pingou.com'), 1)
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
# User already has this email
|
|
Pierre-Yves Chibon |
ca16bb |
data = {
|
|
Pierre-Yves Chibon |
ca16bb |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
ca16bb |
'email': 'foo@pingou.com',
|
|
Pierre-Yves Chibon |
ca16bb |
}
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ca16bb |
'/settings/email/add', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertTrue('pingou\'s settings' in output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertIn(
|
|
Pierre-Yves Chibon |
ca16bb |
'The email: foo@pingou.com is already '
|
|
Pierre-Yves Chibon |
ca16bb |
'associated to you', output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.data.count('foo@pingou.com'), 5)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.data.count('bar@pingou.com'), 4)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.data.count('foobar@pingou.com'), 1)
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
# Email registered by someone else
|
|
Pierre-Yves Chibon |
ca16bb |
data = {
|
|
Pierre-Yves Chibon |
ca16bb |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
ca16bb |
'email': 'foo@bar.com',
|
|
Pierre-Yves Chibon |
ca16bb |
}
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ca16bb |
'/settings/email/add', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertTrue("Add new email" in output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertIn(
|
|
Pierre-Yves Chibon |
ca16bb |
'Someone else has already registered this '
|
|
Pierre-Yves Chibon |
ca16bb |
'email', output.data)
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
ca16bb |
ast.return_value = True
|
|
Pierre-Yves Chibon |
ca16bb |
output = self.app.post('/settings/email/add', data=data)
|
|
Pierre-Yves Chibon |
ca16bb |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
ca16bb |
|
|
Pierre-Yves Chibon |
5cae35 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
5cae35 |
@patch('pagure.ui.app.admin_session_timedout')
|
|
Pierre-Yves Chibon |
5cae35 |
def test_set_default_email(self, ast, send_email):
|
|
Pierre-Yves Chibon |
5cae35 |
""" Test the set_default_email endpoint. """
|
|
Pierre-Yves Chibon |
5cae35 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
5cae35 |
ast.return_value = False
|
|
Pierre-Yves Chibon |
5cae35 |
self.test_new_project()
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
5cae35 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
5cae35 |
output = self.app.post('/settings/email/default')
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertTrue('Page not found (404)' in output.data)
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
5cae35 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
5cae35 |
output = self.app.get('/settings/')
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertTrue("pingou's settings" in output.data)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
5cae35 |
'<textarea id="ssh_key" name="ssh_key"></textarea>'
|
|
Pierre-Yves Chibon |
5cae35 |
in output.data)
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
5cae35 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
data = {
|
|
Pierre-Yves Chibon |
5cae35 |
'email': 'foo@pingou.com',
|
|
Pierre-Yves Chibon |
5cae35 |
}
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
5cae35 |
'/settings/email/default', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertTrue("pingou's settings" in output.data)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertEqual(output.data.count('foo@pingou.com'), 4)
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
# Set invalid default email
|
|
Pierre-Yves Chibon |
5cae35 |
data = {
|
|
Pierre-Yves Chibon |
5cae35 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
5cae35 |
'email': 'foobar@pingou.com',
|
|
Pierre-Yves Chibon |
5cae35 |
}
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
5cae35 |
'/settings/email/default', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertTrue("pingou's settings" in output.data)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertEqual(output.data.count('foo@pingou.com'), 4)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertIn(
|
|
Pierre-Yves Chibon |
5cae35 |
'You do not have the email: foobar@pingou'
|
|
Pierre-Yves Chibon |
5cae35 |
'.com, nothing to set', output.data)
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
# Set default email
|
|
Pierre-Yves Chibon |
5cae35 |
data = {
|
|
Pierre-Yves Chibon |
5cae35 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
5cae35 |
'email': 'foo@pingou.com',
|
|
Pierre-Yves Chibon |
5cae35 |
}
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
5cae35 |
'/settings/email/default', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertTrue("pingou's settings" in output.data)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertEqual(output.data.count('foo@pingou.com'), 4)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertIn(
|
|
Pierre-Yves Chibon |
5cae35 |
'Default email set to: foo@pingou.com',
|
|
Pierre-Yves Chibon |
5cae35 |
output.data)
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
5cae35 |
ast.return_value = True
|
|
Pierre-Yves Chibon |
5cae35 |
output = self.app.post('/settings/email/default', data=data)
|
|
Pierre-Yves Chibon |
5cae35 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
5cae35 |
|
|
Pierre-Yves Chibon |
2497e3 |
@patch('pagure.ui.app.admin_session_timedout')
|
|
Pierre-Yves Chibon |
2497e3 |
def test_confirm_email(self, ast):
|
|
Pierre-Yves Chibon |
2497e3 |
""" Test the confirm_email endpoint. """
|
|
Pierre-Yves Chibon |
2497e3 |
output = self.app.get('/settings/email/confirm/foobar')
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
2497e3 |
|
|
Pierre-Yves Chibon |
2497e3 |
ast.return_value = False
|
|
Pierre-Yves Chibon |
2497e3 |
|
|
Pierre-Yves Chibon |
2497e3 |
# Add a pending email to pingou
|
|
Pierre-Yves Chibon |
2497e3 |
userobj = pagure.lib.search_user(self.session, username='pingou')
|
|
Pierre-Yves Chibon |
2497e3 |
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertEqual(len(userobj.emails), 2)
|
|
Pierre-Yves Chibon |
2497e3 |
|
|
Pierre-Yves Chibon |
2497e3 |
email_pend = pagure.lib.model.UserEmailPending(
|
|
Pierre-Yves Chibon |
2497e3 |
user_id=userobj.id,
|
|
Pierre-Yves Chibon |
2497e3 |
email='foo@fp.o',
|
|
Pierre-Yves Chibon |
2497e3 |
token='abcdef',
|
|
Pierre-Yves Chibon |
2497e3 |
)
|
|
Pierre-Yves Chibon |
2497e3 |
self.session.add(email_pend)
|
|
Pierre-Yves Chibon |
2497e3 |
self.session.commit()
|
|
Pierre-Yves Chibon |
2497e3 |
|
|
Pierre-Yves Chibon |
2497e3 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
2497e3 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
2497e3 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
2497e3 |
# Wrong token
|
|
Pierre-Yves Chibon |
2497e3 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
2497e3 |
'/settings/email/confirm/foobar', follow_redirects=True)
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertIn(
|
|
Pierre-Yves Chibon |
2497e3 |
"pingou's settings", output.data)
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertIn(
|
|
Pierre-Yves Chibon |
2497e3 |
'No email associated with this token.',
|
|
Pierre-Yves Chibon |
2497e3 |
output.data)
|
|
Pierre-Yves Chibon |
2497e3 |
|
|
Pierre-Yves Chibon |
2497e3 |
# Confirm email
|
|
Pierre-Yves Chibon |
2497e3 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
2497e3 |
'/settings/email/confirm/abcdef', follow_redirects=True)
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertIn(
|
|
Pierre-Yves Chibon |
2497e3 |
"pingou's settings", output.data)
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertIn(
|
|
Pierre-Yves Chibon |
2497e3 |
'Email validated', output.data)
|
|
Pierre-Yves Chibon |
2497e3 |
|
|
Pierre-Yves Chibon |
2497e3 |
userobj = pagure.lib.search_user(self.session, username='pingou')
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertEqual(len(userobj.emails), 3)
|
|
Pierre-Yves Chibon |
2497e3 |
|
|
Pierre-Yves Chibon |
2497e3 |
ast.return_value = True
|
|
Pierre-Yves Chibon |
2497e3 |
output = self.app.get('/settings/email/confirm/foobar')
|
|
Pierre-Yves Chibon |
2497e3 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
2497e3 |
|
|
Pierre-Yves Chibon |
cfad13 |
|
|
Pierre-Yves Chibon |
cfad13 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
fe5017 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskApptests)
|
|
Pierre-Yves Chibon |
cfad13 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|