Blame tests/test_pagure_flask_api_ui_private_repo.py

farhaanbukhsh 1df65f
# -*- coding: utf-8 -*-
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
__requires__ = ['SQLAlchemy >= 0.8']
farhaanbukhsh 1df65f
import pkg_resources
farhaanbukhsh 1df65f
farhaanbukhsh 60d445
import datetime
farhaanbukhsh 1df65f
import unittest
farhaanbukhsh 1df65f
import shutil
farhaanbukhsh 1df65f
import sys
farhaanbukhsh c4f329
import tempfile
farhaanbukhsh 1df65f
import os
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
import json
farhaanbukhsh c4f329
import pygit2
farhaanbukhsh 1df65f
from mock import patch
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
sys.path.insert(0, os.path.join(os.path.dirname(
farhaanbukhsh 1df65f
    os.path.abspath(__file__)), '..'))
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
import pagure.lib
farhaanbukhsh 1df65f
import tests
farhaanbukhsh c4f329
from pagure.lib.repo import PagureRepo
farhaanbukhsh 1df65f
Farhaan Bukhsh 8aa0f5
FULL_ISSUE_LIST = [
Farhaan Bukhsh 8aa0f5
    {
Farhaan Bukhsh 8aa0f5
        "assignee": None,
Farhaan Bukhsh 8aa0f5
        "blocks": [],
Farhaan Bukhsh 8aa0f5
        "close_status": None,
Farhaan Bukhsh 8aa0f5
        "closed_at": None,
Farhaan Bukhsh 8aa0f5
        "comments": [],
Farhaan Bukhsh 8aa0f5
        "content": "We should work on this",
Farhaan Bukhsh 8aa0f5
        "custom_fields": [],
Farhaan Bukhsh 8aa0f5
        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
        "depends": [],
Farhaan Bukhsh 8aa0f5
        "id": 8,
Farhaan Bukhsh 8aa0f5
        "last_updated": "1431414800",
Farhaan Bukhsh 8aa0f5
        "milestone": None,
Farhaan Bukhsh 8aa0f5
        "priority": None,
Farhaan Bukhsh 8aa0f5
        "private": True,
Farhaan Bukhsh 8aa0f5
        "status": "Open",
Farhaan Bukhsh 8aa0f5
        "tags": [],
Farhaan Bukhsh 8aa0f5
        "title": "Test issue",
Farhaan Bukhsh 8aa0f5
        "user": {
Farhaan Bukhsh 8aa0f5
            "fullname": "PY C",
Farhaan Bukhsh 8aa0f5
            "name": "pingou"
Farhaan Bukhsh 8aa0f5
        }
Farhaan Bukhsh 8aa0f5
    },
Farhaan Bukhsh 8aa0f5
    {
Farhaan Bukhsh 8aa0f5
        "assignee": None,
Farhaan Bukhsh 8aa0f5
        "blocks": [],
Farhaan Bukhsh 8aa0f5
        "close_status": None,
Farhaan Bukhsh 8aa0f5
        "closed_at": None,
Farhaan Bukhsh 8aa0f5
        "comments": [],
Farhaan Bukhsh 8aa0f5
        "content": "This issue needs attention",
Farhaan Bukhsh 8aa0f5
        "custom_fields": [],
Farhaan Bukhsh 8aa0f5
        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
        "depends": [],
Farhaan Bukhsh 8aa0f5
        "id": 7,
Farhaan Bukhsh 8aa0f5
        "last_updated": "1431414800",
Farhaan Bukhsh 8aa0f5
        "milestone": None,
Farhaan Bukhsh 8aa0f5
        "priority": None,
Farhaan Bukhsh 8aa0f5
        "private": True,
Farhaan Bukhsh 8aa0f5
        "status": "Open",
Farhaan Bukhsh 8aa0f5
        "tags": [],
Farhaan Bukhsh 8aa0f5
        "title": "test issue",
Farhaan Bukhsh 8aa0f5
        "user": {
Farhaan Bukhsh 8aa0f5
            "fullname": "PY C",
Farhaan Bukhsh 8aa0f5
            "name": "pingou"
Farhaan Bukhsh 8aa0f5
        }
Farhaan Bukhsh 8aa0f5
    },
Farhaan Bukhsh 8aa0f5
    {
Farhaan Bukhsh 8aa0f5
        "assignee": None,
Farhaan Bukhsh 8aa0f5
        "blocks": [],
Farhaan Bukhsh 8aa0f5
        "close_status": None,
Farhaan Bukhsh 8aa0f5
        "closed_at": None,
Farhaan Bukhsh 8aa0f5
        "comments": [],
Farhaan Bukhsh 8aa0f5
        "content": "This issue needs attention",
Farhaan Bukhsh 8aa0f5
        "custom_fields": [],
Farhaan Bukhsh 8aa0f5
        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
        "depends": [],
Farhaan Bukhsh 8aa0f5
        "id": 6,
Farhaan Bukhsh 8aa0f5
        "last_updated": "1431414800",
Farhaan Bukhsh 8aa0f5
        "milestone": None,
Farhaan Bukhsh 8aa0f5
        "priority": None,
Farhaan Bukhsh 8aa0f5
        "private": True,
Farhaan Bukhsh 8aa0f5
        "status": "Open",
Farhaan Bukhsh 8aa0f5
        "tags": [],
Farhaan Bukhsh 8aa0f5
        "title": "test issue",
Farhaan Bukhsh 8aa0f5
        "user": {
Farhaan Bukhsh 8aa0f5
            "fullname": "PY C",
Farhaan Bukhsh 8aa0f5
            "name": "pingou"
Farhaan Bukhsh 8aa0f5
        }
Farhaan Bukhsh 8aa0f5
    },
Farhaan Bukhsh 8aa0f5
    {
Farhaan Bukhsh 8aa0f5
        "assignee": None,
Farhaan Bukhsh 8aa0f5
        "blocks": [],
Farhaan Bukhsh 8aa0f5
        "close_status": None,
Farhaan Bukhsh 8aa0f5
        "closed_at": None,
Farhaan Bukhsh 8aa0f5
        "comments": [],
Farhaan Bukhsh 8aa0f5
        "content": "This issue needs attention",
Farhaan Bukhsh 8aa0f5
        "custom_fields": [],
Farhaan Bukhsh 8aa0f5
        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
        "depends": [],
Farhaan Bukhsh 8aa0f5
        "id": 5,
Farhaan Bukhsh 8aa0f5
        "last_updated": "1431414800",
Farhaan Bukhsh 8aa0f5
        "milestone": None,
Farhaan Bukhsh 8aa0f5
        "priority": None,
Farhaan Bukhsh 8aa0f5
        "private": False,
Farhaan Bukhsh 8aa0f5
        "status": "Open",
Farhaan Bukhsh 8aa0f5
        "tags": [],
Farhaan Bukhsh 8aa0f5
        "title": "test issue",
Farhaan Bukhsh 8aa0f5
        "user": {
Farhaan Bukhsh 8aa0f5
            "fullname": "PY C",
Farhaan Bukhsh 8aa0f5
            "name": "pingou"
Farhaan Bukhsh 8aa0f5
        }
Farhaan Bukhsh 8aa0f5
    },
Farhaan Bukhsh 8aa0f5
    {
Farhaan Bukhsh 8aa0f5
        "assignee": None,
Farhaan Bukhsh 8aa0f5
        "blocks": [],
Farhaan Bukhsh 8aa0f5
        "close_status": None,
Farhaan Bukhsh 8aa0f5
        "closed_at": None,
Farhaan Bukhsh 8aa0f5
        "comments": [],
Farhaan Bukhsh 8aa0f5
        "content": "This issue needs attention",
Farhaan Bukhsh 8aa0f5
        "custom_fields": [],
Farhaan Bukhsh 8aa0f5
        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
        "depends": [],
Farhaan Bukhsh 8aa0f5
        "id": 4,
Farhaan Bukhsh 8aa0f5
        "last_updated": "1431414800",
Farhaan Bukhsh 8aa0f5
        "milestone": None,
Farhaan Bukhsh 8aa0f5
        "priority": None,
Farhaan Bukhsh 8aa0f5
        "private": False,
Farhaan Bukhsh 8aa0f5
        "status": "Open",
Farhaan Bukhsh 8aa0f5
        "tags": [],
Farhaan Bukhsh 8aa0f5
        "title": "test issue",
Farhaan Bukhsh 8aa0f5
        "user": {
Farhaan Bukhsh 8aa0f5
            "fullname": "PY C",
Farhaan Bukhsh 8aa0f5
            "name": "pingou"
Farhaan Bukhsh 8aa0f5
        }
Farhaan Bukhsh 8aa0f5
    },
Farhaan Bukhsh 8aa0f5
    {
Farhaan Bukhsh 8aa0f5
        "assignee": None,
Farhaan Bukhsh 8aa0f5
        "blocks": [],
Farhaan Bukhsh 8aa0f5
        "close_status": None,
Farhaan Bukhsh 8aa0f5
        "closed_at": None,
Farhaan Bukhsh 8aa0f5
        "comments": [],
Farhaan Bukhsh 8aa0f5
        "content": "This issue needs attention",
Farhaan Bukhsh 8aa0f5
        "custom_fields": [],
Farhaan Bukhsh 8aa0f5
        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
        "depends": [],
Farhaan Bukhsh 8aa0f5
        "id": 3,
Farhaan Bukhsh 8aa0f5
        "last_updated": "1431414800",
Farhaan Bukhsh 8aa0f5
        "milestone": None,
Farhaan Bukhsh 8aa0f5
        "priority": None,
Farhaan Bukhsh 8aa0f5
        "private": False,
Farhaan Bukhsh 8aa0f5
        "status": "Open",
Farhaan Bukhsh 8aa0f5
        "tags": [],
Farhaan Bukhsh 8aa0f5
        "title": "test issue",
Farhaan Bukhsh 8aa0f5
        "user": {
Farhaan Bukhsh 8aa0f5
            "fullname": "PY C",
Farhaan Bukhsh 8aa0f5
            "name": "pingou"
Farhaan Bukhsh 8aa0f5
        }
Farhaan Bukhsh 8aa0f5
    },
Farhaan Bukhsh 8aa0f5
    {
Farhaan Bukhsh 8aa0f5
        "assignee": None,
Farhaan Bukhsh 8aa0f5
        "blocks": [],
Farhaan Bukhsh 8aa0f5
        "close_status": None,
Farhaan Bukhsh 8aa0f5
        "closed_at": None,
Farhaan Bukhsh 8aa0f5
        "comments": [],
Farhaan Bukhsh 8aa0f5
        "content": "This issue needs attention",
Farhaan Bukhsh 8aa0f5
        "custom_fields": [],
Farhaan Bukhsh 8aa0f5
        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
        "depends": [],
Farhaan Bukhsh 8aa0f5
        "id": 2,
Farhaan Bukhsh 8aa0f5
        "last_updated": "1431414800",
Farhaan Bukhsh 8aa0f5
        "milestone": None,
Farhaan Bukhsh 8aa0f5
        "priority": None,
Farhaan Bukhsh 8aa0f5
        "private": False,
Farhaan Bukhsh 8aa0f5
        "status": "Open",
Farhaan Bukhsh 8aa0f5
        "tags": [],
Farhaan Bukhsh 8aa0f5
        "title": "test issue",
Farhaan Bukhsh 8aa0f5
        "user": {
Farhaan Bukhsh 8aa0f5
            "fullname": "PY C",
Farhaan Bukhsh 8aa0f5
            "name": "pingou"
Farhaan Bukhsh 8aa0f5
        }
Farhaan Bukhsh 8aa0f5
    },
Farhaan Bukhsh 8aa0f5
    {
Farhaan Bukhsh 8aa0f5
        "assignee": None,
Farhaan Bukhsh 8aa0f5
        "blocks": [],
Farhaan Bukhsh 8aa0f5
        "close_status": None,
Farhaan Bukhsh 8aa0f5
        "closed_at": None,
Farhaan Bukhsh 8aa0f5
        "comments": [],
Farhaan Bukhsh 8aa0f5
        "content": "This issue needs attention",
Farhaan Bukhsh 8aa0f5
        "custom_fields": [],
Farhaan Bukhsh 8aa0f5
        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
        "depends": [],
Farhaan Bukhsh 8aa0f5
        "id": 1,
Farhaan Bukhsh 8aa0f5
        "last_updated": "1431414800",
Farhaan Bukhsh 8aa0f5
        "milestone": None,
Farhaan Bukhsh 8aa0f5
        "priority": None,
Farhaan Bukhsh 8aa0f5
        "private": False,
Farhaan Bukhsh 8aa0f5
        "status": "Open",
Farhaan Bukhsh 8aa0f5
        "tags": [],
Farhaan Bukhsh 8aa0f5
        "title": "test issue",
Farhaan Bukhsh 8aa0f5
        "user": {
Farhaan Bukhsh 8aa0f5
            "fullname": "PY C",
Farhaan Bukhsh 8aa0f5
            "name": "pingou"
Farhaan Bukhsh 8aa0f5
        }
Farhaan Bukhsh 8aa0f5
    }
Farhaan Bukhsh 8aa0f5
]
Farhaan Bukhsh 8aa0f5
farhaanbukhsh 753ee7
farhaanbukhsh 1df65f
class PagurePrivateRepotest(tests.Modeltests):
farhaanbukhsh 1df65f
    """ Tests for private repo in pagure """
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
    def setUp(self):
farhaanbukhsh 1df65f
        """ Set up the environnment, ran before every tests. """
farhaanbukhsh 1df65f
        super(PagurePrivateRepotest, self).setUp()
farhaanbukhsh 1df65f
farhaanbukhsh 4858f8
        pagure.APP.config['TESTING'] = True
farhaanbukhsh c87985
        pagure.APP.config['DATAGREPPER_URL'] = None
Farhaan Bukhsh 3a123d
        pagure.APP.config['PRIVATE_PROJECTS'] = True
farhaanbukhsh 4858f8
        pagure.SESSION = self.session
farhaanbukhsh 4858f8
        pagure.lib.SESSION = self.session
farhaanbukhsh 4858f8
        pagure.ui.SESSION = self.session
farhaanbukhsh 1df65f
        pagure.ui.app.SESSION = self.session
farhaanbukhsh 1df65f
        pagure.ui.filters.SESSION = self.session
farhaanbukhsh 4858f8
        pagure.ui.fork.SESSION = self.session
farhaanbukhsh 1df65f
        pagure.ui.repo.SESSION = self.session
farhaanbukhsh 4858f8
        pagure.ui.issues.SESSION = self.session
farhaanbukhsh 60d445
        pagure.api.SESSION = self.session
farhaanbukhsh 60d445
        pagure.api.project.SESSION = self.session
farhaanbukhsh 44a97a
        pagure.api.fork.SESSION = self.session
farhaanbukhsh 48869c
        pagure.api.issue.SESSION = self.session
farhaanbukhsh 1df65f
Farhaan Bukhsh d59b42
        pagure.APP.config['VIRUS_SCAN_ATTACHMENTS'] = False
Farhaan Bukhsh d59b42
        pagure.APP.config['GIT_FOLDER'] = self.path
farhaanbukhsh 1df65f
        pagure.APP.config['FORK_FOLDER'] = os.path.join(
Farhaan Bukhsh d59b42
            self.path, 'forks')
Farhaan Bukhsh d59b42
        pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
Farhaan Bukhsh d59b42
            self.path, 'requests')
farhaanbukhsh 1df65f
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Farhaan Bukhsh d59b42
            self.path, 'tickets')
farhaanbukhsh 1df65f
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Farhaan Bukhsh d59b42
            self.path, 'docs')
Farhaan Bukhsh d59b42
        pagure.APP.config['UPLOAD_FOLDER_PATH'] = os.path.join(
Farhaan Bukhsh d59b42
            self.path, 'releases')
farhaanbukhsh 1df65f
        self.app = pagure.APP.test_client()
farhaanbukhsh 1df65f
farhaanbukhsh c4f329
    def set_up_git_repo(
farhaanbukhsh c4f329
            self, new_project=None, branch_from='feature', mtype='FF'):
farhaanbukhsh c4f329
        """ Set up the git repo and create the corresponding PullRequest
farhaanbukhsh c4f329
        object.
farhaanbukhsh c4f329
        """
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        # Create a git repo to play with
Farhaan Bukhsh 990ffe
        gitrepo = os.path.join(self.path, 'pmc.git')
farhaanbukhsh c4f329
        repo = pygit2.init_repository(gitrepo, bare=True)
farhaanbukhsh c4f329
farhaanbukhsh 4ea512
        newpath = tempfile.mkdtemp(prefix='pagure-private-test')
farhaanbukhsh 4858f8
        repopath = os.path.join(newpath, 'test')
farhaanbukhsh c4f329
        clone_repo = pygit2.clone_repository(gitrepo, repopath)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        # Create a file in that git repo
farhaanbukhsh c4f329
        with open(os.path.join(repopath, 'sources'), 'w') as stream:
farhaanbukhsh c4f329
            stream.write('foo\n bar')
farhaanbukhsh c4f329
        clone_repo.index.add('sources')
farhaanbukhsh c4f329
        clone_repo.index.write()
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        # Commits the files added
farhaanbukhsh c4f329
        tree = clone_repo.index.write_tree()
farhaanbukhsh c4f329
        author = pygit2.Signature(
farhaanbukhsh c4f329
            'Alice Author', 'alice@authors.tld')
farhaanbukhsh c4f329
        committer = pygit2.Signature(
farhaanbukhsh c4f329
            'Cecil Committer', 'cecil@committers.tld')
farhaanbukhsh c4f329
        clone_repo.create_commit(
farhaanbukhsh c4f329
            'refs/heads/master',  # the name of the reference to update
farhaanbukhsh c4f329
            author,
farhaanbukhsh c4f329
            committer,
farhaanbukhsh c4f329
            'Add sources file for testing',
farhaanbukhsh c4f329
            # binary string representing the tree object ID
farhaanbukhsh c4f329
            tree,
farhaanbukhsh c4f329
            # list of binary strings representing parents of the new commit
farhaanbukhsh c4f329
            []
farhaanbukhsh c4f329
        )
farhaanbukhsh c4f329
        refname = 'refs/heads/master:refs/heads/master'
farhaanbukhsh c4f329
        ori_remote = clone_repo.remotes[0]
farhaanbukhsh c4f329
        PagureRepo.push(ori_remote, refname)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        first_commit = repo.revparse_single('HEAD')
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        if mtype == 'merge':
farhaanbukhsh c4f329
            with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
farhaanbukhsh c4f329
                stream.write('*~')
farhaanbukhsh c4f329
            clone_repo.index.add('.gitignore')
farhaanbukhsh c4f329
            clone_repo.index.write()
farhaanbukhsh c4f329
farhaanbukhsh c4f329
            # Commits the files added
farhaanbukhsh c4f329
            tree = clone_repo.index.write_tree()
farhaanbukhsh c4f329
            author = pygit2.Signature(
farhaanbukhsh c4f329
                'Alice Äuthòr', 'alice@äuthòrs.tld')
farhaanbukhsh c4f329
            committer = pygit2.Signature(
farhaanbukhsh c4f329
                'Cecil Cõmmîttër', 'cecil@cõmmîttërs.tld')
farhaanbukhsh c4f329
            clone_repo.create_commit(
farhaanbukhsh c4f329
                'refs/heads/master',
farhaanbukhsh c4f329
                author,
farhaanbukhsh c4f329
                committer,
farhaanbukhsh c4f329
                'Add .gitignore file for testing',
farhaanbukhsh c4f329
                # binary string representing the tree object ID
farhaanbukhsh c4f329
                tree,
farhaanbukhsh c4f329
                # list of binary strings representing parents of the new commit
farhaanbukhsh c4f329
                [first_commit.oid.hex]
farhaanbukhsh c4f329
            )
farhaanbukhsh c4f329
            refname = 'refs/heads/master:refs/heads/master'
farhaanbukhsh c4f329
            ori_remote = clone_repo.remotes[0]
farhaanbukhsh c4f329
            PagureRepo.push(ori_remote, refname)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        if mtype == 'conflicts':
farhaanbukhsh c4f329
            with open(os.path.join(repopath, 'sources'), 'w') as stream:
farhaanbukhsh c4f329
                stream.write('foo\n bar\nbaz')
farhaanbukhsh c4f329
            clone_repo.index.add('sources')
farhaanbukhsh c4f329
            clone_repo.index.write()
farhaanbukhsh c4f329
farhaanbukhsh c4f329
            # Commits the files added
farhaanbukhsh c4f329
            tree = clone_repo.index.write_tree()
farhaanbukhsh c4f329
            author = pygit2.Signature(
farhaanbukhsh c4f329
                'Alice Author', 'alice@authors.tld')
farhaanbukhsh c4f329
            committer = pygit2.Signature(
farhaanbukhsh c4f329
                'Cecil Committer', 'cecil@committers.tld')
farhaanbukhsh c4f329
            clone_repo.create_commit(
farhaanbukhsh c4f329
                'refs/heads/master',
farhaanbukhsh c4f329
                author,
farhaanbukhsh c4f329
                committer,
farhaanbukhsh c4f329
                'Add sources conflicting',
farhaanbukhsh c4f329
                # binary string representing the tree object ID
farhaanbukhsh c4f329
                tree,
farhaanbukhsh c4f329
                # list of binary strings representing parents of the new commit
farhaanbukhsh c4f329
                [first_commit.oid.hex]
farhaanbukhsh c4f329
            )
farhaanbukhsh c4f329
            refname = 'refs/heads/master:refs/heads/master'
farhaanbukhsh c4f329
            ori_remote = clone_repo.remotes[0]
farhaanbukhsh c4f329
            PagureRepo.push(ori_remote, refname)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        # Set the second repo
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        new_gitrepo = repopath
farhaanbukhsh c4f329
        if new_project:
farhaanbukhsh c4f329
            # Create a new git repo to play with
farhaanbukhsh c4f329
            new_gitrepo = os.path.join(newpath, new_project.fullname)
farhaanbukhsh c4f329
            if not os.path.exists(new_gitrepo):
farhaanbukhsh c4f329
                os.makedirs(new_gitrepo)
farhaanbukhsh c4f329
                new_repo = pygit2.clone_repository(gitrepo, new_gitrepo)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        repo = pygit2.Repository(new_gitrepo)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        if mtype != 'nochanges':
farhaanbukhsh c4f329
            # Edit the sources file again
farhaanbukhsh c4f329
            with open(os.path.join(new_gitrepo, 'sources'), 'w') as stream:
farhaanbukhsh c4f329
                stream.write('foo\n bar\nbaz\n boose')
farhaanbukhsh c4f329
            repo.index.add('sources')
farhaanbukhsh c4f329
            repo.index.write()
farhaanbukhsh c4f329
farhaanbukhsh c4f329
            # Commits the files added
farhaanbukhsh c4f329
            tree = repo.index.write_tree()
farhaanbukhsh c4f329
            author = pygit2.Signature(
farhaanbukhsh c4f329
                'Alice Author', 'alice@authors.tld')
farhaanbukhsh c4f329
            committer = pygit2.Signature(
farhaanbukhsh c4f329
                'Cecil Committer', 'cecil@committers.tld')
farhaanbukhsh c4f329
            repo.create_commit(
farhaanbukhsh c4f329
                'refs/heads/%s' % branch_from,
farhaanbukhsh c4f329
                author,
farhaanbukhsh c4f329
                committer,
farhaanbukhsh c4f329
                'A commit on branch %s' % branch_from,
farhaanbukhsh c4f329
                tree,
farhaanbukhsh c4f329
                [first_commit.oid.hex]
farhaanbukhsh c4f329
            )
farhaanbukhsh c4f329
            refname = 'refs/heads/%s' % (branch_from)
farhaanbukhsh c4f329
            ori_remote = repo.remotes[0]
farhaanbukhsh c4f329
            PagureRepo.push(ori_remote, refname)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        # Create a PR for these changes
Farhaan Bukhsh 839011
        project = pagure.lib._get_project(self.session, 'pmc')
farhaanbukhsh c4f329
        req = pagure.lib.new_pull_request(
farhaanbukhsh c4f329
            session=self.session,
farhaanbukhsh c4f329
            repo_from=project,
farhaanbukhsh c4f329
            branch_from=branch_from,
farhaanbukhsh c4f329
            repo_to=project,
farhaanbukhsh c4f329
            branch_to='master',
farhaanbukhsh c4f329
            title='PR from the %s branch' % branch_from,
farhaanbukhsh c4f329
            user='pingou',
farhaanbukhsh c4f329
            requestfolder=None,
farhaanbukhsh c4f329
        )
farhaanbukhsh c4f329
        self.session.commit()
farhaanbukhsh c4f329
        self.assertEqual(req.id, 1)
farhaanbukhsh c4f329
        self.assertEqual(req.title, 'PR from the %s branch' % branch_from)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        shutil.rmtree(newpath)
farhaanbukhsh c4f329
farhaanbukhsh 1df65f
    def test_index(self):
farhaanbukhsh 1df65f
        """ Test the index endpoint. """
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        output = self.app.get('/')
farhaanbukhsh 1df65f
        self.assertEqual(output.status_code, 200)
farhaanbukhsh 1df65f
        self.assertIn(
farhaanbukhsh 1df65f
            '

All Projects '

farhaanbukhsh c87985
            '0', output.get_data(as_text=True))
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        # Add a private project
farhaanbukhsh 1df65f
        item = pagure.lib.model.Project(
farhaanbukhsh 1df65f
            user_id=2,  # foo
farhaanbukhsh 1df65f
            name='test3',
farhaanbukhsh 1df65f
            description='test project description',
farhaanbukhsh 1df65f
            hook_token='aaabbbeee',
farhaanbukhsh 1df65f
            private=True,
farhaanbukhsh 1df65f
        )
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        self.session.add(item)
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        # Add a public project
farhaanbukhsh 1df65f
        item = pagure.lib.model.Project(
farhaanbukhsh 1df65f
            user_id=2,  # foo
farhaanbukhsh 1df65f
            name='test4',
farhaanbukhsh 1df65f
            description='test project description',
farhaanbukhsh 1df65f
            hook_token='aaabbbeeeccceee',
farhaanbukhsh 1df65f
        )
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        self.session.add(item)
farhaanbukhsh 1df65f
        self.session.commit()
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        output = self.app.get('/?page=abc')
farhaanbukhsh 1df65f
        self.assertEqual(output.status_code, 200)
farhaanbukhsh 1df65f
        self.assertIn(
farhaanbukhsh 1df65f
            '

All Projects '

farhaanbukhsh c87985
            '1', output.get_data(as_text=True))
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        user = tests.FakeUser(username='foo')
farhaanbukhsh 1df65f
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 3604c1
            output = self.app.get('/')
farhaanbukhsh 1df65f
            self.assertIn(
Pierre-Yves Chibon 3604c1
                'My Projects 2',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh 1df65f
            self.assertIn(
farhaanbukhsh 1df65f
                'Forks 0',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh 1df65f
            self.assertEqual(
farhaanbukhsh c87985
                output.get_data(as_text=True).count('

No group found

'), 1)
farhaanbukhsh 1df65f
            self.assertEqual(
Farhaan Bukhsh 02f421
                output.get_data(as_text=True).count('
'), 6)
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
    def test_view_user(self):
farhaanbukhsh 1df65f
        """ Test the view_user endpoint. """
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        output = self.app.get('/user/foo?repopage=abc&forkpage=def')
farhaanbukhsh 1df65f
        self.assertEqual(output.status_code, 200)
farhaanbukhsh 1df65f
        self.assertIn(
farhaanbukhsh 1df65f
            'Projects 0',
farhaanbukhsh c87985
            output.get_data(as_text=True))
farhaanbukhsh 1df65f
        self.assertIn(
farhaanbukhsh 1df65f
            'Forks 0',
farhaanbukhsh c87985
            output.get_data(as_text=True))
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        # Add a private project
farhaanbukhsh 1df65f
        item = pagure.lib.model.Project(
farhaanbukhsh 1df65f
            user_id=2,  # foo
farhaanbukhsh 1df65f
            name='test3',
farhaanbukhsh 1df65f
            description='test project description',
farhaanbukhsh 1df65f
            hook_token='aaabbbeee',
farhaanbukhsh 1df65f
            private=True,
farhaanbukhsh 1df65f
        )
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        self.session.add(item)
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        # Add a public project
farhaanbukhsh 1df65f
        item = pagure.lib.model.Project(
farhaanbukhsh 1df65f
            user_id=2,  # foo
farhaanbukhsh 1df65f
            name='test4',
farhaanbukhsh 1df65f
            description='test project description',
farhaanbukhsh 1df65f
            hook_token='aaabbbeeeccceee',
farhaanbukhsh 1df65f
        )
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        self.session.add(item)
farhaanbukhsh 1df65f
        self.session.commit()
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        self.gitrepos = tests.create_projects_git(
farhaanbukhsh 1df65f
            pagure.APP.config['GIT_FOLDER'])
farhaanbukhsh 1df65f
Pierre-Yves Chibon 3604c1
        output = self.app.get('/user/foo')
farhaanbukhsh 1df65f
        self.assertEqual(output.status_code, 200)
farhaanbukhsh 1df65f
        self.assertIn(
farhaanbukhsh 1df65f
            'Projects 1',
farhaanbukhsh c87985
            output.get_data(as_text=True))
farhaanbukhsh 1df65f
        self.assertIn(
farhaanbukhsh c87985
            'Forks 0', output.get_data(as_text=True))
farhaanbukhsh 1df65f
farhaanbukhsh 1df65f
        user = tests.FakeUser(username='foo')
farhaanbukhsh 1df65f
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 3604c1
            output = self.app.get('/user/foo')
farhaanbukhsh 1df65f
            self.assertIn(
farhaanbukhsh 1df65f
                'Projects 2',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh 1df65f
            self.assertIn(
farhaanbukhsh 1df65f
                'Forks 0',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh 1df65f
            self.assertEqual(
farhaanbukhsh c87985
                output.get_data(as_text=True).count('

No group found

'), 1)
farhaanbukhsh 1df65f
            self.assertEqual(
Farhaan Bukhsh 02f421
                output.get_data(as_text=True).count('
'), 5)
farhaanbukhsh 1df65f
farhaanbukhsh b909de
        user.username = 'pingou'
farhaanbukhsh 1df65f
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 3604c1
            output = self.app.get('/user/foo')
farhaanbukhsh 1df65f
            self.assertIn(
farhaanbukhsh 1df65f
                'Projects 1',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh 1df65f
            self.assertIn(
farhaanbukhsh 1df65f
                'Forks 0',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh 1df65f
            self.assertEqual(
farhaanbukhsh c87985
                output.get_data(as_text=True).count('

No group found

'), 1)
farhaanbukhsh 1df65f
            self.assertEqual(
Farhaan Bukhsh 02f421
                output.get_data(as_text=True).count('
'), 5)
farhaanbukhsh 1df65f
farhaanbukhsh d59922
        # Check pingou has 0 projects
farhaanbukhsh d59922
        user.username = 'pingou'
farhaanbukhsh d59922
        with tests.user_set(pagure.APP, user):
farhaanbukhsh d59922
            output = self.app.get('/')
farhaanbukhsh d59922
            self.assertIn(
farhaanbukhsh d59922
                'My Projects 0',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh d59922
            self.assertIn(
farhaanbukhsh d59922
                'Forks 0',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh d59922
            self.assertEqual(
farhaanbukhsh c87985
                output.get_data(as_text=True).count('

No group found

'), 1)
farhaanbukhsh d59922
            self.assertEqual(
Farhaan Bukhsh 02f421
                output.get_data(as_text=True).count('
'), 6)
farhaanbukhsh d59922
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test3')
farhaanbukhsh b909de
farhaanbukhsh b909de
        msg = pagure.lib.add_user_to_project(
farhaanbukhsh b6711e
            session=self.session,
farhaanbukhsh b6711e
            project=repo,
farhaanbukhsh b6711e
            new_user='pingou',
farhaanbukhsh b6711e
            user='foo',
farhaanbukhsh b6711e
        )
farhaanbukhsh b909de
        self.assertEqual(msg, 'User added')
farhaanbukhsh b6711e
farhaanbukhsh b6711e
        # New user added to private projects
farhaanbukhsh b909de
        user.username = 'pingou'
farhaanbukhsh b6711e
        with tests.user_set(pagure.APP, user):
farhaanbukhsh b6711e
            output = self.app.get('/')
farhaanbukhsh b6711e
            self.assertIn(
farhaanbukhsh b6711e
                'My Projects 1',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh b6711e
            self.assertIn(
farhaanbukhsh b6711e
                'Forks 0',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh b6711e
            self.assertEqual(
farhaanbukhsh c87985
                output.get_data(as_text=True).count('

No group found

'), 1)
farhaanbukhsh b6711e
            self.assertEqual(
Farhaan Bukhsh 02f421
                output.get_data(as_text=True).count('
'), 6)
farhaanbukhsh b6711e
farhaanbukhsh c4f329
    @patch('pagure.ui.repo.admin_session_timedout')
farhaanbukhsh c4f329
    def test_private_settings_ui(self, ast):
farhaanbukhsh c4f329
        """ Test UI for private repo"""
farhaanbukhsh c4f329
farhaanbukhsh b909de
        # Add private repo
farhaanbukhsh 0163a1
        item = pagure.lib.model.Project(
farhaanbukhsh 0163a1
            user_id=1,  # pingou
farhaanbukhsh 0163a1
            name='test4',
farhaanbukhsh 0163a1
            description='test project description',
farhaanbukhsh 0163a1
            hook_token='aaabbbeeeceee',
farhaanbukhsh 0163a1
            private=True,
farhaanbukhsh 0163a1
        )
farhaanbukhsh 0163a1
        self.session.add(item)
farhaanbukhsh 0163a1
        self.session.commit()
farhaanbukhsh 0163a1
farhaanbukhsh 0163a1
        # Add a git repo
farhaanbukhsh b909de
        repo_path = os.path.join(
farhaanbukhsh b909de
            pagure.APP.config.get('GIT_FOLDER'), 'test4.git')
farhaanbukhsh 0163a1
        if not os.path.exists(repo_path):
farhaanbukhsh 0163a1
            os.makedirs(repo_path)
farhaanbukhsh 0163a1
        pygit2.init_repository(repo_path)
farhaanbukhsh 0163a1
farhaanbukhsh c4f329
        user = tests.FakeUser(username='pingou')
farhaanbukhsh c4f329
        with tests.user_set(pagure.APP, user):
farhaanbukhsh c4f329
            tests.create_projects(self.session)
farhaanbukhsh 4858f8
            tests.create_projects_git(pagure.APP.config.get('GIT_FOLDER'))
farhaanbukhsh c4f329
farhaanbukhsh c4f329
            ast.return_value = False
farhaanbukhsh c4f329
            output = self.app.post('/test/settings')
farhaanbukhsh c4f329
farhaanbukhsh 0163a1
            # Check for a public repo
farhaanbukhsh c4f329
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c4f329
            self.assertIn(
farhaanbukhsh c87985
                '
farhaanbukhsh c4f329
farhaanbukhsh 0163a1
            ast.return_value = False
farhaanbukhsh 0163a1
            output = self.app.post('/test4/settings')
farhaanbukhsh 0163a1
farhaanbukhsh 0163a1
            # Check for private repo
farhaanbukhsh 0163a1
            self.assertEqual(output.status_code, 200)
farhaanbukhsh 0163a1
            self.assertIn(
farhaanbukhsh c87985
                '<input checked="" name="private" type="checkbox" value="private">', output.get_data(as_text=True))
farhaanbukhsh 0163a1
farhaanbukhsh fc046c
            # Check the new project form has 'private' checkbox
farhaanbukhsh fc046c
            output = self.app.get('/new')
farhaanbukhsh fc046c
            self.assertEqual(output.status_code, 200)
farhaanbukhsh fc046c
            self.assertIn(
farhaanbukhsh c87985
                '<input id="private" name="private" type="checkbox" value="y">', output.get_data(as_text=True))
farhaanbukhsh 0163a1
farhaanbukhsh 4ea512
    @patch('pagure.lib.notify.send_email')
farhaanbukhsh 4ea512
    def test_private_pr(self, send_email):
farhaanbukhsh c4f329
        """Test pull request made to the private repo"""
farhaanbukhsh c4f329
farhaanbukhsh 4ea512
        send_email.return_value = True
farhaanbukhsh c4f329
        # Add a private project
farhaanbukhsh c4f329
        item = pagure.lib.model.Project(
farhaanbukhsh c4f329
            user_id=1,  # pingou
farhaanbukhsh c4f329
            name='pmc',
farhaanbukhsh c4f329
            description='test project description',
farhaanbukhsh c4f329
            hook_token='aaabbbeeeceee',
farhaanbukhsh c4f329
            private=True,
farhaanbukhsh c4f329
        )
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        self.session.add(item)
farhaanbukhsh c4f329
        self.session.commit()
farhaanbukhsh c4f329
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'pmc')
farhaanbukhsh f889f7
farhaanbukhsh f889f7
        msg = pagure.lib.add_user_to_project(
farhaanbukhsh f889f7
            session=self.session,
farhaanbukhsh f889f7
            project=repo,
farhaanbukhsh f889f7
            new_user='foo',
farhaanbukhsh f889f7
            user='pingou',
farhaanbukhsh f889f7
        )
farhaanbukhsh f889f7
        self.session.commit()
farhaanbukhsh f889f7
        self.assertEqual(msg, 'User added')
farhaanbukhsh f889f7
farhaanbukhsh c4f329
        # Create all the git repos
farhaanbukhsh c4f329
        tests.create_projects_git(
Farhaan Bukhsh 02f421
            os.path.join(self.path, 'requests'), bare=True)
farhaanbukhsh c4f329
farhaanbukhsh 1432c1
        # Add a git repo
farhaanbukhsh b909de
        repo_path = os.path.join(
farhaanbukhsh b909de
            pagure.APP.config.get('REQUESTS_FOLDER'), 'pmc.git')
farhaanbukhsh 1432c1
        if not os.path.exists(repo_path):
farhaanbukhsh 1432c1
            os.makedirs(repo_path)
farhaanbukhsh 1432c1
        pygit2.init_repository(repo_path, bare=True)
farhaanbukhsh c4f329
        # Check repo was created
farhaanbukhsh c4f329
        user = tests.FakeUser(username='pingou')
farhaanbukhsh c4f329
        with tests.user_set(pagure.APP, user):
farhaanbukhsh c4f329
            output = self.app.get('/user/pingou/')
farhaanbukhsh c4f329
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c4f329
            self.assertIn(
farhaanbukhsh c4f329
                '
\n Projects
farhaanbukhsh c87985
                'class="label label-default">1', output.get_data(as_text=True))
farhaanbukhsh c4f329
            self.assertIn(
farhaanbukhsh c4f329
                'Forks 0',
farhaanbukhsh c87985
                output.get_data(as_text=True))
farhaanbukhsh c4f329
farhaanbukhsh c4f329
            self.set_up_git_repo(new_project=None, branch_from='feature')
Farhaan Bukhsh 839011
            project = pagure.lib._get_project(self.session, 'pmc')
farhaanbukhsh c4f329
            self.assertEqual(len(project.requests), 1)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
            output = self.app.get('/pmc/pull-request/1')
farhaanbukhsh c4f329
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        # Check repo was created
farhaanbukhsh c4f329
        user = tests.FakeUser()
farhaanbukhsh c4f329
        with tests.user_set(pagure.APP, user):
farhaanbukhsh c4f329
            output = self.app.get('/pmc/pull-requests')
farhaanbukhsh e9261e
            self.assertEqual(output.status_code, 404)
farhaanbukhsh c4f329
farhaanbukhsh c4f329
        user = tests.FakeUser(username='pingou')
farhaanbukhsh c4f329
        with tests.user_set(pagure.APP, user):
farhaanbukhsh c4f329
            output = self.app.get('/pmc/pull-requests')
farhaanbukhsh 1432c1
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c4f329
farhaanbukhsh f889f7
        user = tests.FakeUser(username='foo')
farhaanbukhsh f889f7
        with tests.user_set(pagure.APP, user):
farhaanbukhsh f889f7
            output = self.app.get('/pmc/pull-requests')
farhaanbukhsh f889f7
            self.assertEqual(output.status_code, 200)
farhaanbukhsh f889f7
farhaanbukhsh 420a97
    @patch('pagure.lib.git.update_git')
farhaanbukhsh 420a97
    @patch('pagure.lib.notify.send_email')
farhaanbukhsh 420a97
    def test_private_repo_issues_ui(self, p_send_email, p_ugt):
farhaanbukhsh 420a97
        """ Test issues made to private repo"""
farhaanbukhsh 420a97
        p_send_email.return_value = True
farhaanbukhsh 420a97
        p_ugt.return_value = True
farhaanbukhsh 420a97
farhaanbukhsh 420a97
        # Add private repo
farhaanbukhsh 420a97
        item = pagure.lib.model.Project(
farhaanbukhsh 420a97
            user_id=1,  # pingou
farhaanbukhsh 420a97
            name='test4',
farhaanbukhsh 420a97
            description='test project description',
farhaanbukhsh 420a97
            hook_token='aaabbbeeeceee',
farhaanbukhsh 420a97
            private=True,
farhaanbukhsh 420a97
        )
farhaanbukhsh 420a97
        self.session.add(item)
farhaanbukhsh 420a97
        self.session.commit()
farhaanbukhsh 420a97
farhaanbukhsh d59922
        for repo in ['GIT_FOLDER', 'TICKETS_FOLDER']:
farhaanbukhsh d59922
            # Add a git repo
farhaanbukhsh d59922
            repo_path = os.path.join(
farhaanbukhsh d59922
                pagure.APP.config.get(repo), 'test4.git')
farhaanbukhsh d59922
            if not os.path.exists(repo_path):
farhaanbukhsh d59922
                os.makedirs(repo_path)
farhaanbukhsh d59922
            pygit2.init_repository(repo_path)
farhaanbukhsh 420a97
farhaanbukhsh 44a97a
        # Check if the private repo issues are publicly not accesible
farhaanbukhsh 420a97
        output = self.app.get('/test4/issues')
farhaanbukhsh e9261e
        self.assertEqual(output.status_code, 404)
farhaanbukhsh 420a97
farhaanbukhsh 420a97
        # Create issues to play with
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh 420a97
        msg = pagure.lib.new_issue(
farhaanbukhsh 420a97
            session=self.session,
farhaanbukhsh 420a97
            repo=repo,
farhaanbukhsh 420a97
            title='Test issue',
farhaanbukhsh 420a97
            content='We should work on this',
farhaanbukhsh 420a97
            user='pingou',
farhaanbukhsh 420a97
            ticketfolder=None
farhaanbukhsh 420a97
        )
farhaanbukhsh 420a97
        self.session.commit()
farhaanbukhsh 420a97
        self.assertEqual(msg.title, 'Test issue')
farhaanbukhsh 420a97
farhaanbukhsh 420a97
        user = tests.FakeUser()
farhaanbukhsh 420a97
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 420a97
farhaanbukhsh 420a97
            # Whole list
farhaanbukhsh 420a97
            output = self.app.get('/test4/issues')
farhaanbukhsh e9261e
            self.assertEqual(output.status_code, 404)
farhaanbukhsh 420a97
farhaanbukhsh 420a97
            # Check single issue
farhaanbukhsh 420a97
            output = self.app.get('/test4/issue/1')
farhaanbukhsh e9261e
            self.assertEqual(output.status_code, 404)
farhaanbukhsh 420a97
farhaanbukhsh 44a97a
        user = tests.FakeUser()
farhaanbukhsh 44a97a
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 44a97a
farhaanbukhsh 44a97a
            # Whole list
farhaanbukhsh 44a97a
            output = self.app.get('/test4/issues')
farhaanbukhsh 44a97a
            self.assertEqual(output.status_code, 404)
farhaanbukhsh 44a97a
farhaanbukhsh 420a97
        user = tests.FakeUser(username='pingou')
farhaanbukhsh 420a97
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 420a97
farhaanbukhsh 420a97
            # Whole list
farhaanbukhsh 420a97
            output = self.app.get('/test4/issues')
farhaanbukhsh 420a97
            self.assertEqual(output.status_code, 200)
farhaanbukhsh d59922
            self.assertIn(
farhaanbukhsh c87985
                '<title>Issues - test4 - Pagure</title>', output.get_data(as_text=True))
farhaanbukhsh 420a97
            self.assertTrue(
farhaanbukhsh c87985
                '

\n 1 Open Issues' in output.get_data(as_text=True))

farhaanbukhsh 420a97
farhaanbukhsh 420a97
            # Check single issue
farhaanbukhsh 420a97
            output = self.app.get('/test4/issue/1')
farhaanbukhsh 420a97
            self.assertEqual(output.status_code, 200)
farhaanbukhsh 420a97
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh f889f7
farhaanbukhsh f889f7
        msg = pagure.lib.add_user_to_project(
farhaanbukhsh f889f7
            session=self.session,
farhaanbukhsh f889f7
            project=repo,
farhaanbukhsh f889f7
            new_user='foo',
farhaanbukhsh f889f7
            user='pingou',
farhaanbukhsh f889f7
        )
farhaanbukhsh f889f7
        self.session.commit()
farhaanbukhsh f889f7
        self.assertEqual(msg, 'User added')
farhaanbukhsh f889f7
farhaanbukhsh d59922
        user.username = 'foo'
farhaanbukhsh f889f7
        with tests.user_set(pagure.APP, user):
farhaanbukhsh f889f7
farhaanbukhsh f889f7
            # Whole list
farhaanbukhsh f889f7
            output = self.app.get('/test4/issues')
farhaanbukhsh f889f7
            self.assertEqual(output.status_code, 200)
farhaanbukhsh d59922
            self.assertIn(
farhaanbukhsh c87985
                '<title>Issues - test4 - Pagure</title>', output.get_data(as_text=True))
farhaanbukhsh f889f7
            self.assertTrue(
farhaanbukhsh c87985
                '

\n 1 Open Issues' in output.get_data(as_text=True))

farhaanbukhsh f889f7
farhaanbukhsh f889f7
            # Check single issue
farhaanbukhsh f889f7
            output = self.app.get('/test4/issue/1')
farhaanbukhsh f889f7
            self.assertEqual(output.status_code, 200)
farhaanbukhsh f889f7
farhaanbukhsh 7ca1b1
    # API checks
farhaanbukhsh 7ca1b1
    def test_api_private_repo_projects(self):
farhaanbukhsh 7ca1b1
        """ Test api points for private repo for projects"""
farhaanbukhsh 60d445
farhaanbukhsh 60d445
        # Add private repo
farhaanbukhsh 60d445
        item = pagure.lib.model.Project(
farhaanbukhsh 60d445
            user_id=1,  # pingou
farhaanbukhsh 60d445
            name='test4',
farhaanbukhsh 60d445
            description='test project description',
farhaanbukhsh 60d445
            hook_token='aaabbbeeeceee',
farhaanbukhsh 60d445
            private=True,
farhaanbukhsh 60d445
        )
farhaanbukhsh 60d445
        self.session.add(item)
farhaanbukhsh 60d445
        self.session.commit()
farhaanbukhsh 60d445
farhaanbukhsh 60d445
        # Create a git repo to play with
Farhaan Bukhsh 02f421
        gitrepo = os.path.join(self.path, 'test4.git')
farhaanbukhsh 60d445
        repo = pygit2.init_repository(gitrepo, bare=True)
farhaanbukhsh 60d445
farhaanbukhsh 60d445
        newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
farhaanbukhsh 60d445
        repopath = os.path.join(newpath, 'test4')
farhaanbukhsh 60d445
        clone_repo = pygit2.clone_repository(gitrepo, repopath)
farhaanbukhsh 60d445
        # Create a file in that git repo
farhaanbukhsh 60d445
        with open(os.path.join(repopath, 'sources'), 'w') as stream:
farhaanbukhsh 60d445
            stream.write('foo\n bar')
farhaanbukhsh 60d445
        clone_repo.index.add('sources')
farhaanbukhsh 60d445
        clone_repo.index.write()
farhaanbukhsh 60d445
farhaanbukhsh 60d445
        # Commits the files added
farhaanbukhsh 60d445
        tree = clone_repo.index.write_tree()
farhaanbukhsh 60d445
        author = pygit2.Signature(
farhaanbukhsh 60d445
            'Alice Author', 'alice@authors.tld')
farhaanbukhsh 60d445
        committer = pygit2.Signature(
farhaanbukhsh 60d445
            'Cecil Committer', 'cecil@committers.tld')
farhaanbukhsh 60d445
        clone_repo.create_commit(
farhaanbukhsh 60d445
            'refs/heads/master',  # the name of the reference to update
farhaanbukhsh 60d445
            author,
farhaanbukhsh 60d445
            committer,
farhaanbukhsh 60d445
            'Add sources file for testing',
farhaanbukhsh 60d445
            # binary string representing the tree object ID
farhaanbukhsh 60d445
            tree,
farhaanbukhsh 60d445
            # list of binary strings representing parents of the new commit
farhaanbukhsh 60d445
            []
farhaanbukhsh 60d445
        )
farhaanbukhsh 60d445
        refname = 'refs/heads/master:refs/heads/master'
farhaanbukhsh 60d445
        ori_remote = clone_repo.remotes[0]
farhaanbukhsh 60d445
        PagureRepo.push(ori_remote, refname)
farhaanbukhsh 60d445
farhaanbukhsh 60d445
        # Tag our first commit
farhaanbukhsh 60d445
        first_commit = repo.revparse_single('HEAD')
farhaanbukhsh 60d445
        tagger = pygit2.Signature('Alice Doe', 'adoe@example.com', 12347, 0)
farhaanbukhsh 60d445
        repo.create_tag(
farhaanbukhsh 60d445
            "0.0.1", first_commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger,
farhaanbukhsh 60d445
            "Release 0.0.1")
farhaanbukhsh 60d445
farhaanbukhsh 60d445
        # Create a token for foo for this project
farhaanbukhsh 60d445
        item = pagure.lib.model.Token(
farhaanbukhsh 60d445
            id='foobar_token',
farhaanbukhsh 60d445
            user_id=1,
farhaanbukhsh 60d445
            project_id=1,
farhaanbukhsh 60d445
            expiration=datetime.datetime.utcnow() + datetime.timedelta(
farhaanbukhsh 60d445
                days=30)
farhaanbukhsh 60d445
        )
farhaanbukhsh 60d445
        self.session.add(item)
farhaanbukhsh 60d445
        self.session.commit()
farhaanbukhsh 60d445
        item = pagure.lib.model.TokenAcl(
farhaanbukhsh 60d445
            token_id='foobar_token',
farhaanbukhsh d59922
            acl_id=1,
farhaanbukhsh 60d445
        )
farhaanbukhsh 60d445
        self.session.add(item)
farhaanbukhsh 60d445
        self.session.commit()
farhaanbukhsh 60d445
farhaanbukhsh 753ee7
        # Check if the admin requests
farhaanbukhsh 753ee7
        user = tests.FakeUser(username='pingou')
farhaanbukhsh 753ee7
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 753ee7
            # Check tags
farhaanbukhsh 753ee7
            output = self.app.get('/api/0/test4/git/tags')
farhaanbukhsh 753ee7
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 753ee7
            self.assertDictEqual(
farhaanbukhsh 753ee7
                data,
farhaanbukhsh 753ee7
                {'tags': ['0.0.1'], 'total_tags': 1}
farhaanbukhsh 753ee7
            )
farhaanbukhsh 753ee7
farhaanbukhsh 753ee7
        output = self.app.get('/api/0/test4/git/tags')
farhaanbukhsh 753ee7
        self.assertEqual(output.status_code, 404)
farhaanbukhsh 60d445
farhaanbukhsh 753ee7
        # Chekc if user is not admin
farhaanbukhsh 753ee7
        user = tests.FakeUser()
farhaanbukhsh 753ee7
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 753ee7
            output = self.app.get('/api/0/test4/git/tags')
farhaanbukhsh 753ee7
            self.assertEqual(output.status_code, 404)
farhaanbukhsh 60d445
farhaanbukhsh 60d445
        shutil.rmtree(newpath)
Pierre-Yves Chibon 3604c1
farhaanbukhsh 7ca1b1
        # Check before adding
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh 7ca1b1
        self.assertEqual(repo.tags, [])
farhaanbukhsh 7ca1b1
farhaanbukhsh 7ca1b1
        # Adding a tag
farhaanbukhsh 7ca1b1
        output = pagure.lib.update_tags(
farhaanbukhsh 7ca1b1
            self.session, repo, 'infra', 'pingou',
farhaanbukhsh 7ca1b1
            ticketfolder=None)
farhaanbukhsh 7ca1b1
        self.assertEqual(output, ['Tag added: infra'])
farhaanbukhsh 7ca1b1
farhaanbukhsh 7ca1b1
        # Check after adding
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh 7ca1b1
        self.assertEqual(len(repo.tags), 1)
farhaanbukhsh 7ca1b1
        self.assertEqual(repo.tags_text, ['infra'])
farhaanbukhsh 7ca1b1
farhaanbukhsh 7ca1b1
        # Check the API
farhaanbukhsh 7ca1b1
        output = self.app.get('/api/0/projects?tags=inf')
farhaanbukhsh 7ca1b1
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 7ca1b1
        self.assertDictEqual(
farhaanbukhsh 7ca1b1
            data,
farhaanbukhsh 7ca1b1
            {'error_code': 'ENOPROJECTS', 'error': 'No projects found'}
farhaanbukhsh 7ca1b1
        )
farhaanbukhsh 7ca1b1
farhaanbukhsh 7ca1b1
        # Request by not a loggged in user
farhaanbukhsh 7ca1b1
        output = self.app.get('/api/0/projects?tags=infra')
farhaanbukhsh 7ca1b1
        self.assertEqual(output.status_code, 404)
farhaanbukhsh 7ca1b1
farhaanbukhsh 7ca1b1
        user = tests.FakeUser()
farhaanbukhsh 7ca1b1
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 7ca1b1
            # Request by a non authorized user
farhaanbukhsh 7ca1b1
            output = self.app.get('/api/0/projects?tags=infra')
farhaanbukhsh 7ca1b1
            self.assertEqual(output.status_code, 404)
farhaanbukhsh 7ca1b1
farhaanbukhsh 7ca1b1
        user.username = 'pingou'
farhaanbukhsh 7ca1b1
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 7ca1b1
            # Private repo username is compulsion to pass
farhaanbukhsh 7ca1b1
            output = self.app.get('/api/0/projects?tags=infra')
farhaanbukhsh 7ca1b1
            self.assertEqual(output.status_code, 404)
farhaanbukhsh 7ca1b1
farhaanbukhsh 7ca1b1
            output = self.app.get('/api/0/projects?username=pingou')
farhaanbukhsh 7ca1b1
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 7ca1b1
            data['projects'][0]['date_created'] = "1436527638"
farhaanbukhsh 7ca1b1
            self.assertDictEqual(
farhaanbukhsh 7ca1b1
                data,
farhaanbukhsh 7ca1b1
                {
Farhaan Bukhsh 8aa0f5
                    "args": {
Farhaan Bukhsh 8aa0f5
                        "fork": None,
Farhaan Bukhsh 8aa0f5
                        "pattern": None,
Farhaan Bukhsh 8aa0f5
                        "tags": [],
Farhaan Bukhsh 8aa0f5
                        "username": "pingou"
Farhaan Bukhsh 8aa0f5
                    },
Farhaan Bukhsh 8aa0f5
farhaanbukhsh 7ca1b1
                    "total_projects": 1,
farhaanbukhsh 7ca1b1
                    "projects": [
farhaanbukhsh 7ca1b1
                        {
Farhaan Bukhsh 990ffe
                            "close_status": [],
Farhaan Bukhsh 990ffe
                            "custom_keys": [],
farhaanbukhsh 7ca1b1
                            "date_created": "1436527638",
farhaanbukhsh 7ca1b1
                            "description": "test project description",
farhaanbukhsh 7ca1b1
                            "id": 1,
Farhaan Bukhsh 990ffe
                            "milestones": {},
farhaanbukhsh 7ca1b1
                            "name": "test4",
Farhaan Bukhsh 990ffe
                            "namespace": None,
farhaanbukhsh 7ca1b1
                            "parent": None,
farhaanbukhsh 7ca1b1
                            "priorities": {},
farhaanbukhsh 7ca1b1
                            "tags": ["infra"],
farhaanbukhsh 7ca1b1
                            "user": {
farhaanbukhsh 7ca1b1
                                "fullname": "PY C",
farhaanbukhsh 7ca1b1
                                "name": "pingou"
farhaanbukhsh 7ca1b1
                            }
farhaanbukhsh 7ca1b1
                        },
farhaanbukhsh 7ca1b1
                    ]
farhaanbukhsh 7ca1b1
                }
farhaanbukhsh 7ca1b1
            )
farhaanbukhsh 7ca1b1
farhaanbukhsh 7ca1b1
            output = self.app.get('/api/0/projects?username=pingou&tags=infra')
farhaanbukhsh 7ca1b1
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 7ca1b1
            data['projects'][0]['date_created'] = "1436527638"
farhaanbukhsh 7ca1b1
            self.assertDictEqual(
farhaanbukhsh 7ca1b1
                data,
farhaanbukhsh 7ca1b1
                {
Farhaan Bukhsh 8aa0f5
                    "args": {
Farhaan Bukhsh 8aa0f5
                        "fork": None,
Farhaan Bukhsh 8aa0f5
                        "pattern": None,
Farhaan Bukhsh 8aa0f5
                        "tags": ["infra"],
Farhaan Bukhsh 8aa0f5
                        "username": "pingou"
Farhaan Bukhsh 8aa0f5
                    },
farhaanbukhsh 7ca1b1
                    "total_projects": 1,
farhaanbukhsh 7ca1b1
                    "projects": [
farhaanbukhsh 7ca1b1
                        {
Farhaan Bukhsh 990ffe
                            "close_status": [],
Farhaan Bukhsh 990ffe
                            "custom_keys": [],
farhaanbukhsh 7ca1b1
                            "date_created": "1436527638",
farhaanbukhsh 7ca1b1
                            "description": "test project description",
farhaanbukhsh 7ca1b1
                            "id": 1,
Farhaan Bukhsh 990ffe
                            "milestones": {},
farhaanbukhsh 7ca1b1
                            "name": "test4",
Farhaan Bukhsh 990ffe
                            "namespace": None,
farhaanbukhsh 7ca1b1
                            "parent": None,
farhaanbukhsh 7ca1b1
                            "priorities": {},
farhaanbukhsh 7ca1b1
                            "tags": ["infra"],
farhaanbukhsh 7ca1b1
                            "user": {
farhaanbukhsh 7ca1b1
                                "fullname": "PY C",
farhaanbukhsh 7ca1b1
                                "name": "pingou"
farhaanbukhsh 7ca1b1
                            }
farhaanbukhsh 7ca1b1
                        }
farhaanbukhsh 7ca1b1
                    ]
farhaanbukhsh 7ca1b1
                }
Farhaan Bukhsh 990ffe
farhaanbukhsh 7ca1b1
            )
farhaanbukhsh 7ca1b1
farhaanbukhsh 44a97a
    # Api pull-request views
farhaanbukhsh 44a97a
    @patch('pagure.lib.notify.send_email')
farhaanbukhsh e3c47c
    def test_api_private_repo_fork(self, send_email):
farhaanbukhsh 44a97a
        """ Test api endpoints in api/fork"""
farhaanbukhsh 44a97a
farhaanbukhsh 44a97a
        send_email.return_value = True
farhaanbukhsh fd8d2a
farhaanbukhsh 44a97a
        # Add private repo
farhaanbukhsh 44a97a
        item = pagure.lib.model.Project(
farhaanbukhsh 44a97a
            user_id=1,  # pingou
farhaanbukhsh 44a97a
            name='test4',
farhaanbukhsh 44a97a
            description='test project description',
farhaanbukhsh 44a97a
            hook_token='aaabbbeeeceee',
farhaanbukhsh 44a97a
            private=True,
farhaanbukhsh 44a97a
        )
farhaanbukhsh 44a97a
        self.session.add(item)
farhaanbukhsh 44a97a
        self.session.commit()
farhaanbukhsh 44a97a
farhaanbukhsh fd8d2a
        tests.create_tokens(self.session)
farhaanbukhsh fd8d2a
        tests.create_tokens_acl(self.session)
farhaanbukhsh 44a97a
farhaanbukhsh fd8d2a
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh 44a97a
        # Create a pull-request
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
Farhaan Bukhsh 839011
        forked_repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh 44a97a
        req = pagure.lib.new_pull_request(
farhaanbukhsh 44a97a
            session=self.session,
farhaanbukhsh 44a97a
            repo_from=forked_repo,
farhaanbukhsh 44a97a
            branch_from='master',
farhaanbukhsh 44a97a
            repo_to=repo,
farhaanbukhsh 44a97a
            branch_to='master',
farhaanbukhsh 44a97a
            title='test pull-request',
farhaanbukhsh 44a97a
            user='pingou',
farhaanbukhsh 44a97a
            requestfolder=None,
farhaanbukhsh 44a97a
        )
farhaanbukhsh 44a97a
        self.session.commit()
farhaanbukhsh 44a97a
        self.assertEqual(req.id, 1)
farhaanbukhsh 44a97a
        self.assertEqual(req.title, 'test pull-request')
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        # Check list of PR
farhaanbukhsh 44a97a
        output = self.app.get('/api/0/test4/pull-requests')
farhaanbukhsh 44a97a
        self.assertEqual(output.status_code, 404)
farhaanbukhsh 44a97a
farhaanbukhsh fd8d2a
        # Check single PR
farhaanbukhsh fd8d2a
        output = self.app.get('/api/0/test/pull-request/1')
farhaanbukhsh fd8d2a
        self.assertEqual(output.status_code, 404)
farhaanbukhsh fd8d2a
farhaanbukhsh 44a97a
        user = tests.FakeUser(username='pingou')
farhaanbukhsh 44a97a
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 44a97a
            # List pull-requests
farhaanbukhsh 44a97a
            output = self.app.get('/api/0/test4/pull-requests')
farhaanbukhsh 44a97a
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 44a97a
            data['requests'][0]['date_created'] = '1431414800'
farhaanbukhsh 44a97a
            data['requests'][0]['updated_on'] = '1431414800'
farhaanbukhsh 44a97a
            data['requests'][0]['project']['date_created'] = '1431414800'
farhaanbukhsh 44a97a
            data['requests'][0]['repo_from']['date_created'] = '1431414800'
farhaanbukhsh 44a97a
            data['requests'][0]['uid'] = '1431414800'
Farhaan Bukhsh 8aa0f5
            data['requests'][0]['last_updated'] = '1431414800'
farhaanbukhsh 44a97a
            self.assertDictEqual(
farhaanbukhsh 44a97a
                data,
farhaanbukhsh 44a97a
                {
Farhaan Bukhsh 02f421
                    "args": {
Farhaan Bukhsh 02f421
                        "assignee": None,
Farhaan Bukhsh 02f421
                        "author": None,
Farhaan Bukhsh 02f421
                        "status": True
Farhaan Bukhsh 02f421
                    },
Farhaan Bukhsh 02f421
                    "requests": [
Farhaan Bukhsh 02f421
                        {
Farhaan Bukhsh 02f421
                            "assignee": None,
Farhaan Bukhsh 02f421
                            "branch": "master",
Farhaan Bukhsh 02f421
                            "branch_from": "master",
Farhaan Bukhsh 02f421
                            "closed_at": None,
Farhaan Bukhsh 02f421
                            "closed_by": None,
Farhaan Bukhsh 02f421
                            "comments": [],
Farhaan Bukhsh 02f421
                            "commit_start": None,
Farhaan Bukhsh 02f421
                            "commit_stop": None,
Farhaan Bukhsh 02f421
                            "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
                            "last_updated": "1431414800",
Farhaan Bukhsh 02f421
                            "id": 1,
Farhaan Bukhsh 02f421
                            "initial_comment": None,
Farhaan Bukhsh 02f421
                            "project": {
Farhaan Bukhsh 02f421
                                "close_status": [],
Farhaan Bukhsh 02f421
                                "custom_keys": [],
Farhaan Bukhsh 02f421
                                "date_created": "1431414800",
Farhaan Bukhsh 02f421
                                "description": "test project description",
Farhaan Bukhsh 02f421
                                "id": 1,
Farhaan Bukhsh 02f421
                                "milestones": {},
Farhaan Bukhsh 02f421
                                "name": "test4",
Farhaan Bukhsh 02f421
                                "namespace": None,
Farhaan Bukhsh 02f421
                                "parent": None,
Farhaan Bukhsh 02f421
                                "priorities": {},
Farhaan Bukhsh 02f421
                                "tags": [],
Farhaan Bukhsh 02f421
                                "user": {
Farhaan Bukhsh 02f421
                                    "fullname": "PY C",
Farhaan Bukhsh 02f421
                                    "name": "pingou"
Farhaan Bukhsh 02f421
                                }
Farhaan Bukhsh 02f421
                            },
Farhaan Bukhsh 02f421
                            "remote_git": None,
Farhaan Bukhsh 02f421
                            "repo_from": {
Farhaan Bukhsh 02f421
                                "close_status": [],
Farhaan Bukhsh 02f421
                                "custom_keys": [],
Farhaan Bukhsh 02f421
                                "date_created": "1431414800",
Farhaan Bukhsh 02f421
                                "description": "test project description",
Farhaan Bukhsh 02f421
                                "id": 1,
Farhaan Bukhsh 02f421
                                "milestones": {},
Farhaan Bukhsh 02f421
                                "name": "test4",
Farhaan Bukhsh 02f421
                                "namespace": None,
Farhaan Bukhsh 02f421
                                "parent": None,
Farhaan Bukhsh 02f421
                                "priorities": {},
Farhaan Bukhsh 02f421
                                "tags": [],
Farhaan Bukhsh 02f421
                                "user": {
Farhaan Bukhsh 02f421
                                    "fullname": "PY C",
Farhaan Bukhsh 02f421
                                    "name": "pingou"
Farhaan Bukhsh 02f421
                                }
Farhaan Bukhsh 02f421
                            },
Farhaan Bukhsh 02f421
                            "status": "Open",
Farhaan Bukhsh 02f421
                            "title": "test pull-request",
Farhaan Bukhsh 02f421
                            "uid": "1431414800",
Farhaan Bukhsh 02f421
                            "updated_on": "1431414800",
Farhaan Bukhsh 02f421
                            "user": {
Farhaan Bukhsh 02f421
                                "fullname": "PY C",
Farhaan Bukhsh 02f421
                                "name": "pingou"
Farhaan Bukhsh 02f421
                            }
Farhaan Bukhsh 02f421
                        }
Farhaan Bukhsh 02f421
                    ],
Farhaan Bukhsh 02f421
                    "total_requests": 1
Farhaan Bukhsh 65b71a
                }
farhaanbukhsh 44a97a
            )
farhaanbukhsh 44a97a
            headers = {'Authorization': 'token foobar_token'}
farhaanbukhsh 44a97a
farhaanbukhsh 44a97a
            # Access Pull-Request authenticated
farhaanbukhsh e3c47c
            output = self.app.get(
farhaanbukhsh e3c47c
                '/api/0/test4/pull-requests', headers=headers)
farhaanbukhsh 44a97a
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data2 = json.loads(output.get_data(as_text=True))
farhaanbukhsh 44a97a
            data2['requests'][0]['date_created'] = '1431414800'
farhaanbukhsh 44a97a
            data2['requests'][0]['updated_on'] = '1431414800'
farhaanbukhsh 44a97a
            data2['requests'][0]['project']['date_created'] = '1431414800'
farhaanbukhsh 44a97a
            data2['requests'][0]['repo_from']['date_created'] = '1431414800'
farhaanbukhsh 44a97a
            data2['requests'][0]['uid'] = '1431414800'
Farhaan Bukhsh 8aa0f5
            data2['requests'][0]['last_updated'] = '1431414800'
farhaanbukhsh 44a97a
            self.assertDictEqual(data, data2)
farhaanbukhsh 44a97a
farhaanbukhsh fd8d2a
            # For single PR
farhaanbukhsh f693ef
            output = self.app.get('/api/0/test4/pull-request/1')
farhaanbukhsh f693ef
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh f693ef
            data['date_created'] = '1431414800'
farhaanbukhsh f693ef
            data['updated_on'] = '1431414800'
farhaanbukhsh f693ef
            data['project']['date_created'] = '1431414800'
farhaanbukhsh f693ef
            data['repo_from']['date_created'] = '1431414800'
farhaanbukhsh f693ef
            data['uid'] = '1431414800'
Farhaan Bukhsh 8aa0f5
            data['last_updated'] = '1431414800'
farhaanbukhsh f693ef
            self.assertDictEqual(
farhaanbukhsh f693ef
                data,
Farhaan Bukhsh 02f421
                {
Farhaan Bukhsh 02f421
                    "assignee": None,
Farhaan Bukhsh 02f421
                    "branch": "master",
Farhaan Bukhsh 02f421
                    "branch_from": "master",
Farhaan Bukhsh 02f421
                    "closed_at": None,
Farhaan Bukhsh 02f421
                    "closed_by": None,
Farhaan Bukhsh 02f421
                    "comments": [],
Farhaan Bukhsh 02f421
                    "commit_start": None,
Farhaan Bukhsh 02f421
                    "commit_stop": None,
Farhaan Bukhsh 02f421
                    "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
                    "last_updated": "1431414800",
Farhaan Bukhsh 02f421
                    "id": 1,
Farhaan Bukhsh 02f421
                    "initial_comment": None,
Farhaan Bukhsh 02f421
                    "project": {
Farhaan Bukhsh 02f421
                        "close_status": [],
Farhaan Bukhsh 02f421
                        "custom_keys": [],
Farhaan Bukhsh 02f421
                        "date_created": "1431414800",
Farhaan Bukhsh 02f421
                        "description": "test project description",
Farhaan Bukhsh 02f421
                        "id": 1,
Farhaan Bukhsh 02f421
                        "milestones": {},
Farhaan Bukhsh 02f421
                        "name": "test4",
Farhaan Bukhsh 02f421
                        "namespace": None,
Farhaan Bukhsh 02f421
                        "parent": None,
Farhaan Bukhsh 02f421
                        "priorities": {},
Farhaan Bukhsh 02f421
                        "tags": [],
Farhaan Bukhsh 02f421
                        "user": {
Farhaan Bukhsh 02f421
                            "fullname": "PY C",
Farhaan Bukhsh 02f421
                            "name": "pingou"
Farhaan Bukhsh 02f421
                        }
Farhaan Bukhsh 02f421
                    },
Farhaan Bukhsh 02f421
                    "remote_git": None,
Farhaan Bukhsh 02f421
                    "repo_from": {
Farhaan Bukhsh 02f421
                        "close_status": [],
Farhaan Bukhsh 02f421
                        "custom_keys": [],
Farhaan Bukhsh 02f421
                        "date_created": "1431414800",
Farhaan Bukhsh 02f421
                        "description": "test project description",
Farhaan Bukhsh 02f421
                        "id": 1,
Farhaan Bukhsh 02f421
                        "milestones": {},
Farhaan Bukhsh 02f421
                        "name": "test4",
Farhaan Bukhsh 02f421
                        "namespace": None,
Farhaan Bukhsh 02f421
                        "parent": None,
Farhaan Bukhsh 02f421
                        "priorities": {},
Farhaan Bukhsh 02f421
                        "tags": [],
Farhaan Bukhsh 02f421
                        "user": {
Farhaan Bukhsh 02f421
                            "fullname": "PY C",
Farhaan Bukhsh 02f421
                            "name": "pingou"
Farhaan Bukhsh 02f421
                        }
Farhaan Bukhsh 02f421
                    },
Farhaan Bukhsh 02f421
                    "status": "Open",
Farhaan Bukhsh 02f421
                    "title": "test pull-request",
Farhaan Bukhsh 02f421
                    "uid": "1431414800",
Farhaan Bukhsh 02f421
                    "updated_on": "1431414800",
Farhaan Bukhsh 02f421
                    "user": {
Farhaan Bukhsh 02f421
                        "fullname": "PY C",
Farhaan Bukhsh 02f421
                        "name": "pingou"
Farhaan Bukhsh 02f421
                    }
Farhaan Bukhsh 65b71a
                }
Farhaan Bukhsh 65b71a
farhaanbukhsh f693ef
            )
farhaanbukhsh f693ef
farhaanbukhsh f693ef
            # Access Pull-Request authenticated
farhaanbukhsh e3c47c
            output = self.app.get(
farhaanbukhsh e3c47c
                '/api/0/test4/pull-request/1', headers=headers)
farhaanbukhsh f693ef
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data2 = json.loads(output.get_data(as_text=True))
farhaanbukhsh f693ef
            data2['date_created'] = '1431414800'
farhaanbukhsh f693ef
            data2['project']['date_created'] = '1431414800'
farhaanbukhsh f693ef
            data2['repo_from']['date_created'] = '1431414800'
farhaanbukhsh f693ef
            data2['uid'] = '1431414800'
farhaanbukhsh f693ef
            data2['date_created'] = '1431414800'
farhaanbukhsh f693ef
            data2['updated_on'] = '1431414800'
Farhaan Bukhsh 8aa0f5
            data2['last_updated'] = '1431414800'
farhaanbukhsh f693ef
            self.assertDictEqual(data, data2)
farhaanbukhsh f693ef
farhaanbukhsh fd8d2a
    @patch('pagure.lib.notify.send_email')
farhaanbukhsh fd8d2a
    def test_api_pr_private_repo_add_comment(self, mockemail):
farhaanbukhsh fd8d2a
        """ Test the api_pull_request_add_comment method of the flask api. """
farhaanbukhsh fd8d2a
        mockemail.return_value = True
farhaanbukhsh fd8d2a
        pagure.APP.config['REQUESTS_FOLDER'] = None
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        # Add private repo
farhaanbukhsh fd8d2a
        item = pagure.lib.model.Project(
farhaanbukhsh fd8d2a
            user_id=1,  # pingou
farhaanbukhsh fd8d2a
            name='test4',
farhaanbukhsh fd8d2a
            description='test project description',
farhaanbukhsh fd8d2a
            hook_token='aaabbbeeeceee',
farhaanbukhsh fd8d2a
            private=True,
farhaanbukhsh fd8d2a
        )
farhaanbukhsh fd8d2a
        self.session.add(item)
farhaanbukhsh fd8d2a
        self.session.commit()
farhaanbukhsh fd8d2a
        tests.create_tokens(self.session)
farhaanbukhsh fd8d2a
        tests.create_tokens_acl(self.session)
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh fd8d2a
        # Create a pull-request
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
Farhaan Bukhsh 839011
        forked_repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh fd8d2a
        req = pagure.lib.new_pull_request(
farhaanbukhsh fd8d2a
            session=self.session,
farhaanbukhsh fd8d2a
            repo_from=forked_repo,
farhaanbukhsh fd8d2a
            branch_from='master',
farhaanbukhsh fd8d2a
            repo_to=repo,
farhaanbukhsh fd8d2a
            branch_to='master',
farhaanbukhsh fd8d2a
            title='test pull-request',
farhaanbukhsh fd8d2a
            user='pingou',
farhaanbukhsh fd8d2a
            requestfolder=None,
farhaanbukhsh fd8d2a
        )
farhaanbukhsh fd8d2a
        self.session.commit()
farhaanbukhsh fd8d2a
        self.assertEqual(req.id, 1)
farhaanbukhsh fd8d2a
        self.assertEqual(req.title, 'test pull-request')
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        # Check comments before
farhaanbukhsh fd8d2a
        request = pagure.lib.search_pull_requests(
farhaanbukhsh fd8d2a
            self.session, project_id=1, requestid=1)
farhaanbukhsh fd8d2a
        self.assertEqual(len(request.comments), 0)
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        data = {
farhaanbukhsh fd8d2a
            'title': 'test issue',
farhaanbukhsh fd8d2a
        }
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        # Incomplete request
farhaanbukhsh fd8d2a
        output = self.app.post(
farhaanbukhsh fd8d2a
            '/api/0/test4/pull-request/1/comment', data=data, headers=headers)
farhaanbukhsh fd8d2a
        self.assertEqual(output.status_code, 400)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh fd8d2a
        self.assertDictEqual(
farhaanbukhsh fd8d2a
            data,
farhaanbukhsh fd8d2a
            {
farhaanbukhsh e3c47c
                "error": "Invalid or incomplete input submited",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDREQ",
Farhaan Bukhsh 8aa0f5
                "errors": {"comment": ["This field is required."]}
farhaanbukhsh fd8d2a
            }
farhaanbukhsh fd8d2a
        )
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        # No change
farhaanbukhsh fd8d2a
        request = pagure.lib.search_pull_requests(
farhaanbukhsh fd8d2a
            self.session, project_id=1, requestid=1)
farhaanbukhsh fd8d2a
        self.assertEqual(len(request.comments), 0)
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        data = {
farhaanbukhsh fd8d2a
            'comment': 'This is a very interesting question',
farhaanbukhsh fd8d2a
        }
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        # Valid request
farhaanbukhsh fd8d2a
        output = self.app.post(
farhaanbukhsh fd8d2a
            '/api/0/test4/pull-request/1/comment', data=data, headers=headers)
farhaanbukhsh fd8d2a
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh fd8d2a
        self.assertDictEqual(
farhaanbukhsh fd8d2a
            data,
farhaanbukhsh fd8d2a
            {'message': 'Comment added'}
farhaanbukhsh fd8d2a
        )
farhaanbukhsh fd8d2a
farhaanbukhsh fd8d2a
        # One comment added
farhaanbukhsh fd8d2a
        request = pagure.lib.search_pull_requests(
farhaanbukhsh fd8d2a
            self.session, project_id=1, requestid=1)
farhaanbukhsh fd8d2a
        self.assertEqual(len(request.comments), 1)
farhaanbukhsh fd8d2a
farhaanbukhsh a0d3dc
    @patch('pagure.lib.notify.send_email')
farhaanbukhsh a0d3dc
    def test_api_private_repo_pr_add_flag(self, mockemail):
farhaanbukhsh a0d3dc
        """ Test the api_pull_request_add_flag method of the flask api. """
farhaanbukhsh a0d3dc
        mockemail.return_value = True
farhaanbukhsh a0d3dc
        pagure.APP.config['REQUESTS_FOLDER'] = None
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # Add private repo
farhaanbukhsh a0d3dc
        item = pagure.lib.model.Project(
farhaanbukhsh a0d3dc
            user_id=1,  # pingou
farhaanbukhsh a0d3dc
            name='test4',
farhaanbukhsh a0d3dc
            description='test project description',
farhaanbukhsh a0d3dc
            hook_token='aaabbbeeeceee',
farhaanbukhsh a0d3dc
            private=True,
farhaanbukhsh a0d3dc
        )
farhaanbukhsh a0d3dc
        self.session.add(item)
farhaanbukhsh a0d3dc
        self.session.commit()
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # Add private repo
farhaanbukhsh a0d3dc
        item = pagure.lib.model.Project(
farhaanbukhsh a0d3dc
            user_id=1,  # pingou
farhaanbukhsh a0d3dc
            name='test2',
farhaanbukhsh a0d3dc
            description='test project description',
farhaanbukhsh a0d3dc
            hook_token='foo_bar',
farhaanbukhsh a0d3dc
            private=True,
farhaanbukhsh a0d3dc
        )
farhaanbukhsh a0d3dc
        self.session.add(item)
farhaanbukhsh a0d3dc
        self.session.commit()
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        tests.create_tokens(self.session)
farhaanbukhsh a0d3dc
        tests.create_tokens_acl(self.session)
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # Invalid project
farhaanbukhsh a0d3dc
        output = self.app.post(
farhaanbukhsh a0d3dc
            '/api/0/foo/pull-request/1/flag', headers=headers)
farhaanbukhsh a0d3dc
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh a0d3dc
        self.assertDictEqual(
farhaanbukhsh a0d3dc
            data,
farhaanbukhsh a0d3dc
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh a0d3dc
            }
farhaanbukhsh a0d3dc
        )
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # Valid token, wrong project
farhaanbukhsh a0d3dc
        output = self.app.post(
farhaanbukhsh a0d3dc
            '/api/0/test2/pull-request/1/flag', headers=headers)
farhaanbukhsh a0d3dc
        self.assertEqual(output.status_code, 401)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh a0d3dc
        self.assertDictEqual(
farhaanbukhsh a0d3dc
            data,
farhaanbukhsh a0d3dc
            {
farhaanbukhsh e3c47c
                "error": "Invalid or expired token. Please visit "
Farhaan Bukhsh 8aa0f5
                         "https://pagure.org/ to get or renew your API token.",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDTOK",
farhaanbukhsh a0d3dc
            }
farhaanbukhsh a0d3dc
        )
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # No input
farhaanbukhsh a0d3dc
        output = self.app.post(
farhaanbukhsh a0d3dc
            '/api/0/test4/pull-request/1/flag', headers=headers)
farhaanbukhsh a0d3dc
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh a0d3dc
        self.assertDictEqual(
farhaanbukhsh a0d3dc
            data,
farhaanbukhsh a0d3dc
            {
farhaanbukhsh e3c47c
                "error": "Pull-Request not found",
farhaanbukhsh e3c47c
                "error_code": "ENOREQ",
farhaanbukhsh a0d3dc
            }
farhaanbukhsh a0d3dc
        )
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # Create a pull-request
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
Farhaan Bukhsh 839011
        forked_repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh a0d3dc
        req = pagure.lib.new_pull_request(
farhaanbukhsh a0d3dc
            session=self.session,
farhaanbukhsh a0d3dc
            repo_from=forked_repo,
farhaanbukhsh a0d3dc
            branch_from='master',
farhaanbukhsh a0d3dc
            repo_to=repo,
farhaanbukhsh a0d3dc
            branch_to='master',
farhaanbukhsh a0d3dc
            title='test pull-request',
farhaanbukhsh a0d3dc
            user='pingou',
farhaanbukhsh a0d3dc
            requestfolder=None,
farhaanbukhsh a0d3dc
        )
farhaanbukhsh a0d3dc
        self.session.commit()
farhaanbukhsh a0d3dc
        self.assertEqual(req.id, 1)
farhaanbukhsh a0d3dc
        self.assertEqual(req.title, 'test pull-request')
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # Check comments before
farhaanbukhsh a0d3dc
        request = pagure.lib.search_pull_requests(
farhaanbukhsh a0d3dc
            self.session, project_id=1, requestid=1)
farhaanbukhsh a0d3dc
        self.assertEqual(len(request.flags), 0)
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        data = {
farhaanbukhsh a0d3dc
            'username': 'Jenkins',
farhaanbukhsh a0d3dc
            'percent': 100,
farhaanbukhsh a0d3dc
            'url': 'http://jenkins.cloud.fedoraproject.org/',
farhaanbukhsh a0d3dc
            'uid': 'jenkins_build_pagure_100+seed',
farhaanbukhsh a0d3dc
        }
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # Incomplete request
farhaanbukhsh a0d3dc
        output = self.app.post(
farhaanbukhsh a0d3dc
            '/api/0/test4/pull-request/1/flag', data=data, headers=headers)
farhaanbukhsh a0d3dc
        self.assertEqual(output.status_code, 400)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh a0d3dc
        self.assertDictEqual(
farhaanbukhsh a0d3dc
            data,
farhaanbukhsh a0d3dc
            {
farhaanbukhsh e3c47c
                "error": "Invalid or incomplete input submited",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDREQ",
Farhaan Bukhsh 8aa0f5
                "errors": {"comment": ["This field is required."]}
farhaanbukhsh a0d3dc
            }
farhaanbukhsh a0d3dc
        )
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # No change
farhaanbukhsh a0d3dc
        request = pagure.lib.search_pull_requests(
farhaanbukhsh a0d3dc
            self.session, project_id=1, requestid=1)
farhaanbukhsh a0d3dc
        self.assertEqual(len(request.flags), 0)
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        data = {
farhaanbukhsh a0d3dc
            'username': 'Jenkins',
farhaanbukhsh a0d3dc
            'percent': 0,
farhaanbukhsh a0d3dc
            'comment': 'Tests failed',
farhaanbukhsh a0d3dc
            'url': 'http://jenkins.cloud.fedoraproject.org/',
farhaanbukhsh a0d3dc
            'uid': 'jenkins_build_pagure_100+seed',
farhaanbukhsh a0d3dc
        }
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # Valid request
farhaanbukhsh a0d3dc
        output = self.app.post(
farhaanbukhsh a0d3dc
            '/api/0/test4/pull-request/1/flag', data=data, headers=headers)
farhaanbukhsh a0d3dc
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh a0d3dc
        self.assertDictEqual(
farhaanbukhsh a0d3dc
            data,
farhaanbukhsh a0d3dc
            {'message': 'Flag added'}
farhaanbukhsh a0d3dc
        )
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # One flag added
farhaanbukhsh a0d3dc
        request = pagure.lib.search_pull_requests(
farhaanbukhsh a0d3dc
            self.session, project_id=1, requestid=1)
farhaanbukhsh a0d3dc
        self.assertEqual(len(request.flags), 1)
farhaanbukhsh a0d3dc
        self.assertEqual(request.flags[0].comment, 'Tests failed')
farhaanbukhsh a0d3dc
        self.assertEqual(request.flags[0].percent, 0)
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # Update flag
farhaanbukhsh a0d3dc
        data = {
farhaanbukhsh a0d3dc
            'username': 'Jenkins',
farhaanbukhsh a0d3dc
            'percent': 100,
farhaanbukhsh a0d3dc
            'comment': 'Tests passed',
farhaanbukhsh a0d3dc
            'url': 'http://jenkins.cloud.fedoraproject.org/',
farhaanbukhsh a0d3dc
            'uid': 'jenkins_build_pagure_100+seed',
farhaanbukhsh a0d3dc
        }
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        output = self.app.post(
farhaanbukhsh a0d3dc
            '/api/0/test4/pull-request/1/flag', data=data, headers=headers)
farhaanbukhsh a0d3dc
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh a0d3dc
        self.assertDictEqual(
farhaanbukhsh a0d3dc
            data,
farhaanbukhsh a0d3dc
            {'message': 'Flag updated'}
farhaanbukhsh a0d3dc
        )
farhaanbukhsh a0d3dc
farhaanbukhsh a0d3dc
        # One flag added
farhaanbukhsh a0d3dc
        request = pagure.lib.search_pull_requests(
farhaanbukhsh a0d3dc
            self.session, project_id=1, requestid=1)
farhaanbukhsh a0d3dc
        self.assertEqual(len(request.flags), 1)
farhaanbukhsh a0d3dc
        self.assertEqual(request.flags[0].comment, 'Tests passed')
farhaanbukhsh a0d3dc
        self.assertEqual(request.flags[0].percent, 100)
farhaanbukhsh a0d3dc
farhaanbukhsh 6d10ff
    @patch('pagure.lib.notify.send_email')
farhaanbukhsh 6d10ff
    def test_api_private_repo_pr_close(self, send_email):
farhaanbukhsh 6d10ff
        """ Test the api_pull_request_close method of the flask api. """
farhaanbukhsh 6d10ff
        send_email.return_value = True
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        pagure.APP.config['REQUESTS_FOLDER'] = None
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Add private repo
farhaanbukhsh 6d10ff
        item = pagure.lib.model.Project(
farhaanbukhsh 6d10ff
            user_id=1,  # pingou
farhaanbukhsh 6d10ff
            name='test4',
farhaanbukhsh 6d10ff
            description='test project description',
farhaanbukhsh 6d10ff
            hook_token='aaabbbeeeceee',
farhaanbukhsh 6d10ff
            private=True,
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.add(item)
farhaanbukhsh 6d10ff
        self.session.commit()
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        tests.create_tokens(self.session)
farhaanbukhsh 6d10ff
        tests.create_tokens_acl(self.session)
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Add private repo
farhaanbukhsh 6d10ff
        item = pagure.lib.model.Project(
farhaanbukhsh 6d10ff
            user_id=1,  # pingou
farhaanbukhsh 6d10ff
            name='test2',
farhaanbukhsh 6d10ff
            description='test project description',
farhaanbukhsh 6d10ff
            hook_token='foo_bar',
farhaanbukhsh 6d10ff
            private=True,
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.add(item)
farhaanbukhsh 6d10ff
        self.session.commit()
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Create the pull-request to close
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
Farhaan Bukhsh 839011
        forked_repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh 6d10ff
        req = pagure.lib.new_pull_request(
farhaanbukhsh 6d10ff
            session=self.session,
farhaanbukhsh 6d10ff
            repo_from=forked_repo,
farhaanbukhsh 6d10ff
            branch_from='master',
farhaanbukhsh 6d10ff
            repo_to=repo,
farhaanbukhsh 6d10ff
            branch_to='master',
farhaanbukhsh 6d10ff
            title='test pull-request',
farhaanbukhsh 6d10ff
            user='pingou',
farhaanbukhsh 6d10ff
            requestfolder=None,
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.commit()
farhaanbukhsh 6d10ff
        self.assertEqual(req.id, 1)
farhaanbukhsh 6d10ff
        self.assertEqual(req.title, 'test pull-request')
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Invalid project
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/foo/pull-request/1/close', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh 6d10ff
            }
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Valid token, wrong project
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/test2/pull-request/1/close', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 401)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {
farhaanbukhsh e3c47c
                "error": "Invalid or expired token. Please visit "
Farhaan Bukhsh 8aa0f5
                         "https://pagure.org/ to get or renew your API token.",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDTOK",
farhaanbukhsh 6d10ff
            }
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Invalid PR
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/test4/pull-request/2/close', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Create a token for foo for this project
farhaanbukhsh 6d10ff
        item = pagure.lib.model.Token(
farhaanbukhsh 6d10ff
            id='foobar_token',
farhaanbukhsh 6d10ff
            user_id=2,
farhaanbukhsh 6d10ff
            project_id=1,
farhaanbukhsh 6d10ff
            expiration=datetime.datetime.utcnow() + datetime.timedelta(
farhaanbukhsh 6d10ff
                days=30)
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.add(item)
farhaanbukhsh 6d10ff
        self.session.commit()
Farhaan Bukhsh 5d8713
        # Allow the token to close PR
Farhaan Bukhsh 5d8713
        acls = pagure.lib.get_acls(self.session)
Farhaan Bukhsh 5d8713
        acl = None
Farhaan Bukhsh 5d8713
        for acl in acls:
Farhaan Bukhsh 5d8713
            if acl.name == 'pull_request_close':
Farhaan Bukhsh 5d8713
                break
farhaanbukhsh 6d10ff
        item = pagure.lib.model.TokenAcl(
farhaanbukhsh 6d10ff
            token_id='foobar_token',
Farhaan Bukhsh 5d8713
            acl_id=acl.id,
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.add(item)
farhaanbukhsh 6d10ff
        self.session.commit()
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        headers = {'Authorization': 'token foobar_token'}
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # User not admin
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/test4/pull-request/1/close', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh 6d10ff
            }
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Close PR
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/test4/pull-request/1/close', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {"message": "Pull-request closed!"}
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
    @patch('pagure.lib.notify.send_email')
farhaanbukhsh 6d10ff
    @patch('pagure.lib.git.merge_pull_request')
farhaanbukhsh 48869c
    def test_api_private_repo_pr_merge(self, mpr, send_email):
farhaanbukhsh 6d10ff
        """ Test the api_pull_request_merge method of the flask api. """
farhaanbukhsh 6d10ff
        mpr.return_value = 'Changes merged!'
farhaanbukhsh 6d10ff
        send_email.return_value = True
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        pagure.APP.config['REQUESTS_FOLDER'] = None
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Add private repo
farhaanbukhsh 6d10ff
        item = pagure.lib.model.Project(
farhaanbukhsh 6d10ff
            user_id=1,  # pingou
farhaanbukhsh 6d10ff
            name='test4',
farhaanbukhsh 6d10ff
            description='test project description',
farhaanbukhsh 6d10ff
            hook_token='aaabbbeeeceee',
farhaanbukhsh 6d10ff
            private=True,
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.add(item)
farhaanbukhsh 6d10ff
        self.session.commit()
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        tests.create_tokens(self.session)
farhaanbukhsh 6d10ff
        tests.create_tokens_acl(self.session)
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Add private repo
farhaanbukhsh 6d10ff
        item = pagure.lib.model.Project(
farhaanbukhsh 6d10ff
            user_id=1,  # pingou
farhaanbukhsh 6d10ff
            name='test2',
farhaanbukhsh 6d10ff
            description='test project description',
farhaanbukhsh 6d10ff
            hook_token='foo_bar',
farhaanbukhsh 6d10ff
            private=True,
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.add(item)
farhaanbukhsh 6d10ff
        self.session.commit()
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Create the pull-request to close
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
Farhaan Bukhsh 839011
        forked_repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh 6d10ff
        req = pagure.lib.new_pull_request(
farhaanbukhsh 6d10ff
            session=self.session,
farhaanbukhsh 6d10ff
            repo_from=forked_repo,
farhaanbukhsh 6d10ff
            branch_from='master',
farhaanbukhsh 6d10ff
            repo_to=repo,
farhaanbukhsh 6d10ff
            branch_to='master',
farhaanbukhsh 6d10ff
            title='test pull-request',
farhaanbukhsh 6d10ff
            user='pingou',
farhaanbukhsh 6d10ff
            requestfolder=None,
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.commit()
farhaanbukhsh 6d10ff
        self.assertEqual(req.id, 1)
farhaanbukhsh 6d10ff
        self.assertEqual(req.title, 'test pull-request')
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Invalid project
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/foo/pull-request/1/merge', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh 6d10ff
            }
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Valid token, wrong project
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/test2/pull-request/1/merge', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 401)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {
farhaanbukhsh e3c47c
                "error": "Invalid or expired token. Please visit "
Farhaan Bukhsh 8aa0f5
                         "https://pagure.org/ to get or renew your API token.",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDTOK",
farhaanbukhsh 6d10ff
            }
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Invalid PR
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/test4/pull-request/2/merge', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Create a token for foo for this project
farhaanbukhsh 6d10ff
        item = pagure.lib.model.Token(
farhaanbukhsh 6d10ff
            id='foobar_token',
farhaanbukhsh 6d10ff
            user_id=2,
farhaanbukhsh 6d10ff
            project_id=1,
farhaanbukhsh 6d10ff
            expiration=datetime.datetime.utcnow() + datetime.timedelta(
farhaanbukhsh 6d10ff
                days=30)
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.add(item)
farhaanbukhsh 6d10ff
        self.session.commit()
Farhaan Bukhsh 5d8713
Farhaan Bukhsh 5d8713
        # Allow the token to merge PR
Farhaan Bukhsh 5d8713
        acls = pagure.lib.get_acls(self.session)
Farhaan Bukhsh 5d8713
        acl = None
Farhaan Bukhsh 5d8713
        for acl in acls:
Farhaan Bukhsh 5d8713
            if acl.name == 'pull_request_merge':
Farhaan Bukhsh 5d8713
                break
farhaanbukhsh 6d10ff
        item = pagure.lib.model.TokenAcl(
farhaanbukhsh 6d10ff
            token_id='foobar_token',
Farhaan Bukhsh 5d8713
            acl_id=acl.id,
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
        self.session.add(item)
farhaanbukhsh 6d10ff
        self.session.commit()
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        headers = {'Authorization': 'token foobar_token'}
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # User not admin
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/test4/pull-request/1/merge', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh 6d10ff
            }
farhaanbukhsh 6d10ff
        )
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh 6d10ff
farhaanbukhsh 6d10ff
        # Merge PR
farhaanbukhsh 6d10ff
        output = self.app.post(
farhaanbukhsh 6d10ff
            '/api/0/test4/pull-request/1/merge', headers=headers)
farhaanbukhsh 6d10ff
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 6d10ff
        self.assertDictEqual(
farhaanbukhsh 6d10ff
            data,
farhaanbukhsh 6d10ff
            {"message": "Changes merged!"}
farhaanbukhsh 6d10ff
        )
farhaanbukhsh fd8d2a
farhaanbukhsh 48869c
    def test_api_private_repo_new_issue(self):
farhaanbukhsh 48869c
        """ Test the api_new_issue method of the flask api. """
farhaanbukhsh 48869c
        # Add private repo
farhaanbukhsh 48869c
        item = pagure.lib.model.Project(
farhaanbukhsh 48869c
            user_id=1,  # pingou
farhaanbukhsh 48869c
            name='test4',
farhaanbukhsh 48869c
            description='test project description',
farhaanbukhsh 48869c
            hook_token='aaabbbeeeceee',
farhaanbukhsh 48869c
            private=True,
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
        self.session.add(item)
farhaanbukhsh 48869c
        self.session.commit()
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        for repo in ['GIT_FOLDER', 'TICKETS_FOLDER']:
farhaanbukhsh 48869c
            # Add a git repo
farhaanbukhsh 48869c
            repo_path = os.path.join(
farhaanbukhsh 48869c
                pagure.APP.config.get(repo), 'test4.git')
farhaanbukhsh 48869c
            if not os.path.exists(repo_path):
farhaanbukhsh 48869c
                os.makedirs(repo_path)
farhaanbukhsh 48869c
            pygit2.init_repository(repo_path, bare=True)
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        tests.create_tokens(self.session)
farhaanbukhsh 48869c
        tests.create_tokens_acl(self.session)
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Add private repo
farhaanbukhsh 48869c
        item = pagure.lib.model.Project(
farhaanbukhsh 48869c
            user_id=1,  # pingou
farhaanbukhsh 48869c
            name='test2',
farhaanbukhsh 48869c
            description='test project description',
farhaanbukhsh 48869c
            hook_token='foo_bar',
farhaanbukhsh 48869c
            private=True,
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
        self.session.add(item)
farhaanbukhsh 48869c
        self.session.commit()
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Valid token, wrong project
farhaanbukhsh 48869c
        output = self.app.post('/api/0/test2/new_issue', headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 401)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "error": "Invalid or expired token. Please visit "
Farhaan Bukhsh 8aa0f5
                         "https://pagure.org/ to get or renew your API token.",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDTOK",
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # No input
farhaanbukhsh 48869c
        output = self.app.post('/api/0/test4/new_issue', headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 400)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "error": "Invalid or incomplete input submited",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDREQ",
Farhaan Bukhsh 8aa0f5
                "errors": {
Farhaan Bukhsh 8aa0f5
                    "issue_content": ["This field is required."],
Farhaan Bukhsh 8aa0f5
                    "title": ["This field is required."]
Farhaan Bukhsh 8aa0f5
                }
Farhaan Bukhsh 8aa0f5
            })
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        data = {
farhaanbukhsh 48869c
            'title': 'test issue',
farhaanbukhsh 48869c
        }
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Invalid repo
farhaanbukhsh 48869c
        output = self.app.post(
farhaanbukhsh 48869c
            '/api/0/foo/new_issue', data=data, headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Incomplete request
farhaanbukhsh 48869c
        output = self.app.post(
farhaanbukhsh 48869c
            '/api/0/test4/new_issue', data=data, headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 400)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "error": "Invalid or incomplete input submited",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDREQ",
Farhaan Bukhsh 8aa0f5
                "errors": {
Farhaan Bukhsh 8aa0f5
                    "issue_content": ["This field is required."],
Farhaan Bukhsh 8aa0f5
                    "title": ["This field is required."]
Farhaan Bukhsh 8aa0f5
                }
Farhaan Bukhsh 8aa0f5
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        data = {
farhaanbukhsh 48869c
            'title': 'test issue',
farhaanbukhsh 48869c
            'issue_content': 'This issue needs attention',
farhaanbukhsh 48869c
        }
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Valid request
farhaanbukhsh 48869c
        output = self.app.post(
farhaanbukhsh 48869c
            '/api/0/test4/new_issue', data=data, headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
Farhaan Bukhsh 8aa0f5
        data['issue']['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
        data['issue']['last_updated'] = '1431414800'
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
Farhaan Bukhsh 8aa0f5
            {
Farhaan Bukhsh 8aa0f5
                'issue': FULL_ISSUE_LIST[7],
Farhaan Bukhsh 8aa0f5
                'message': 'Issue created'
Farhaan Bukhsh 8aa0f5
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
    def test_api_priavte_repo_view_issues(self):
farhaanbukhsh 48869c
        """ Test the api_view_issues method of the flask api. """
farhaanbukhsh 48869c
        self.test_api_private_repo_new_issue()
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Invalid repo
farhaanbukhsh 48869c
        output = self.app.get('/api/0/foo/issues')
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # List all opened issues
farhaanbukhsh 48869c
        user = tests.FakeUser(username='pingou')
farhaanbukhsh 48869c
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 48869c
            output = self.app.get('/api/0/test4/issues')
farhaanbukhsh 48869c
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
            data['issues'][0]['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
            data['issues'][0]['last_updated'] = '1431414800'
farhaanbukhsh 48869c
            self.assertDictEqual(
farhaanbukhsh 48869c
                data,
farhaanbukhsh 48869c
                {
farhaanbukhsh e3c47c
                    "args": {
farhaanbukhsh e3c47c
                        "assignee": None,
farhaanbukhsh e3c47c
                        "author": None,
Farhaan Bukhsh 8aa0f5
                        "since": None,
farhaanbukhsh e3c47c
                        "status": None,
farhaanbukhsh e3c47c
                        "tags": []
farhaanbukhsh e3c47c
                    },
farhaanbukhsh e3c47c
                    "total_issues": 1,
farhaanbukhsh e3c47c
                    "issues": [
farhaanbukhsh e3c47c
                        {
farhaanbukhsh e3c47c
                            "assignee": None,
farhaanbukhsh e3c47c
                            "blocks": [],
Farhaan Bukhsh 8c7649
                            "close_status": None,
farhaanbukhsh 87bf09
                            "closed_at": None,
farhaanbukhsh e3c47c
                            "comments": [],
farhaanbukhsh e3c47c
                            "content": "This issue needs attention",
Farhaan Bukhsh 8c7649
                            "custom_fields": [],
farhaanbukhsh e3c47c
                            "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
                            "last_updated": "1431414800",
farhaanbukhsh e3c47c
                            "depends": [],
farhaanbukhsh e3c47c
                            "id": 1,
Farhaan Bukhsh 8c7649
                            "milestone": None,
farhaanbukhsh e3c47c
                            "priority": None,
farhaanbukhsh e3c47c
                            "private": False,
farhaanbukhsh e3c47c
                            "status": "Open",
farhaanbukhsh e3c47c
                            "tags": [],
farhaanbukhsh e3c47c
                            "title": "test issue",
farhaanbukhsh e3c47c
                            "user": {
farhaanbukhsh e3c47c
                                "fullname": "PY C",
farhaanbukhsh e3c47c
                                "name": "pingou"
Farhaan Bukhsh 8c7649
farhaanbukhsh e3c47c
                            }
farhaanbukhsh e3c47c
                        }
farhaanbukhsh e3c47c
                    ]
farhaanbukhsh 48869c
                }
farhaanbukhsh 48869c
            )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Create private issue
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh 48869c
        msg = pagure.lib.new_issue(
farhaanbukhsh 48869c
            session=self.session,
farhaanbukhsh 48869c
            repo=repo,
farhaanbukhsh 48869c
            title='Test issue',
farhaanbukhsh 48869c
            content='We should work on this',
farhaanbukhsh 48869c
            user='pingou',
farhaanbukhsh 48869c
            ticketfolder=None,
farhaanbukhsh 48869c
            private=True,
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
        self.session.commit()
farhaanbukhsh 48869c
        self.assertEqual(msg.title, 'Test issue')
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Private issues are retrieved
farhaanbukhsh 48869c
        user = tests.FakeUser(username='pingou')
farhaanbukhsh 48869c
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 48869c
            output = self.app.get('/api/0/test4/issues')
farhaanbukhsh 48869c
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
            data['issues'][0]['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
            data['issues'][0]['last_updated'] = '1431414800'
farhaanbukhsh 48869c
            data['issues'][1]['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
            data['issues'][1]['last_updated'] = '1431414800'
farhaanbukhsh 48869c
            self.assertDictEqual(
farhaanbukhsh 48869c
                data,
Farhaan Bukhsh 8c7649
                {
Farhaan Bukhsh 8c7649
                    "args": {
Farhaan Bukhsh 8c7649
                        "assignee": None,
Farhaan Bukhsh 8c7649
                        "author": None,
Farhaan Bukhsh 8c7649
                        "status": None,
Farhaan Bukhsh 8aa0f5
                        "since": None,
Farhaan Bukhsh 8c7649
                        "tags": []
Farhaan Bukhsh 8c7649
                    },
Farhaan Bukhsh 8c7649
                    "issues": [
Farhaan Bukhsh 8c7649
                        {
Farhaan Bukhsh 8c7649
                            "assignee": None,
Farhaan Bukhsh 8c7649
                            "blocks": [],
Farhaan Bukhsh 8c7649
                            "close_status": None,
Farhaan Bukhsh 8c7649
                            "closed_at": None,
Farhaan Bukhsh 8c7649
                            "comments": [],
Farhaan Bukhsh 8c7649
                            "content": "We should work on this",
Farhaan Bukhsh 8c7649
                            "custom_fields": [],
Farhaan Bukhsh 8c7649
                            "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
                            "last_updated": "1431414800",
Farhaan Bukhsh 8c7649
                            "depends": [],
Farhaan Bukhsh 8c7649
                            "id": 2,
Farhaan Bukhsh 8c7649
                            "milestone": None,
Farhaan Bukhsh 8c7649
                            "priority": None,
Farhaan Bukhsh 8c7649
                            "private": True,
Farhaan Bukhsh 8c7649
                            "status": "Open",
Farhaan Bukhsh 8c7649
                            "tags": [],
Farhaan Bukhsh 8c7649
                            "title": "Test issue",
Farhaan Bukhsh 8c7649
                            "user": {
Farhaan Bukhsh 8c7649
                                "fullname": "PY C",
Farhaan Bukhsh 8c7649
                                "name": "pingou"
Farhaan Bukhsh 8c7649
                            }
Farhaan Bukhsh 8c7649
                        },
Farhaan Bukhsh 8c7649
                        {
Farhaan Bukhsh 8c7649
                            "assignee": None,
Farhaan Bukhsh 8c7649
                            "blocks": [],
Farhaan Bukhsh 8c7649
                            "close_status": None,
Farhaan Bukhsh 8c7649
                            "closed_at": None,
Farhaan Bukhsh 8c7649
                            "comments": [],
Farhaan Bukhsh 8c7649
                            "content": "This issue needs attention",
Farhaan Bukhsh 8c7649
                            "custom_fields": [],
Farhaan Bukhsh 8c7649
                            "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
                            "last_updated": "1431414800",
Farhaan Bukhsh 8c7649
                            "depends": [],
Farhaan Bukhsh 8c7649
                            "id": 1,
Farhaan Bukhsh 8c7649
                            "milestone": None,
Farhaan Bukhsh 8c7649
                            "priority": None,
Farhaan Bukhsh 8c7649
                            "private": False,
Farhaan Bukhsh 8c7649
                            "status": "Open",
Farhaan Bukhsh 8c7649
                            "tags": [],
Farhaan Bukhsh 8c7649
                            "title": "test issue",
Farhaan Bukhsh 8c7649
                            "user": {
Farhaan Bukhsh 8c7649
                                "fullname": "PY C",
Farhaan Bukhsh 8c7649
                                "name": "pingou"
Farhaan Bukhsh 8c7649
                            }
Farhaan Bukhsh 8c7649
                        }
Farhaan Bukhsh 8c7649
                    ],
Farhaan Bukhsh 8c7649
                    "total_issues": 2
Farhaan Bukhsh 8c7649
                }
Farhaan Bukhsh 8c7649
farhaanbukhsh e3c47c
            )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Access issues authenticated but non-existing token
farhaanbukhsh 48869c
        headers = {'Authorization': 'token aaabbbccc'}
farhaanbukhsh 48869c
        output = self.app.get('/api/0/test4/issues', headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 401)
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Access issues authenticated correctly
farhaanbukhsh 48869c
        output = self.app.get('/api/0/test4/issues', headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        data['issues'][0]['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
        data['issues'][0]['last_updated'] = '1431414800'
farhaanbukhsh 48869c
        data['issues'][1]['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
        data['issues'][1]['last_updated'] = '1431414800'
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "args": {
farhaanbukhsh e3c47c
                    "assignee": None,
farhaanbukhsh e3c47c
                    "author": None,
farhaanbukhsh e3c47c
                    "status": None,
Farhaan Bukhsh 8aa0f5
                    "since": None,
farhaanbukhsh e3c47c
                    "tags": []
farhaanbukhsh 48869c
                },
farhaanbukhsh e3c47c
                "issues": [
farhaanbukhsh e3c47c
                    {
farhaanbukhsh e3c47c
                        "assignee": None,
farhaanbukhsh e3c47c
                        "blocks": [],
Farhaan Bukhsh 8c7649
                        "close_status": None,
farhaanbukhsh 87bf09
                        "closed_at": None,
farhaanbukhsh e3c47c
                        "comments": [],
Farhaan Bukhsh 8c7649
                        "content": "We should work on this",
Farhaan Bukhsh 8c7649
                        "custom_fields": [],
farhaanbukhsh e3c47c
                        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
                        "last_updated": "1431414800",
farhaanbukhsh e3c47c
                        "depends": [],
Farhaan Bukhsh 8c7649
                        "id": 2,
Farhaan Bukhsh 8c7649
                        "milestone": None,
farhaanbukhsh e3c47c
                        "priority": None,
Farhaan Bukhsh 8c7649
                        "private": True,
farhaanbukhsh e3c47c
                        "status": "Open",
farhaanbukhsh e3c47c
                        "tags": [],
Farhaan Bukhsh 8c7649
                        "title": "Test issue",
farhaanbukhsh e3c47c
                        "user": {
farhaanbukhsh e3c47c
                            "fullname": "PY C",
farhaanbukhsh e3c47c
                            "name": "pingou"
farhaanbukhsh e3c47c
                        }
farhaanbukhsh e3c47c
                    },
farhaanbukhsh e3c47c
                    {
farhaanbukhsh e3c47c
                        "assignee": None,
farhaanbukhsh e3c47c
                        "blocks": [],
Farhaan Bukhsh 8c7649
                        "close_status": None,
farhaanbukhsh 87bf09
                        "closed_at": None,
farhaanbukhsh e3c47c
                        "comments": [],
Farhaan Bukhsh 8c7649
                        "content": "This issue needs attention",
Farhaan Bukhsh 8c7649
                        "custom_fields": [],
farhaanbukhsh e3c47c
                        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
                        "last_updated": "1431414800",
farhaanbukhsh e3c47c
                        "depends": [],
Farhaan Bukhsh 8c7649
                        "id": 1,
Farhaan Bukhsh 8c7649
                        "milestone": None,
farhaanbukhsh e3c47c
                        "priority": None,
Farhaan Bukhsh 8c7649
                        "private": False,
farhaanbukhsh e3c47c
                        "status": "Open",
farhaanbukhsh e3c47c
                        "tags": [],
Farhaan Bukhsh 8c7649
                        "title": "test issue",
farhaanbukhsh e3c47c
                        "user": {
farhaanbukhsh e3c47c
                            "fullname": "PY C",
farhaanbukhsh e3c47c
                            "name": "pingou"
farhaanbukhsh e3c47c
                        }
farhaanbukhsh e3c47c
                    }
Farhaan Bukhsh 8c7649
                ],
Farhaan Bukhsh 8c7649
                "total_issues": 2
farhaanbukhsh 48869c
            }
Farhaan Bukhsh 8c7649
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # List closed issue
farhaanbukhsh e3c47c
        output = self.app.get(
farhaanbukhsh e3c47c
            '/api/0/test4/issues?status=Closed', headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "args": {
farhaanbukhsh e3c47c
                    "assignee": None,
farhaanbukhsh e3c47c
                    "author": None,
farhaanbukhsh e3c47c
                    "status": "Closed",
Farhaan Bukhsh 8aa0f5
                    "since": None,
farhaanbukhsh e3c47c
                    "tags": []
farhaanbukhsh e3c47c
                },
farhaanbukhsh e3c47c
                "total_issues": 0,
farhaanbukhsh e3c47c
                "issues": []
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # List closed issue
farhaanbukhsh e3c47c
        output = self.app.get(
farhaanbukhsh e3c47c
            '/api/0/test4/issues?status=Invalid', headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "args": {
farhaanbukhsh e3c47c
                    "assignee": None,
farhaanbukhsh e3c47c
                    "author": None,
farhaanbukhsh e3c47c
                    "status": "Invalid",
Farhaan Bukhsh 8aa0f5
                    "since": None,
farhaanbukhsh e3c47c
                    "tags": []
farhaanbukhsh e3c47c
                },
farhaanbukhsh e3c47c
                "total_issues": 0,
farhaanbukhsh e3c47c
                "issues": []
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # List all issues
farhaanbukhsh e3c47c
        output = self.app.get(
farhaanbukhsh e3c47c
            '/api/0/test4/issues?status=All', headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        data['issues'][0]['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
        data['issues'][0]['last_updated'] = '1431414800'
farhaanbukhsh 48869c
        data['issues'][1]['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
        data['issues'][1]['last_updated'] = '1431414800'
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh 48869c
                "args": {
farhaanbukhsh 48869c
                    "assignee": None,
farhaanbukhsh 48869c
                    "author": None,
Farhaan Bukhsh 8aa0f5
                    "since": None,
farhaanbukhsh 48869c
                    "status": "All",
farhaanbukhsh 48869c
                    "tags": []
farhaanbukhsh 48869c
                },
farhaanbukhsh 48869c
                "issues": [
farhaanbukhsh 48869c
                    {
farhaanbukhsh 48869c
                        "assignee": None,
farhaanbukhsh 48869c
                        "blocks": [],
Farhaan Bukhsh 8c7649
                        "close_status": None,
farhaanbukhsh 87bf09
                        "closed_at": None,
farhaanbukhsh 48869c
                        "comments": [],
Farhaan Bukhsh 8c7649
                        "content": "We should work on this",
Farhaan Bukhsh 8c7649
                        "custom_fields": [],
farhaanbukhsh 48869c
                        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
                        "last_updated": "1431414800",
farhaanbukhsh 48869c
                        "depends": [],
Farhaan Bukhsh 8c7649
                        "id": 2,
Farhaan Bukhsh 8c7649
                        "milestone": None,
farhaanbukhsh 48869c
                        "priority": None,
Farhaan Bukhsh 8c7649
                        "private": True,
farhaanbukhsh 48869c
                        "status": "Open",
farhaanbukhsh 48869c
                        "tags": [],
Farhaan Bukhsh 8c7649
                        "title": "Test issue",
farhaanbukhsh 48869c
                        "user": {
farhaanbukhsh 48869c
                            "fullname": "PY C",
farhaanbukhsh 48869c
                            "name": "pingou"
farhaanbukhsh 48869c
                        }
farhaanbukhsh 48869c
                    },
farhaanbukhsh 48869c
                    {
farhaanbukhsh 48869c
                        "assignee": None,
farhaanbukhsh 48869c
                        "blocks": [],
Farhaan Bukhsh 8c7649
                        "close_status": None,
farhaanbukhsh 87bf09
                        "closed_at": None,
farhaanbukhsh 48869c
                        "comments": [],
Farhaan Bukhsh 8c7649
                        "content": "This issue needs attention",
Farhaan Bukhsh 8c7649
                        "custom_fields": [],
farhaanbukhsh 48869c
                        "date_created": "1431414800",
Farhaan Bukhsh 8aa0f5
                        "last_updated": "1431414800",
farhaanbukhsh 48869c
                        "depends": [],
Farhaan Bukhsh 8c7649
                        "id": 1,
Farhaan Bukhsh 8c7649
                        "milestone": None,
farhaanbukhsh 48869c
                        "priority": None,
Farhaan Bukhsh 8c7649
                        "private": False,
farhaanbukhsh 48869c
                        "status": "Open",
farhaanbukhsh 48869c
                        "tags": [],
Farhaan Bukhsh 8c7649
                        "title": "test issue",
farhaanbukhsh 48869c
                        "user": {
farhaanbukhsh 48869c
                            "fullname": "PY C",
farhaanbukhsh 48869c
                            "name": "pingou"
farhaanbukhsh 48869c
                        }
farhaanbukhsh 48869c
                    }
farhaanbukhsh 48869c
                ],
Farhaan Bukhsh 8c7649
                "total_issues": 2
farhaanbukhsh 48869c
            }
Farhaan Bukhsh 8c7649
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
    def test_api_pivate_repo_view_issue(self):
farhaanbukhsh 48869c
        """ Test the api_view_issue method of the flask api. """
farhaanbukhsh 48869c
        self.test_api_private_repo_new_issue()
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Invalid repo
farhaanbukhsh 48869c
        output = self.app.get('/api/0/foo/issue/1')
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Invalid issue for this repo
farhaanbukhsh 48869c
        output = self.app.get('/api/0/test4/issue/1')
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Un-authorized user
farhaanbukhsh 48869c
        user = tests.FakeUser()
farhaanbukhsh 48869c
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 48869c
            output = self.app.get('/api/0/test4/issue/1')
farhaanbukhsh 48869c
            self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
            self.assertDictEqual(
farhaanbukhsh 48869c
                data,
farhaanbukhsh 48869c
                {
farhaanbukhsh e3c47c
                    "error": "Project not found",
farhaanbukhsh e3c47c
                    "error_code": "ENOPROJECT",
farhaanbukhsh 48869c
                }
farhaanbukhsh 48869c
            )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Valid issue
farhaanbukhsh 48869c
        user = tests.FakeUser(username='pingou')
farhaanbukhsh 48869c
        with tests.user_set(pagure.APP, user):
farhaanbukhsh 48869c
            output = self.app.get('/api/0/test4/issue/1')
farhaanbukhsh 48869c
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
            data['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
            data['last_updated'] = '1431414800'
farhaanbukhsh 48869c
            self.assertDictEqual(
farhaanbukhsh 48869c
                data,
farhaanbukhsh 48869c
                {
farhaanbukhsh e3c47c
                    "assignee": None,
farhaanbukhsh e3c47c
                    "blocks": [],
Farhaan Bukhsh 8c7649
                    "close_status": None,
Farhaan Bukhsh 8c7649
                    "closed_at": None,
farhaanbukhsh e3c47c
                    "comments": [],
farhaanbukhsh e3c47c
                    "content": "This issue needs attention",
Farhaan Bukhsh 8c7649
                    "custom_fields": [],
farhaanbukhsh e3c47c
                    "date_created": "1431414800",
farhaanbukhsh e3c47c
                    "depends": [],
farhaanbukhsh e3c47c
                    "id": 1,
Farhaan Bukhsh 8aa0f5
                    "last_updated": "1431414800",
Farhaan Bukhsh 8c7649
                    "milestone": None,
farhaanbukhsh e3c47c
                    "priority": None,
farhaanbukhsh e3c47c
                    "private": False,
farhaanbukhsh e3c47c
                    "status": "Open",
farhaanbukhsh e3c47c
                    "tags": [],
farhaanbukhsh e3c47c
                    "title": "test issue",
farhaanbukhsh e3c47c
                    "user": {
farhaanbukhsh e3c47c
                        "fullname": "PY C",
farhaanbukhsh e3c47c
                        "name": "pingou"
farhaanbukhsh e3c47c
                    }
farhaanbukhsh 48869c
                }
Farhaan Bukhsh 8aa0f5
farhaanbukhsh 48869c
            )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        headers = {'Authorization': 'token aaabbbccc'}
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Access issue authenticated but non-existing token
farhaanbukhsh 48869c
        output = self.app.get('/api/0/test4/issue/1', headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 401)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "error": "Invalid or expired token. Please visit https://pagure.org/ to get or renew your API token.",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDTOK"
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh 48869c
farhaanbukhsh 48869c
        # Access issue authenticated correctly
farhaanbukhsh 48869c
        output = self.app.get('/api/0/test4/issue/1', headers=headers)
farhaanbukhsh 48869c
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh 48869c
        data['date_created'] = '1431414800'
Farhaan Bukhsh 8aa0f5
        data['last_updated'] = '1431414800'
farhaanbukhsh 48869c
        self.assertDictEqual(
farhaanbukhsh 48869c
            data,
farhaanbukhsh 48869c
            {
farhaanbukhsh e3c47c
                "assignee": None,
farhaanbukhsh e3c47c
                "blocks": [],
Farhaan Bukhsh 8c7649
                "close_status": None,
Farhaan Bukhsh 8c7649
                "closed_at": None,
farhaanbukhsh e3c47c
                "comments": [],
farhaanbukhsh e3c47c
                "content": "This issue needs attention",
Farhaan Bukhsh 8c7649
                "custom_fields": [],
farhaanbukhsh e3c47c
                "date_created": "1431414800",
farhaanbukhsh e3c47c
                "depends": [],
farhaanbukhsh e3c47c
                "id": 1,
Farhaan Bukhsh 8aa0f5
                "last_updated": "1431414800",
Farhaan Bukhsh 8c7649
                "milestone": None,
farhaanbukhsh e3c47c
                "priority": None,
farhaanbukhsh e3c47c
                "private": False,
farhaanbukhsh e3c47c
                "status": "Open",
farhaanbukhsh e3c47c
                "tags": [],
farhaanbukhsh e3c47c
                "title": "test issue",
farhaanbukhsh e3c47c
                "user": {
farhaanbukhsh e3c47c
                    "fullname": "PY C",
farhaanbukhsh e3c47c
                    "name": "pingou"
farhaanbukhsh e3c47c
                }
Farhaan Bukhsh 8aa0f5
farhaanbukhsh 48869c
            }
farhaanbukhsh 48869c
        )
farhaanbukhsh fd8d2a
farhaanbukhsh f15bdf
    def test_api_private_repo_change_status_issue(self):
farhaanbukhsh bf482e
        """ Test the api_change_status_issue method of the flask api. """
farhaanbukhsh bf482e
        item = pagure.lib.model.Project(
farhaanbukhsh bf482e
            user_id=1,  # pingou
farhaanbukhsh bf482e
            name='test4',
farhaanbukhsh bf482e
            description='test project description',
farhaanbukhsh bf482e
            hook_token='aaabbbeeeceee',
farhaanbukhsh bf482e
            private=True,
farhaanbukhsh bf482e
        )
Farhaan Bukhsh 77ab9e
        item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
farhaanbukhsh bf482e
        self.session.add(item)
farhaanbukhsh bf482e
        self.session.commit()
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        for repo in ['GIT_FOLDER', 'TICKETS_FOLDER']:
farhaanbukhsh bf482e
            # Add a git repo
farhaanbukhsh bf482e
            repo_path = os.path.join(
farhaanbukhsh bf482e
                pagure.APP.config.get(repo), 'test4.git')
farhaanbukhsh bf482e
            if not os.path.exists(repo_path):
farhaanbukhsh bf482e
                os.makedirs(repo_path)
farhaanbukhsh bf482e
            pygit2.init_repository(repo_path, bare=True)
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        tests.create_tokens(self.session)
farhaanbukhsh bf482e
        tests.create_tokens_acl(self.session)
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        # Invalid project
farhaanbukhsh bf482e
        output = self.app.post('/api/0/foo/issue/1/status', headers=headers)
farhaanbukhsh bf482e
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh bf482e
        self.assertDictEqual(
farhaanbukhsh bf482e
            data,
farhaanbukhsh bf482e
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh bf482e
            }
farhaanbukhsh bf482e
        )
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        # Valid token, wrong project
farhaanbukhsh bf482e
        user = tests.FakeUser(username='pingou')
farhaanbukhsh bf482e
        with tests.user_set(pagure.APP, user):
farhaanbukhsh e3c47c
            output = self.app.post(
farhaanbukhsh e3c47c
                '/api/0/test2/issue/1/status', headers=headers)
farhaanbukhsh bf482e
            self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh bf482e
            self.assertDictEqual(
farhaanbukhsh bf482e
                data,
farhaanbukhsh bf482e
                {
farhaanbukhsh e3c47c
                    "error": "Project not found",
farhaanbukhsh e3c47c
                    "error_code": "ENOPROJECT",
farhaanbukhsh bf482e
                }
farhaanbukhsh bf482e
            )
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        # No input
farhaanbukhsh bf482e
        output = self.app.post('/api/0/test4/issue/1/status', headers=headers)
farhaanbukhsh bf482e
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh bf482e
        self.assertDictEqual(
farhaanbukhsh bf482e
            data,
farhaanbukhsh bf482e
            {
farhaanbukhsh e3c47c
                "error": "Issue not found",
farhaanbukhsh e3c47c
                "error_code": "ENOISSUE",
farhaanbukhsh bf482e
            }
farhaanbukhsh bf482e
        )
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        # Create normal issue
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh bf482e
        msg = pagure.lib.new_issue(
farhaanbukhsh bf482e
            session=self.session,
farhaanbukhsh bf482e
            repo=repo,
farhaanbukhsh bf482e
            title='Test issue #1',
farhaanbukhsh bf482e
            content='We should work on this',
farhaanbukhsh bf482e
            user='pingou',
farhaanbukhsh bf482e
            ticketfolder=None,
farhaanbukhsh bf482e
            private=False,
farhaanbukhsh bf482e
        )
farhaanbukhsh bf482e
        self.session.commit()
farhaanbukhsh bf482e
        self.assertEqual(msg.title, 'Test issue #1')
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        # Check status before
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh bf482e
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
farhaanbukhsh bf482e
        self.assertEqual(issue.status, 'Open')
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        data = {
farhaanbukhsh bf482e
            'title': 'test issue',
farhaanbukhsh bf482e
        }
farhaanbukhsh bf482e
farhaanbukhsh bf482e
        user = tests.FakeUser(username='pingou')
farhaanbukhsh bf482e
        with tests.user_set(pagure.APP, user):
farhaanbukhsh bf482e
            # Incomplete request
farhaanbukhsh bf482e
            output = self.app.post(
farhaanbukhsh bf482e
                '/api/0/test4/issue/1/status', data=data, headers=headers)
farhaanbukhsh bf482e
            self.assertEqual(output.status_code, 400)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh bf482e
            self.assertDictEqual(
farhaanbukhsh bf482e
                data,
farhaanbukhsh bf482e
                {
farhaanbukhsh e3c47c
                    "error": "Invalid or incomplete input submited",
farhaanbukhsh e3c47c
                    "error_code": "EINVALIDREQ",
Farhaan Bukhsh 8aa0f5
                    "errors": {"status": ["Not a valid choice"]}
farhaanbukhsh bf482e
                }
farhaanbukhsh bf482e
            )
farhaanbukhsh bf482e
farhaanbukhsh bf482e
            # No change
Farhaan Bukhsh 839011
            repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh bf482e
            issue = pagure.lib.search_issues(self.session, repo, issueid=1)
farhaanbukhsh bf482e
            self.assertEqual(issue.status, 'Open')
farhaanbukhsh bf482e
farhaanbukhsh bf482e
            data = {
farhaanbukhsh bf482e
                'status': 'Open',
farhaanbukhsh bf482e
            }
farhaanbukhsh bf482e
farhaanbukhsh bf482e
            # Valid request but no change
farhaanbukhsh bf482e
            output = self.app.post(
farhaanbukhsh bf482e
                '/api/0/test4/issue/1/status', data=data, headers=headers)
farhaanbukhsh bf482e
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh bf482e
            self.assertDictEqual(
farhaanbukhsh bf482e
                data,
farhaanbukhsh bf482e
                {'message': 'No changes'}
farhaanbukhsh bf482e
            )
farhaanbukhsh bf482e
farhaanbukhsh bf482e
            # No change
Farhaan Bukhsh 839011
            repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh bf482e
            issue = pagure.lib.search_issues(self.session, repo, issueid=1)
farhaanbukhsh bf482e
            self.assertEqual(issue.status, 'Open')
farhaanbukhsh bf482e
farhaanbukhsh bf482e
            data = {
farhaanbukhsh bf482e
                'status': 'Fixed',
farhaanbukhsh bf482e
            }
farhaanbukhsh bf482e
farhaanbukhsh bf482e
            # Valid request
farhaanbukhsh bf482e
            output = self.app.post(
farhaanbukhsh bf482e
                '/api/0/test4/issue/1/status', data=data, headers=headers)
farhaanbukhsh bf482e
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh bf482e
            self.assertDictEqual(
farhaanbukhsh bf482e
                data,
farhaanbukhsh bf482e
                {'message': 'Successfully edited issue #1'}
farhaanbukhsh bf482e
            )
farhaanbukhsh bf482e
farhaanbukhsh f15bdf
    @patch('pagure.lib.git.update_git')
farhaanbukhsh f15bdf
    @patch('pagure.lib.notify.send_email')
farhaanbukhsh f15bdf
    def test_api_private_repo_comment_issue(self, p_send_email, p_ugt):
farhaanbukhsh f15bdf
        """ Test the api_comment_issue method of the flask api. """
farhaanbukhsh f15bdf
        p_send_email.return_value = True
farhaanbukhsh f15bdf
        p_ugt.return_value = True
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        item = pagure.lib.model.Project(
farhaanbukhsh f15bdf
            user_id=1,  # pingou
farhaanbukhsh f15bdf
            name='test4',
farhaanbukhsh f15bdf
            description='test project description',
farhaanbukhsh f15bdf
            hook_token='aaabbbeeeceee',
farhaanbukhsh f15bdf
            private=True,
farhaanbukhsh f15bdf
        )
farhaanbukhsh f15bdf
        self.session.add(item)
farhaanbukhsh f15bdf
        self.session.commit()
farhaanbukhsh f15bdf
        tests.create_tokens(self.session)
farhaanbukhsh f15bdf
        tests.create_tokens_acl(self.session)
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        # Invalid project
farhaanbukhsh f15bdf
        output = self.app.post('/api/0/foo/issue/1/comment', headers=headers)
farhaanbukhsh f15bdf
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh f15bdf
        self.assertDictEqual(
farhaanbukhsh f15bdf
            data,
farhaanbukhsh f15bdf
            {
farhaanbukhsh e3c47c
                "error": "Project not found",
farhaanbukhsh e3c47c
                "error_code": "ENOPROJECT",
farhaanbukhsh f15bdf
            }
farhaanbukhsh f15bdf
        )
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        # Invalid token, right project
farhaanbukhsh f15bdf
        headers = {'Authorization': 'token aaabbbccc'}
farhaanbukhsh f15bdf
        output = self.app.post('/api/0/test4/issue/1/comment', headers=headers)
farhaanbukhsh f15bdf
        self.assertEqual(output.status_code, 401)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh f15bdf
        self.assertDictEqual(
farhaanbukhsh f15bdf
            data,
farhaanbukhsh f15bdf
            {
farhaanbukhsh e3c47c
                "error": "Invalid or expired token. Please visit "
Farhaan Bukhsh 8aa0f5
                         "https://pagure.org/ to get or renew your API token.",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDTOK",
farhaanbukhsh f15bdf
            }
farhaanbukhsh f15bdf
        )
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        headers = {'Authorization': 'token aaabbbcccddd'}
farhaanbukhsh f15bdf
        # No input
farhaanbukhsh f15bdf
        output = self.app.post('/api/0/test4/issue/1/comment', headers=headers)
farhaanbukhsh f15bdf
        self.assertEqual(output.status_code, 404)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh f15bdf
        self.assertDictEqual(
farhaanbukhsh f15bdf
            data,
farhaanbukhsh f15bdf
            {
farhaanbukhsh e3c47c
                "error": "Issue not found",
farhaanbukhsh e3c47c
                "error_code": "ENOISSUE",
farhaanbukhsh f15bdf
            }
farhaanbukhsh f15bdf
        )
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        # Create normal issue
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh f15bdf
        msg = pagure.lib.new_issue(
farhaanbukhsh f15bdf
            session=self.session,
farhaanbukhsh f15bdf
            repo=repo,
farhaanbukhsh f15bdf
            title='Test issue #1',
farhaanbukhsh f15bdf
            content='We should work on this',
farhaanbukhsh f15bdf
            user='pingou',
farhaanbukhsh f15bdf
            ticketfolder=None,
farhaanbukhsh f15bdf
            private=False,
farhaanbukhsh f15bdf
            issue_uid='aaabbbccc#1',
farhaanbukhsh f15bdf
        )
farhaanbukhsh f15bdf
        self.session.commit()
farhaanbukhsh f15bdf
        self.assertEqual(msg.title, 'Test issue #1')
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        # Check comments before
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh f15bdf
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
farhaanbukhsh f15bdf
        self.assertEqual(len(issue.comments), 0)
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        data = {
farhaanbukhsh f15bdf
            'title': 'test issue',
farhaanbukhsh f15bdf
        }
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        # Incomplete request
farhaanbukhsh f15bdf
        output = self.app.post(
farhaanbukhsh f15bdf
            '/api/0/test4/issue/1/comment', data=data, headers=headers)
farhaanbukhsh f15bdf
        self.assertEqual(output.status_code, 400)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh f15bdf
        self.assertDictEqual(
farhaanbukhsh f15bdf
            data,
farhaanbukhsh f15bdf
            {
farhaanbukhsh e3c47c
                "error": "Invalid or incomplete input submited",
farhaanbukhsh e3c47c
                "error_code": "EINVALIDREQ",
Farhaan Bukhsh 8aa0f5
                "errors": {"comment": ["This field is required."]}
farhaanbukhsh f15bdf
            }
farhaanbukhsh f15bdf
        )
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        # No change
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh f15bdf
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
farhaanbukhsh f15bdf
        self.assertEqual(issue.status, 'Open')
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        data = {
farhaanbukhsh f15bdf
            'comment': 'This is a very interesting question',
farhaanbukhsh f15bdf
        }
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        # Valid request
farhaanbukhsh f15bdf
        output = self.app.post(
farhaanbukhsh f15bdf
            '/api/0/test4/issue/1/comment', data=data, headers=headers)
farhaanbukhsh f15bdf
        self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
        data = json.loads(output.get_data(as_text=True))
farhaanbukhsh f15bdf
        self.assertDictEqual(
farhaanbukhsh f15bdf
            data,
farhaanbukhsh f15bdf
            {'message': 'Comment added'}
farhaanbukhsh f15bdf
        )
farhaanbukhsh f15bdf
farhaanbukhsh f15bdf
        # One comment added
Farhaan Bukhsh 839011
        repo = pagure.lib._get_project(self.session, 'test4')
farhaanbukhsh f15bdf
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
farhaanbukhsh f15bdf
        self.assertEqual(len(issue.comments), 1)
farhaanbukhsh f15bdf
farhaanbukhsh d9fa21
    @patch('pagure.lib.git.update_git')
farhaanbukhsh d9fa21
    @patch('pagure.lib.notify.send_email')
farhaanbukhsh d9fa21
    def test_api_view_issue_comment(self, p_send_email, p_ugt):
farhaanbukhsh d9fa21
        """ Test the api_view_issue_comment endpoint. """
farhaanbukhsh d9fa21
        p_send_email.return_value = True
farhaanbukhsh d9fa21
        p_ugt.return_value = True
farhaanbukhsh d9fa21
farhaanbukhsh d9fa21
        self.test_api_private_repo_comment_issue()
farhaanbukhsh d9fa21
farhaanbukhsh d9fa21
        # View a comment that does not exist
farhaanbukhsh d9fa21
        output = self.app.get('/api/0/foo/issue/100/comment/2')
farhaanbukhsh d9fa21
        self.assertEqual(output.status_code, 404)
farhaanbukhsh d9fa21
farhaanbukhsh d9fa21
        # Issue exists but not the comment
farhaanbukhsh d9fa21
        output = self.app.get('/api/0/test/issue/1/comment/2')
farhaanbukhsh d9fa21
        self.assertEqual(output.status_code, 404)
farhaanbukhsh d9fa21
farhaanbukhsh d9fa21
        # Issue and comment exists
farhaanbukhsh d9fa21
        output = self.app.get('/api/0/test/issue/1/comment/1')
farhaanbukhsh d9fa21
        self.assertEqual(output.status_code, 404)
farhaanbukhsh d9fa21
farhaanbukhsh d9fa21
        user = tests.FakeUser(username='pingou')
farhaanbukhsh d9fa21
        with tests.user_set(pagure.APP, user):
farhaanbukhsh e3c47c
            output = self.app.get('/api/0/test4/issue/1/comment/1')
farhaanbukhsh d9fa21
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh d9fa21
            data['date_created'] = '1435821770'
farhaanbukhsh d9fa21
            data["comment_date"] = "2015-07-02 09:22"
farhaanbukhsh d9fa21
            data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
farhaanbukhsh d9fa21
            self.assertDictEqual(
farhaanbukhsh d9fa21
                data,
farhaanbukhsh d9fa21
                {
farhaanbukhsh e3c47c
                    "avatar_url": "https://seccdn.libravatar.org/avatar/...",
farhaanbukhsh e3c47c
                    "comment": "This is a very interesting question",
farhaanbukhsh e3c47c
                    "comment_date": "2015-07-02 09:22",
Farhaan Bukhsh 8aa0f5
                    "notification": False,
farhaanbukhsh e3c47c
                    "date_created": "1435821770",
farhaanbukhsh e3c47c
                    "edited_on": None,
farhaanbukhsh e3c47c
                    "editor": None,
farhaanbukhsh e3c47c
                    "id": 1,
farhaanbukhsh e3c47c
                    "parent": None,
farhaanbukhsh e3c47c
                    "user": {
farhaanbukhsh e3c47c
                        "fullname": "PY C",
farhaanbukhsh e3c47c
                        "name": "pingou"
farhaanbukhsh e3c47c
                    }
farhaanbukhsh d9fa21
                }
farhaanbukhsh d9fa21
            )
farhaanbukhsh d9fa21
farhaanbukhsh e3c47c
            # Issue and comment exists, using UID
farhaanbukhsh e3c47c
            output = self.app.get('/api/0/test4/issue/aaabbbccc#1/comment/1')
farhaanbukhsh e3c47c
            self.assertEqual(output.status_code, 200)
farhaanbukhsh c87985
            data = json.loads(output.get_data(as_text=True))
farhaanbukhsh e3c47c
            data['date_created'] = '1435821770'
farhaanbukhsh e3c47c
            data["comment_date"] = "2015-07-02 09:22"
farhaanbukhsh e3c47c
            data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
farhaanbukhsh e3c47c
            self.assertDictEqual(
farhaanbukhsh e3c47c
                data,
farhaanbukhsh e3c47c
                {
farhaanbukhsh e3c47c
                    "avatar_url": "https://seccdn.libravatar.org/avatar/...",
farhaanbukhsh e3c47c
                    "comment": "This is a very interesting question",
farhaanbukhsh e3c47c
                    "comment_date": "2015-07-02 09:22",
Farhaan Bukhsh 8aa0f5
                    "notification": False,
farhaanbukhsh e3c47c
                    "date_created": "1435821770",
farhaanbukhsh e3c47c
                    "edited_on": None,
farhaanbukhsh e3c47c
                    "editor": None,
farhaanbukhsh e3c47c
                    "id": 1,
farhaanbukhsh e3c47c
                    "parent": None,
farhaanbukhsh e3c47c
                    "user": {
farhaanbukhsh e3c47c
                        "fullname": "PY C",
farhaanbukhsh e3c47c
                        "name": "pingou"
farhaanbukhsh e3c47c
                    }
farhaanbukhsh e3c47c
                }
farhaanbukhsh e3c47c
            )
farhaanbukhsh f15bdf
farhaanbukhsh bf482e
farhaanbukhsh 1df65f
if __name__ == '__main__':
farhaanbukhsh 1df65f
    SUITE = unittest.TestLoader().loadTestsFromTestCase(PagurePrivateRepotest)
farhaanbukhsh 1df65f
    unittest.TextTestRunner(verbosity=2).run(SUITE)