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
Aurélien Bompard dcf6f6
from __future__ import unicode_literals
Aurélien Bompard dcf6f6
Pierre-Yves Chibon 179785
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 179785
import pkg_resources
Pierre-Yves Chibon 179785
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
Farhaan Bukhsh 40e9bd
import pagure
Pierre-Yves Chibon 179785
import pagure.lib
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 179785
    """ Tests for pagure.lib.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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 179785
Pierre-Yves Chibon 179785
        # Before
Pierre-Yves Chibon 179785
        issues = pagure.lib.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 179785
        msg = pagure.lib.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
            ticketfolder=None
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 179785
        msg = pagure.lib.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
            ticketfolder=None
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 179785
        issues = pagure.lib.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 179785
        pagure.lib.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 b130e5
        repo = pagure.lib.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')
Pierre-Yves Chibon 9881b9
    def test_drop_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon 9881b9
        """ Test the drop_issue of pagure.lib.
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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 9881b9
Pierre-Yves Chibon 179785
        # Add tag to the second issue
Pierre-Yves Chibon 179785
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 179785
        msgs = pagure.lib.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 ef1fe1
            gitfolder=None,
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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 179785
        self.assertEqual(len(repo.issues), 2)
Pierre-Yves Chibon 179785
        issue = pagure.lib.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 179785
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 179785
        pagure.lib.drop_issue(
Pierre-Yves Chibon 179785
            self.session, issue, user='pingou', ticketfolder=None)
Pierre-Yves Chibon 179785
        self.session.commit()
Pierre-Yves Chibon 179785
Pierre-Yves Chibon b130e5
        repo = pagure.lib.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')
Pierre-Yves Chibon a1c98d
    def test_drop_issue_two_issues_one_tag(self, p_send_email, p_ugt):
Pierre-Yves Chibon a1c98d
        """ Test the drop_issue of pagure.lib.
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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon a1c98d
        # Add the tag to both issues
Pierre-Yves Chibon a1c98d
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon a1c98d
        msgs = pagure.lib.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 ef1fe1
            gitfolder=None,
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 a1c98d
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon a1c98d
        msgs = pagure.lib.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 ef1fe1
            gitfolder=None,
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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon a1c98d
        self.assertEqual(len(repo.issues), 2)
Pierre-Yves Chibon a1c98d
        issue = pagure.lib.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 a1c98d
        issue = pagure.lib.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 a1c98d
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon a1c98d
        pagure.lib.drop_issue(
Pierre-Yves Chibon a1c98d
            self.session, issue, user='pingou', ticketfolder=None)
Pierre-Yves Chibon a1c98d
        self.session.commit()
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon a1c98d
        self.assertEqual(len(repo.issues), 1)
Pierre-Yves Chibon a1c98d
Pierre-Yves Chibon a1c98d
        issue = pagure.lib.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 a1c98d
        issue = pagure.lib.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)