Blame tests/test_pagure_flask_ui_repo_milestones.py

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
Aurélien Bompard 626417
from __future__ import unicode_literals
Aurélien Bompard 626417
Pierre-Yves Chibon 0619e5
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 0619e5
import pkg_resources
Pierre-Yves Chibon 0619e5
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 0619e5
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 0619e5
    os.path.abspath(__file__)), '..'))
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 0619e5
    @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 0619e5
        tests.create_projects_git(os.path.join(self.path, 'repos'))
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 930073
        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 0619e5
            title='Test issue #1',
Pierre-Yves Chibon 0619e5
            content='We should work on this for the second time',
Pierre-Yves Chibon 0619e5
            user='foo',
Pierre-Yves Chibon 0619e5
            status='Open',
Pierre-Yves Chibon 0619e5
        )
Pierre-Yves Chibon 0619e5
        self.session.commit()
Pierre-Yves Chibon 0619e5
        self.assertEqual(msg.title, 'Test issue #1')
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 0619e5
    @patch('pagure.decorators.admin_session_timedout',
Pierre-Yves Chibon 0619e5
           MagicMock(return_value=False))
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 930073
        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 0619e5
        user = tests.FakeUser(username='pingou')
Pierre-Yves Chibon 0619e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 0619e5
            output = self.app.get('/test/settings')
Pierre-Yves Chibon 0619e5
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0619e5
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output.get_data(as_text=True))
Pierre-Yves Chibon 0619e5
            # Check that the milestones have their empty fields
Pierre-Yves Chibon 0619e5
            self.assertIn(
Pierre-Yves Chibon 0619e5
            '''
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 ff299a
      ''', output.get_data(as_text=True))
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 0619e5
    @patch('pagure.decorators.admin_session_timedout',
Pierre-Yves Chibon 0619e5
           MagicMock(return_value=False))
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 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 0619e5
        milestones = {
Pierre-Yves Chibon 0619e5
            '1.0': None,
Pierre-Yves Chibon 0619e5
            '1.1': None,
Pierre-Yves Chibon 0619e5
            '1.2': '2018-12-31',
Pierre-Yves Chibon 0619e5
            '2.0': '2019',
Pierre-Yves Chibon 0619e5
            '3.0': 'future',
Pierre-Yves Chibon 0619e5
            '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
            {
Aurélien Bompard 626417
                '1.0': {'active': True, 'date': None},
Aurélien Bompard 626417
                '1.1': {'active': True, 'date': None},
Aurélien Bompard 626417
                '1.2': {'active': True, 'date': '2018-12-31'},
Aurélien Bompard 626417
                '2.0': {'active': True, 'date': '2019'},
Aurélien Bompard 626417
                '3.0': {'active': True, 'date': 'future'},
Aurélien Bompard 626417
                '4.0': {'active': True, 'date': None},
Pierre-Yves Chibon 0619e5
            }
Pierre-Yves Chibon 0619e5
        )
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 0619e5
    @patch('pagure.decorators.admin_session_timedout',
Pierre-Yves Chibon 0619e5
           MagicMock(return_value=False))
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 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 0619e5
        milestones = {
Pierre-Yves Chibon 0619e5
            '1.0': None,
Pierre-Yves Chibon 0619e5
            '2.0': '2019',
Pierre-Yves Chibon 0619e5
            '3.0': 'future',
Pierre-Yves Chibon 0619e5
        }
Pierre-Yves Chibon 0619e5
        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 0619e5
        user = tests.FakeUser(username='pingou')
Pierre-Yves Chibon 0619e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 0619e5
            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>'
Aurélien Bompard 626417
                '', output.get_data(as_text=True)
Pierre-Yves Chibon 0619e5
            )
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 0619e5
    @patch('pagure.decorators.admin_session_timedout',
Pierre-Yves Chibon 0619e5
           MagicMock(return_value=False))
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 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 0619e5
        milestones = {
Pierre-Yves Chibon 0619e5
            '1.0': {'date': None, 'active': False},
Pierre-Yves Chibon 0619e5
            '2.0': {'date': '2018-01-01', 'active': False},
Pierre-Yves Chibon 0619e5
            '3.0': {'date': '2025-01-01', 'active': True},
Pierre-Yves Chibon 0619e5
            '4.0': {'date': 'future', 'active': True},
Pierre-Yves Chibon 0619e5
        }
Pierre-Yves Chibon 0619e5
        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 0619e5
        user = tests.FakeUser(username='pingou')
Pierre-Yves Chibon 0619e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 0619e5
            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>'
Aurélien Bompard 626417
                '', output.get_data(as_text=True)
Pierre-Yves Chibon 0619e5
            )
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 0619e5
Pierre-Yves Chibon 0619e5
if __name__ == '__main__':
Pierre-Yves Chibon 0619e5
    unittest.main(verbosity=2)