|
Pierre-Yves Chibon |
0619e5 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
"""
|
|
Pierre-Yves Chibon |
0619e5 |
(c) 2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
Authors:
|
|
Pierre-Yves Chibon |
0619e5 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
"""
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Aurélien Bompard |
626417 |
|
|
Pierre-Yves Chibon |
0619e5 |
import sys
|
|
Pierre-Yves Chibon |
0619e5 |
import unittest
|
|
Pierre-Yves Chibon |
0619e5 |
import os
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
from mock import ANY, patch, MagicMock
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
sys.path.insert(
|
|
Pierre-Yves Chibon |
73d120 |
0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
0619e5 |
import tests
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
class PagureFlaskRepoMilestonestests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
0619e5 |
""" Tests for milestones in pagure """
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
0619e5 |
def setUp(self):
|
|
Pierre-Yves Chibon |
0619e5 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
0619e5 |
super(PagureFlaskRepoMilestonestests, self).setUp()
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"))
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
0619e5 |
session=self.session,
|
|
Pierre-Yves Chibon |
0619e5 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this for the second time",
|
|
Pierre-Yves Chibon |
73d120 |
user="foo",
|
|
Pierre-Yves Chibon |
73d120 |
status="Open",
|
|
Pierre-Yves Chibon |
0619e5 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.decorators.admin_session_timedout",
|
|
Pierre-Yves Chibon |
73d120 |
MagicMock(return_value=False),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
def test_milestones_settings_empty(self):
|
|
Pierre-Yves Chibon |
0619e5 |
""" Test the settings page when no milestones are set. """
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
0619e5 |
self.assertEqual(repo.milestones, {})
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
0619e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/settings")
|
|
Pierre-Yves Chibon |
0619e5 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0619e5 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Settings - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
# Check that the milestones have their empty fields
|
|
Pierre-Yves Chibon |
0619e5 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"""
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Akanksha |
d86ac1 |
<input name="milestones" type="hidden" value="1">
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Akanksha |
d86ac1 |
|
|
Pierre-Yves Chibon |
ff299a |
value="" size="3" class="form-control"/>
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Akanksha |
d86ac1 |
|
|
Pierre-Yves Chibon |
ff299a |
value="" class="form-control"/>
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Pierre-Yves Chibon |
ff299a |
data-stone="1">
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Pierre-Yves Chibon |
ff299a |
data-stone="1">
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Akanksha |
d86ac1 |
<input name="milestone_1_active" type="checkbox">
|
|
Pierre-Yves Chibon |
ff299a |
|
|
Pierre-Yves Chibon |
73d120 |
""",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.decorators.admin_session_timedout",
|
|
Pierre-Yves Chibon |
73d120 |
MagicMock(return_value=False),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
def test_setting_retrieving_milestones(self):
|
|
Pierre-Yves Chibon |
0619e5 |
""" Test setting and retrieving milestones off a project. """
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
milestones = {
|
|
Pierre-Yves Chibon |
73d120 |
"1.0": None,
|
|
Pierre-Yves Chibon |
73d120 |
"1.1": None,
|
|
Pierre-Yves Chibon |
73d120 |
"1.2": "2018-12-31",
|
|
Pierre-Yves Chibon |
73d120 |
"2.0": "2019",
|
|
Pierre-Yves Chibon |
73d120 |
"3.0": "future",
|
|
Pierre-Yves Chibon |
73d120 |
"4.0": None,
|
|
Pierre-Yves Chibon |
0619e5 |
}
|
|
Pierre-Yves Chibon |
0619e5 |
repo.milestones = milestones
|
|
Pierre-Yves Chibon |
0619e5 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0619e5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
0619e5 |
repo.milestones,
|
|
Pierre-Yves Chibon |
0619e5 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"1.0": {"active": True, "date": None},
|
|
Pierre-Yves Chibon |
73d120 |
"1.1": {"active": True, "date": None},
|
|
Pierre-Yves Chibon |
73d120 |
"1.2": {"active": True, "date": "2018-12-31"},
|
|
Pierre-Yves Chibon |
73d120 |
"2.0": {"active": True, "date": "2019"},
|
|
Pierre-Yves Chibon |
73d120 |
"3.0": {"active": True, "date": "future"},
|
|
Pierre-Yves Chibon |
73d120 |
"4.0": {"active": True, "date": None},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
0619e5 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.decorators.admin_session_timedout",
|
|
Pierre-Yves Chibon |
73d120 |
MagicMock(return_value=False),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
def test_issue_page_milestone_actives(self):
|
|
Pierre-Yves Chibon |
0619e5 |
""" Test viewing tickets on a project having milestones, all active.
|
|
Pierre-Yves Chibon |
0619e5 |
"""
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
milestones = {"1.0": None, "2.0": "2019", "3.0": "future"}
|
|
Pierre-Yves Chibon |
73d120 |
milestones_keys = ["1.0", "3.0", "2.0"]
|
|
Pierre-Yves Chibon |
0619e5 |
repo.milestones = milestones
|
|
Pierre-Yves Chibon |
0619e5 |
repo.milestones_keys = milestones_keys
|
|
Pierre-Yves Chibon |
0619e5 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0619e5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
0619e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
0619e5 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0619e5 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<select class="form-control c-select" id="milestone" name="milestone">'</select>
|
|
Aurélien Bompard |
626417 |
'<option selected="" value=""></option>'
|
|
Aurélien Bompard |
626417 |
'<option value="1.0">1.0</option>'
|
|
Aurélien Bompard |
626417 |
'<option value="3.0">3.0</option>'
|
|
Aurélien Bompard |
626417 |
'<option value="2.0">2.0</option>'
|
|
Pierre-Yves Chibon |
73d120 |
"",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
0619e5 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.decorators.admin_session_timedout",
|
|
Pierre-Yves Chibon |
73d120 |
MagicMock(return_value=False),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
16317f |
def test_issue_page_milestone_not_allactives(self):
|
|
Pierre-Yves Chibon |
16317f |
""" Test viewing tickets on a project having milestones, not all
|
|
Pierre-Yves Chibon |
16317f |
being active.
|
|
Pierre-Yves Chibon |
0619e5 |
"""
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
milestones = {
|
|
Pierre-Yves Chibon |
73d120 |
"1.0": {"date": None, "active": False},
|
|
Pierre-Yves Chibon |
73d120 |
"2.0": {"date": "2018-01-01", "active": False},
|
|
Pierre-Yves Chibon |
73d120 |
"3.0": {"date": "2025-01-01", "active": True},
|
|
Pierre-Yves Chibon |
73d120 |
"4.0": {"date": "future", "active": True},
|
|
Pierre-Yves Chibon |
0619e5 |
}
|
|
Pierre-Yves Chibon |
73d120 |
milestones_keys = ["1.0", "2.0", "3.0", "4.0"]
|
|
Pierre-Yves Chibon |
0619e5 |
repo.milestones = milestones
|
|
Pierre-Yves Chibon |
0619e5 |
repo.milestones_keys = milestones_keys
|
|
Pierre-Yves Chibon |
0619e5 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0619e5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
0619e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
0619e5 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0619e5 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<select class="form-control c-select" id="milestone" name="milestone">'</select>
|
|
Aurélien Bompard |
626417 |
'<option selected="" value=""></option>'
|
|
Aurélien Bompard |
626417 |
'<option value="3.0">3.0</option>'
|
|
Aurélien Bompard |
626417 |
'<option value="4.0">4.0</option>'
|
|
Pierre-Yves Chibon |
73d120 |
"",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
0619e5 |
)
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
0619e5 |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
0619e5 |
unittest.main(verbosity=2)
|