From 5833b398467eec2ed44427b5f6148d69b7c7ca19 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 11 2016 10:35:21 +0000 Subject: Add unit-tests for creating a project with a non-ascii description --- diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index 09a34d3..a443f2a 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -16,6 +16,7 @@ import shutil import sys import os +import six import json from mock import patch @@ -266,6 +267,57 @@ class PagureFlaskApptests(tests.Modeltests): self.assertTrue(os.path.exists( os.path.join(tests.HERE, 'requests', 'project-1.git'))) + def test_non_ascii_new_project(self): + """ Test the new_project endpoint with a non-ascii project. """ + # Before + projects = pagure.lib.search_projects(self.session) + self.assertEqual(len(projects), 0) + self.assertFalse(os.path.exists( + os.path.join(tests.HERE, 'project-1.git'))) + self.assertFalse(os.path.exists( + os.path.join(tests.HERE, 'tickets', 'project-1.git'))) + self.assertFalse(os.path.exists( + os.path.join(tests.HERE, 'docs', 'project-1.git'))) + self.assertFalse(os.path.exists( + os.path.join(tests.HERE, 'requests', 'project-1.git'))) + + user = tests.FakeUser() + user.username = 'foo' + with tests.user_set(pagure.APP, user): + output = self.app.get('/new/') + self.assertEqual(output.status_code, 200) + self.assertIn( + b'Create new Project', output.data) + + csrf_token = output.data.decode('utf-8').split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + data = { + 'description': 'Prõjéctö #1', + 'name': 'project-1', + 'csrf_token': csrf_token, + } + output = self.app.post('/new/', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200)1 + self.assertIn( + '
\nPrõjéctö #1
', + output.data if six.PY2 else output.data.decode('utf-8')) + self.assertIn(b'

This repo is brand new!

', output.data) + self.assertIn( + b'Overview - project-1 - Pagure', output.data) + + # After + projects = pagure.lib.search_projects(self.session) + self.assertEqual(len(projects), 1) + self.assertTrue(os.path.exists( + os.path.join(tests.HERE, 'project-1.git'))) + self.assertTrue(os.path.exists( + os.path.join(tests.HERE, 'tickets', 'project-1.git'))) + self.assertTrue(os.path.exists( + os.path.join(tests.HERE, 'docs', 'project-1.git'))) + self.assertTrue(os.path.exists( + os.path.join(tests.HERE, 'requests', 'project-1.git'))) + @patch('pagure.ui.app.admin_session_timedout') def test_user_settings(self, ast): """ Test the user_settings endpoint. """