Blame tests/test_pagure_lib_drop_issue.py

Pierre-Yves Chibon 179785
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
"""
Pierre-Yves Chibon 179785
 (c) 2017 - Copyright Red Hat Inc
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
 Authors:
Pierre-Yves Chibon 179785
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
"""
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
Pierre-Yves Chibon 179785
import unittest
Pierre-Yves Chibon 179785
import shutil
Pierre-Yves Chibon 179785
import sys
Pierre-Yves Chibon 179785
import os
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
from mock import patch, MagicMock
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 179785
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 930073
import pagure.lib.query
Pierre-Yves Chibon 179785
import pagure.lib.model
Pierre-Yves Chibon 179785
import tests
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
class PagureLibDropIssuetests(tests.Modeltests):
Pierre-Yves Chibon 930073
    """ Tests for pagure.lib.query.drop_issue """
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 179785
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 9881b9
    def setUp(self, p_send_email, p_ugt):
Pierre-Yves Chibon 9881b9
        """ Create a couple of tickets and add tag to the project so we can
Pierre-Yves Chibon 9881b9
        play with them later.
Pierre-Yves Chibon 179785
        """
Pierre-Yves Chibon 9881b9
        super(PagureLibDropIssuetests, self).setUp()
Pierre-Yves Chibon 9881b9
Pierre-Yves Chibon 179785
        p_send_email.return_value = True
Pierre-Yves Chibon 179785
        p_ugt.return_value = True
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 9881b9
Pierre-Yves Chibon 179785
        tests.create_projects(self.session)
Pierre-Yves Chibon 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
        # Before
Pierre-Yves Chibon 930073
        issues = pagure.lib.query.search_issues(self.session, repo)
Pierre-Yves Chibon 179785
        self.assertEqual(len(issues), 0)
Pierre-Yves Chibon 179785
        self.assertEqual(repo.open_tickets, 0)
Pierre-Yves Chibon 179785
        self.assertEqual(repo.open_tickets_public, 0)
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
        # Create two issues to play with
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.new_issue(
Pierre-Yves Chibon 179785
            session=self.session,
Pierre-Yves Chibon 179785
            repo=repo,
Pierre-Yves Chibon 179785
            title='Test issue',
Pierre-Yves Chibon 179785
            content='We should work on this',
Pierre-Yves Chibon 179785
            user='pingou',
Pierre-Yves Chibon 179785
        )
Pierre-Yves Chibon 179785
        self.session.commit()
Pierre-Yves Chibon 179785
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 179785
        self.assertEqual(repo.open_tickets, 1)
Pierre-Yves Chibon 179785
        self.assertEqual(repo.open_tickets_public, 1)
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.new_issue(
Pierre-Yves Chibon 179785
            session=self.session,
Pierre-Yves Chibon 179785
            repo=repo,
Pierre-Yves Chibon 179785
            title='Test issue #2',
Pierre-Yves Chibon 179785
            content='We should work on this for the second time',
Pierre-Yves Chibon 179785
            user='foo',
Pierre-Yves Chibon 179785
            status='Open',
Pierre-Yves Chibon 179785
        )
Pierre-Yves Chibon 179785
        self.session.commit()
Pierre-Yves Chibon 179785
        self.assertEqual(msg.title, 'Test issue #2')
Pierre-Yves Chibon 179785
        self.assertEqual(repo.open_tickets, 2)
Pierre-Yves Chibon 179785
        self.assertEqual(repo.open_tickets_public, 2)
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
        # After
Pierre-Yves Chibon 930073
        issues = pagure.lib.query.search_issues(self.session, repo)
Pierre-Yves Chibon 179785
        self.assertEqual(len(issues), 2)
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
        # Add tag to the project
Pierre-Yves Chibon 930073
        pagure.lib.query.new_tag(
Pierre-Yves Chibon 179785
            self.session,
Pierre-Yves Chibon 179785
            'red',
Pierre-Yves Chibon 179785
            'red tag',
Pierre-Yves Chibon 179785
            '#ff0000',
Pierre-Yves Chibon 179785
            repo.id
Pierre-Yves Chibon 179785
        )
Pierre-Yves Chibon 179785
        self.session.commit()
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 179785
        self.assertEqual(
Pierre-Yves Chibon 179785
            str(repo.tags_colored),
Pierre-Yves Chibon 179785
            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
Pierre-Yves Chibon 179785
        )
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 9881b9
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 9881b9
    @patch('pagure.lib.notify.send_email')
Patrick Uiterwijk 3f97f6
    @patch('pagure.lib.git._maybe_wait', tests.definitely_wait)
Pierre-Yves Chibon 9881b9
    def test_drop_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon 930073
        """ Test the drop_issue of pagure.lib.query.
Pierre-Yves Chibon 9881b9
Pierre-Yves Chibon 9881b9
        We had an issue where we could not delete issue that had been tagged
Pierre-Yves Chibon 9881b9
        with this test, we create two issues, tag one of them and delete
Pierre-Yves Chibon 9881b9
        it, ensuring it all goes well.
Pierre-Yves Chibon 9881b9
        """
Pierre-Yves Chibon 9881b9
        p_send_email.return_value = True
Pierre-Yves Chibon 9881b9
        p_ugt.return_value = True
Pierre-Yves Chibon 9881b9
Pierre-Yves Chibon 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 9881b9
Pierre-Yves Chibon 179785
        # Add tag to the second issue
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 930073
        msgs = pagure.lib.query.update_tags(
Pierre-Yves Chibon 179785
            self.session,
Pierre-Yves Chibon 179785
            issue,
Pierre-Yves Chibon 179785
            tags=['red'],
Pierre-Yves Chibon 179785
            username='pingou',
Pierre-Yves Chibon 179785
        )
Pierre-Yves Chibon 179785
        self.session.commit()
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
        self.assertEqual(msgs, ['Issue tagged with: red'])
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 179785
        self.assertEqual(len(repo.issues), 2)
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 179785
        self.assertEqual(
Pierre-Yves Chibon 179785
            str(issue.tags),
Pierre-Yves Chibon 179785
            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
Pierre-Yves Chibon 179785
        )
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
        # Drop the issue #2
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 930073
        pagure.lib.query.drop_issue(
Patrick Uiterwijk 3f97f6
            self.session, issue, user='pingou')
Pierre-Yves Chibon 179785
        self.session.commit()
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 179785
        self.assertEqual(len(repo.issues), 1)
Pierre-Yves Chibon 179785
Pierre-Yves Chibon a1c98d
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon a1c98d
    @patch('pagure.lib.notify.send_email')
Patrick Uiterwijk 3f97f6
    @patch('pagure.lib.git._maybe_wait', tests.definitely_wait)
Pierre-Yves Chibon a1c98d
    def test_drop_issue_two_issues_one_tag(self, p_send_email, p_ugt):
Pierre-Yves Chibon 930073
        """ Test the drop_issue of pagure.lib.query.
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon a1c98d
        We had an issue where we could not delete issue that had been tagged
Pierre-Yves Chibon a1c98d
        with this test, we create two issues, tag them both and delete one
Pierre-Yves Chibon a1c98d
        then we check that the other issue is still tagged.
Pierre-Yves Chibon a1c98d
        """
Pierre-Yves Chibon a1c98d
        p_send_email.return_value = True
Pierre-Yves Chibon a1c98d
        p_ugt.return_value = True
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon a1c98d
        # Add the tag to both issues
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 930073
        msgs = pagure.lib.query.update_tags(
Pierre-Yves Chibon a1c98d
            self.session,
Pierre-Yves Chibon a1c98d
            issue,
Pierre-Yves Chibon a1c98d
            tags=['red'],
Pierre-Yves Chibon a1c98d
            username='pingou',
Pierre-Yves Chibon a1c98d
        )
Pierre-Yves Chibon a1c98d
        self.session.commit()
Pierre-Yves Chibon a1c98d
        self.assertEqual(msgs, ['Issue tagged with: red'])
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 930073
        msgs = pagure.lib.query.update_tags(
Pierre-Yves Chibon a1c98d
            self.session,
Pierre-Yves Chibon a1c98d
            issue,
Pierre-Yves Chibon a1c98d
            tags=['red'],
Pierre-Yves Chibon a1c98d
            username='pingou',
Pierre-Yves Chibon a1c98d
        )
Pierre-Yves Chibon a1c98d
        self.session.commit()
Pierre-Yves Chibon a1c98d
        self.assertEqual(msgs, ['Issue tagged with: red'])
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon a1c98d
        self.assertEqual(len(repo.issues), 2)
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon a1c98d
        self.assertEqual(
Pierre-Yves Chibon a1c98d
            str(issue.tags),
Pierre-Yves Chibon a1c98d
            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
Pierre-Yves Chibon a1c98d
        )
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon a1c98d
        self.assertEqual(
Pierre-Yves Chibon a1c98d
            str(issue.tags),
Pierre-Yves Chibon a1c98d
            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
Pierre-Yves Chibon a1c98d
        )
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon a1c98d
        # Drop the issue #2
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 930073
        pagure.lib.query.drop_issue(
Patrick Uiterwijk 3f97f6
            self.session, issue, user='pingou')
Pierre-Yves Chibon a1c98d
        self.session.commit()
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon 930073
        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon a1c98d
        self.assertEqual(len(repo.issues), 1)
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon a1c98d
        self.assertEqual(
Pierre-Yves Chibon a1c98d
            str(issue.tags),
Pierre-Yves Chibon a1c98d
            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
Pierre-Yves Chibon a1c98d
        )
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon a1c98d
        self.assertIsNone(issue)
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
if __name__ == '__main__':
Pierre-Yves Chibon 179785
    unittest.main(verbosity=2)