Blame tests/test_pagure_flask_api_fork.py

Pierre-Yves Chibon c71c2d
# -*- coding: utf-8 -*-
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
"""
Pierre-Yves Chibon c71c2d
 (c) 2015 - Copyright Red Hat Inc
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
 Authors:
Pierre-Yves Chibon c71c2d
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
"""
Pierre-Yves Chibon c71c2d
Aurélien Bompard 626417
from __future__ import unicode_literals
Aurélien Bompard 626417
Pierre-Yves Chibon c71c2d
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon c71c2d
import pkg_resources
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
import datetime
Pierre-Yves Chibon c71c2d
import unittest
Pierre-Yves Chibon c71c2d
import shutil
Pierre-Yves Chibon c71c2d
import sys
Pierre-Yves Chibon c71c2d
import os
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
import json
Pierre-Yves Chibon 9811e6
from mock import patch, MagicMock
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon c71c2d
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon c71c2d
Farhaan Bukhsh 72e9db
import pagure
Pierre-Yves Chibon c71c2d
import pagure.lib
Pierre-Yves Chibon c71c2d
import tests
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
class PagureFlaskApiForktests(tests.Modeltests):
Pierre-Yves Chibon c71c2d
    """ Tests for the flask API of pagure for issue """
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c27d61
    maxDiff = None
Pierre-Yves Chibon c27d61
Pierre-Yves Chibon c71c2d
    def setUp(self):
Pierre-Yves Chibon c71c2d
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon c71c2d
        super(PagureFlaskApiForktests, self).setUp()
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon b130e5
        pagure.config.config['REQUESTS_FOLDER'] = None
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon 7cc2d4
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 7cc2d4
    def test_api_pull_request_views(self, send_email):
Pierre-Yves Chibon ad85b9
        """ Test the api_pull_request_views method of the flask api. """
Pierre-Yves Chibon 7cc2d4
        send_email.return_value = True
Pierre-Yves Chibon 7cc2d4
Pierre-Yves Chibon ad85b9
        tests.create_projects(self.session)
Pierre-Yves Chibon ad85b9
        tests.create_tokens(self.session)
Pierre-Yves Chibon ad85b9
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon ad85b9
Pierre-Yves Chibon ad85b9
        # Create a pull-request
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon b130e5
        forked_repo = pagure.lib.get_authorized_project(
Pierre-Yves Chibon b130e5
            self.session, 'test')
Pierre-Yves Chibon f9c5f9
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon ad85b9
            session=self.session,
Pierre-Yves Chibon ad85b9
            repo_from=forked_repo,
Pierre-Yves Chibon ad85b9
            branch_from='master',
Pierre-Yves Chibon ad85b9
            repo_to=repo,
Pierre-Yves Chibon ad85b9
            branch_to='master',
Pierre-Yves Chibon ad85b9
            title='test pull-request',
Pierre-Yves Chibon ad85b9
            user='pingou',
Pierre-Yves Chibon ad85b9
            requestfolder=None,
Pierre-Yves Chibon ad85b9
        )
Pierre-Yves Chibon ad85b9
        self.session.commit()
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon ad85b9
Pierre-Yves Chibon ad85b9
        # Invalid repo
Pierre-Yves Chibon ad85b9
        output = self.app.get('/api/0/foo/pull-requests')
Pierre-Yves Chibon ad85b9
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon ad85b9
        self.assertDictEqual(
Pierre-Yves Chibon ad85b9
            data,
Pierre-Yves Chibon ad85b9
            {
Pierre-Yves Chibon ad85b9
              "error": "Project not found",
Pierre-Yves Chibon ad85b9
              "error_code": "ENOPROJECT",
Pierre-Yves Chibon ad85b9
            }
Pierre-Yves Chibon ad85b9
        )
Pierre-Yves Chibon ad85b9
Pierre-Yves Chibon ad85b9
        # List pull-requests
Pierre-Yves Chibon ad85b9
        output = self.app.get('/api/0/test/pull-requests')
Pierre-Yves Chibon ad85b9
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon ad85b9
        data['requests'][0]['date_created'] = '1431414800'
Pierre-Yves Chibon 44258a
        data['requests'][0]['updated_on'] = '1431414800'
Pierre-Yves Chibon ad85b9
        data['requests'][0]['project']['date_created'] = '1431414800'
Clement Verna cd6e30
        data['requests'][0]['project']['date_modified'] = '1431414800'
Pierre-Yves Chibon ad85b9
        data['requests'][0]['repo_from']['date_created'] = '1431414800'
Clement Verna cd6e30
        data['requests'][0]['repo_from']['date_modified'] = '1431414800'
Pierre-Yves Chibon ad85b9
        data['requests'][0]['uid'] = '1431414800'
Mark Reynolds 23b4d2
        data['requests'][0]['last_updated'] = '1431414800'
Matt Prahl 6bf79a
        expected_data = {
Matt Prahl 6bf79a
            "args": {
Pierre-Yves Chibon 316f15
                "assignee": None,
Pierre-Yves Chibon 316f15
                "author": None,
Pierre-Yves Chibon 316f15
                "status": True
Matt Prahl 6bf79a
            },
Matt Prahl 6bf79a
            "requests": [{
Matt Prahl 6bf79a
                "assignee": None,
Matt Prahl 6bf79a
                "branch": "master",
Matt Prahl 6bf79a
                "branch_from": "master",
Pierre-Yves Chibon f21734
                "cached_merge_status": "unknown",
Matt Prahl 6bf79a
                "closed_at": None,
Matt Prahl 6bf79a
                "closed_by": None,
Matt Prahl 6bf79a
                "comments": [],
Matt Prahl 6bf79a
                "commit_start": None,
Matt Prahl 6bf79a
                "commit_stop": None,
Matt Prahl 6bf79a
                "date_created": "1431414800",
Matt Prahl 6bf79a
                "id": 1,
Matt Prahl 6bf79a
                "initial_comment": None,
Matt Prahl 6bf79a
                "last_updated": "1431414800",
Matt Prahl 6bf79a
                "project": {
Matt Prahl 6bf79a
                    "access_groups": {
Matt Prahl 6bf79a
                        "admin": [],
Matt Prahl 6bf79a
                        "commit": [],
Matt Prahl 6bf79a
                        "ticket": []
Matt Prahl 6bf79a
                    },
Matt Prahl 6bf79a
                    "access_users": {
Matt Prahl 6bf79a
                        "admin": [],
Matt Prahl 6bf79a
                        "commit": [],
Matt Prahl 6bf79a
                        "owner": ["pingou"],
Matt Prahl 6bf79a
                        "ticket": []
Matt Prahl 6bf79a
                    },
Pierre-Yves Chibon f254bf
                    "close_status": [
Matt Prahl 6bf79a
                        "Invalid",
Matt Prahl 6bf79a
                        "Insufficient data",
Matt Prahl 6bf79a
                        "Fixed",
Matt Prahl 6bf79a
                        "Duplicate"
Pierre-Yves Chibon f254bf
                    ],
Pierre-Yves Chibon 022564
                    "custom_keys": [],
Pierre-Yves Chibon ad85b9
                    "date_created": "1431414800",
Clement Verna cd6e30
                    "date_modified": "1431414800",
Pierre-Yves Chibon ad85b9
                    "description": "test project #1",
Matt Prahl 6bf79a
                    "fullname": "test",
Pierre-Yves Chibon 469e24
                    "url_path": "test",
Pierre-Yves Chibon ad85b9
                    "id": 1,
Pierre-Yves Chibon f254bf
                    "milestones": {},
Pierre-Yves Chibon ad85b9
                    "name": "test",
Pierre-Yves Chibon 733a9d
                    "namespace": None,
Pierre-Yves Chibon ad85b9
                    "parent": None,
Pierre-Yves Chibon 14bde2
                    "priorities": {},
Pierre-Yves Chibon a30916
                    "tags": [],
Pierre-Yves Chibon ad85b9
                    "user": {
Matt Prahl 6bf79a
                        "fullname": "PY C",
Matt Prahl 6bf79a
                        "name": "pingou"
Pierre-Yves Chibon ad85b9
                    }
Matt Prahl 6bf79a
                },
Matt Prahl 6bf79a
                "remote_git": None,
Matt Prahl 6bf79a
                "repo_from": {
Matt Prahl 6bf79a
                    "access_groups": {
Matt Prahl 6bf79a
                        "admin": [],
Matt Prahl 6bf79a
                        "commit": [],
Matt Prahl 6bf79a
                        "ticket": []},
Matt Prahl 6bf79a
                    "access_users": {
Matt Prahl 6bf79a
                        "admin": [],
Matt Prahl 6bf79a
                        "commit": [],
Matt Prahl 6bf79a
                        "owner": ["pingou"],
Matt Prahl 6bf79a
                        "ticket": []
Matt Prahl 6bf79a
                    },
Pierre-Yves Chibon f254bf
                    "close_status": [
Matt Prahl 6bf79a
                        "Invalid",
Matt Prahl 6bf79a
                        "Insufficient data",
Matt Prahl 6bf79a
                        "Fixed",
Matt Prahl 6bf79a
                        "Duplicate"
Pierre-Yves Chibon f254bf
                    ],
Pierre-Yves Chibon 022564
                    "custom_keys": [],
Pierre-Yves Chibon ad85b9
                    "date_created": "1431414800",
Clement Verna cd6e30
                    "date_modified": "1431414800",
Pierre-Yves Chibon ad85b9
                    "description": "test project #1",
Matt Prahl 6bf79a
                    "fullname": "test",
Pierre-Yves Chibon 469e24
                    "url_path": "test",
Pierre-Yves Chibon ad85b9
                    "id": 1,
Pierre-Yves Chibon f254bf
                    "milestones": {},
Pierre-Yves Chibon ad85b9
                    "name": "test",
Pierre-Yves Chibon 733a9d
                    "namespace": None,
Pierre-Yves Chibon ad85b9
                    "parent": None,
Pierre-Yves Chibon 14bde2
                    "priorities": {},
Pierre-Yves Chibon a30916
                    "tags": [],
Pierre-Yves Chibon ad85b9
                    "user": {
Matt Prahl 6bf79a
                        "fullname": "PY C",
Matt Prahl 6bf79a
                        "name": "pingou"
Pierre-Yves Chibon ad85b9
                    }
Matt Prahl 6bf79a
                },
Matt Prahl 6bf79a
                "status": "Open",
Matt Prahl 6bf79a
                "title": "test pull-request",
Matt Prahl 6bf79a
                "uid": "1431414800",
Matt Prahl 6bf79a
                "updated_on": "1431414800",
Matt Prahl 6bf79a
                "user": {
Pierre-Yves Chibon ad85b9
                    "fullname": "PY C",
Pierre-Yves Chibon ad85b9
                    "name": "pingou"
Pierre-Yves Chibon ad85b9
                }
Matt Prahl 6bf79a
            }],
Matt Prahl 6bf79a
            "total_requests": 1
Matt Prahl 6bf79a
        }
Matt Prahl 6bf79a
        self.assertDictEqual(data, expected_data)
Pierre-Yves Chibon ad85b9
Pierre-Yves Chibon ad85b9
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon ad85b9
Pierre-Yves Chibon ad85b9
        # Access Pull-Request authenticated
Pierre-Yves Chibon ad85b9
        output = self.app.get('/api/0/test/pull-requests', headers=headers)
Pierre-Yves Chibon ad85b9
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data2 = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon ad85b9
        data2['requests'][0]['date_created'] = '1431414800'
Pierre-Yves Chibon 44258a
        data2['requests'][0]['updated_on'] = '1431414800'
Pierre-Yves Chibon ad85b9
        data2['requests'][0]['project']['date_created'] = '1431414800'
Clement Verna cd6e30
        data2['requests'][0]['project']['date_modified'] = '1431414800'
Pierre-Yves Chibon ad85b9
        data2['requests'][0]['repo_from']['date_created'] = '1431414800'
Clement Verna cd6e30
        data2['requests'][0]['repo_from']['date_modified'] = '1431414800'
Pierre-Yves Chibon ad85b9
        data2['requests'][0]['uid'] = '1431414800'
Mark Reynolds 23b4d2
        data2['requests'][0]['last_updated'] = '1431414800'
Pierre-Yves Chibon ad85b9
        self.assertDictEqual(data, data2)
Pierre-Yves Chibon ad85b9
Pierre-Yves Chibon 7cc2d4
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 7cc2d4
    def test_api_pull_request_view(self, send_email):
Pierre-Yves Chibon c71c2d
        """ Test the api_pull_request_view method of the flask api. """
Pierre-Yves Chibon 7cc2d4
        send_email.return_value = True
Pierre-Yves Chibon c71c2d
        tests.create_projects(self.session)
Pierre-Yves Chibon c71c2d
        tests.create_tokens(self.session)
Pierre-Yves Chibon c71c2d
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
        # Create a pull-request
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon b130e5
        forked_repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon f9c5f9
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon c71c2d
            session=self.session,
Pierre-Yves Chibon c71c2d
            repo_from=forked_repo,
Pierre-Yves Chibon c71c2d
            branch_from='master',
Pierre-Yves Chibon c71c2d
            repo_to=repo,
Pierre-Yves Chibon c71c2d
            branch_to='master',
Pierre-Yves Chibon c71c2d
            title='test pull-request',
Pierre-Yves Chibon c71c2d
            user='pingou',
Pierre-Yves Chibon c71c2d
            requestfolder=None,
Pierre-Yves Chibon c71c2d
        )
Pierre-Yves Chibon c71c2d
        self.session.commit()
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
        # Invalid repo
Pierre-Yves Chibon c71c2d
        output = self.app.get('/api/0/foo/pull-request/1')
Pierre-Yves Chibon c71c2d
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon c71c2d
        self.assertDictEqual(
Pierre-Yves Chibon c71c2d
            data,
Pierre-Yves Chibon c71c2d
            {
Pierre-Yves Chibon c71c2d
              "error": "Project not found",
Pierre-Yves Chibon d661a4
              "error_code": "ENOPROJECT",
Pierre-Yves Chibon c71c2d
            }
Pierre-Yves Chibon c71c2d
        )
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
        # Invalid issue for this repo
Pierre-Yves Chibon c71c2d
        output = self.app.get('/api/0/test2/pull-request/1')
Pierre-Yves Chibon c71c2d
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon c71c2d
        self.assertDictEqual(
Pierre-Yves Chibon c71c2d
            data,
Pierre-Yves Chibon c71c2d
            {
Pierre-Yves Chibon c71c2d
              "error": "Pull-Request not found",
Pierre-Yves Chibon d661a4
              "error_code": "ENOREQ",
Pierre-Yves Chibon c71c2d
            }
Pierre-Yves Chibon c71c2d
        )
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
        # Valid issue
Pierre-Yves Chibon c71c2d
        output = self.app.get('/api/0/test/pull-request/1')
Pierre-Yves Chibon c71c2d
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon c71c2d
        data['date_created'] = '1431414800'
Pierre-Yves Chibon 44258a
        data['updated_on'] = '1431414800'
Pierre-Yves Chibon c71c2d
        data['project']['date_created'] = '1431414800'
Clement Verna cd6e30
        data['project']['date_modified'] = '1431414800'
Pierre-Yves Chibon c71c2d
        data['repo_from']['date_created'] = '1431414800'
Clement Verna cd6e30
        data['repo_from']['date_modified'] = '1431414800'
Pierre-Yves Chibon c71c2d
        data['uid'] = '1431414800'
Mark Reynolds 23b4d2
        data['last_updated'] = '1431414800'
Matt Prahl 6bf79a
        expected_data = {
Matt Prahl 6bf79a
            "assignee": None,
Matt Prahl 6bf79a
            "branch": "master",
Matt Prahl 6bf79a
            "branch_from": "master",
Pierre-Yves Chibon f21734
            "cached_merge_status": "unknown",
Matt Prahl 6bf79a
            "closed_at": None,
Matt Prahl 6bf79a
            "closed_by": None,
Matt Prahl 6bf79a
            "comments": [],
Matt Prahl 6bf79a
            "commit_start": None,
Matt Prahl 6bf79a
            "commit_stop": None,
Matt Prahl 6bf79a
            "date_created": "1431414800",
Matt Prahl 6bf79a
            "id": 1,
Matt Prahl 6bf79a
            "initial_comment": None,
Matt Prahl 6bf79a
            "last_updated": "1431414800",
Matt Prahl 6bf79a
            "project": {
Matt Prahl 6bf79a
                "access_groups": {
Matt Prahl 6bf79a
                    "admin": [],
Matt Prahl 6bf79a
                    "commit": [],
Matt Prahl 6bf79a
                    "ticket": []
Matt Prahl 6bf79a
                },
Matt Prahl 6bf79a
                "access_users": {
Matt Prahl 6bf79a
                    "admin": [],
Matt Prahl 6bf79a
                    "commit": [],
Matt Prahl 6bf79a
                    "owner": ["pingou"],
Matt Prahl 6bf79a
                    "ticket": []
Matt Prahl 6bf79a
                },
Pierre-Yves Chibon f254bf
                "close_status": [
Matt Prahl 6bf79a
                    "Invalid",
Matt Prahl 6bf79a
                    "Insufficient data",
Matt Prahl 6bf79a
                    "Fixed",
Matt Prahl 6bf79a
                    "Duplicate"
Pierre-Yves Chibon f254bf
                ],
Pierre-Yves Chibon 022564
                "custom_keys": [],
Pierre-Yves Chibon c71c2d
                "date_created": "1431414800",
Clement Verna cd6e30
                "date_modified": "1431414800",
Pierre-Yves Chibon c71c2d
                "description": "test project #1",
Pierre-Yves Chibon c9e619
                "fullname": "test",
Pierre-Yves Chibon 469e24
                "url_path": "test",
Pierre-Yves Chibon c71c2d
                "id": 1,
Pierre-Yves Chibon f254bf
                "milestones": {},
Pierre-Yves Chibon c71c2d
                "name": "test",
Pierre-Yves Chibon 733a9d
                "namespace": None,
Pierre-Yves Chibon c71c2d
                "parent": None,
Pierre-Yves Chibon 14bde2
                "priorities": {},
Pierre-Yves Chibon a30916
                "tags": [],
Pierre-Yves Chibon c71c2d
                "user": {
Matt Prahl 6bf79a
                    "fullname": "PY C",
Matt Prahl 6bf79a
                    "name": "pingou"
Pierre-Yves Chibon c71c2d
                }
Matt Prahl 6bf79a
            },
Matt Prahl 6bf79a
            "remote_git": None,
Matt Prahl 6bf79a
            "repo_from": {
Matt Prahl 6bf79a
                "access_groups": {
Matt Prahl 6bf79a
                    "admin": [],
Matt Prahl 6bf79a
                    "commit": [],
Matt Prahl 6bf79a
                    "ticket": []},
Matt Prahl 6bf79a
                "access_users": {
Matt Prahl 6bf79a
                    "admin": [],
Matt Prahl 6bf79a
                    "commit": [],
Matt Prahl 6bf79a
                    "owner": ["pingou"],
Matt Prahl 6bf79a
                    "ticket": []},
Matt Prahl 6bf79a
                "close_status": [
Matt Prahl 6bf79a
                    "Invalid",
Matt Prahl 6bf79a
                    "Insufficient data",
Matt Prahl 6bf79a
                    "Fixed",
Matt Prahl 6bf79a
                    "Duplicate"],
Matt Prahl 6bf79a
                    "custom_keys": [],
Matt Prahl 6bf79a
                    "date_created": "1431414800",
Clement Verna cd6e30
                    "date_modified": "1431414800",
Matt Prahl 6bf79a
                    "description": "test project #1",
Matt Prahl 6bf79a
                    "fullname": "test",
Pierre-Yves Chibon 469e24
                    "url_path": "test",
Matt Prahl 6bf79a
                    "id": 1,
Matt Prahl 6bf79a
                    "milestones": {},
Matt Prahl 6bf79a
                    "name": "test",
Matt Prahl 6bf79a
                    "namespace": None,
Matt Prahl 6bf79a
                    "parent": None,
Matt Prahl 6bf79a
                    "priorities": {},
Matt Prahl 6bf79a
                    "tags": [],
Matt Prahl 6bf79a
                    "user": {
Matt Prahl 6bf79a
                        "fullname": "PY C",
Matt Prahl 6bf79a
                        "name": "pingou"
Matt Prahl 6bf79a
                    }
Matt Prahl 6bf79a
            },
Matt Prahl 6bf79a
            "status": "Open",
Matt Prahl 6bf79a
            "title": "test pull-request",
Matt Prahl 6bf79a
            "uid": "1431414800",
Matt Prahl 6bf79a
            "updated_on": "1431414800",
Matt Prahl 6bf79a
            "user": {
Pierre-Yves Chibon c71c2d
                "fullname": "PY C",
Pierre-Yves Chibon c71c2d
                "name": "pingou"
Pierre-Yves Chibon c71c2d
            }
Matt Prahl 6bf79a
        }
Matt Prahl 6bf79a
        self.assertDictEqual(data, expected_data)
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
        # Access Pull-Request authenticated
Pierre-Yves Chibon c71c2d
        output = self.app.get('/api/0/test/pull-request/1', headers=headers)
Pierre-Yves Chibon c71c2d
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data2 = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon c71c2d
        data2['date_created'] = '1431414800'
Pierre-Yves Chibon c71c2d
        data2['project']['date_created'] = '1431414800'
Clement Verna cd6e30
        data2['project']['date_modified'] = '1431414800'
Pierre-Yves Chibon c71c2d
        data2['repo_from']['date_created'] = '1431414800'
Clement Verna cd6e30
        data2['repo_from']['date_modified'] = '1431414800'
Pierre-Yves Chibon c71c2d
        data2['uid'] = '1431414800'
Pierre-Yves Chibon c71c2d
        data2['date_created'] = '1431414800'
Pierre-Yves Chibon 44258a
        data2['updated_on'] = '1431414800'
Mark Reynolds 23b4d2
        data2['last_updated'] = '1431414800'
Pierre-Yves Chibon c71c2d
        self.assertDictEqual(data, data2)
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon 7cc2d4
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 7cc2d4
    def test_api_pull_request_close(self, send_email):
Pierre-Yves Chibon 209c7e
        """ Test the api_pull_request_close method of the flask api. """
Pierre-Yves Chibon 7cc2d4
        send_email.return_value = True
Pierre-Yves Chibon 7cc2d4
Pierre-Yves Chibon 209c7e
        tests.create_projects(self.session)
Pierre-Yves Chibon 209c7e
        tests.create_tokens(self.session)
Pierre-Yves Chibon 209c7e
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 209c7e
Pierre-Yves Chibon 209c7e
        # Create the pull-request to close
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon b130e5
        forked_repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon f9c5f9
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon 209c7e
            session=self.session,
Pierre-Yves Chibon 209c7e
            repo_from=forked_repo,
Pierre-Yves Chibon 209c7e
            branch_from='master',
Pierre-Yves Chibon 209c7e
            repo_to=repo,
Pierre-Yves Chibon 209c7e
            branch_to='master',
Pierre-Yves Chibon 209c7e
            title='test pull-request',
Pierre-Yves Chibon 209c7e
            user='pingou',
Pierre-Yves Chibon 209c7e
            requestfolder=None,
Pierre-Yves Chibon 209c7e
        )
Pierre-Yves Chibon 209c7e
        self.session.commit()
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon 209c7e
Pierre-Yves Chibon 209c7e
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 209c7e
Pierre-Yves Chibon 209c7e
        # Invalid project
Pierre-Yves Chibon 209c7e
        output = self.app.post(
Pierre-Yves Chibon 209c7e
            '/api/0/foo/pull-request/1/close', headers=headers)
Pierre-Yves Chibon 209c7e
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 209c7e
        self.assertDictEqual(
Pierre-Yves Chibon 209c7e
            data,
Pierre-Yves Chibon 209c7e
            {
Pierre-Yves Chibon 209c7e
              "error": "Project not found",
Pierre-Yves Chibon d661a4
              "error_code": "ENOPROJECT",
Pierre-Yves Chibon 209c7e
            }
Pierre-Yves Chibon 209c7e
        )
Pierre-Yves Chibon 209c7e
Pierre-Yves Chibon 209c7e
        # Valid token, wrong project
Pierre-Yves Chibon 209c7e
        output = self.app.post(
Pierre-Yves Chibon 209c7e
            '/api/0/test2/pull-request/1/close', headers=headers)
Pierre-Yves Chibon 209c7e
        self.assertEqual(output.status_code, 401)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Jeremy Cline 099538
        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
Jeremy Cline 099538
                         data['error_code'])
Jeremy Cline 099538
        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
Pierre-Yves Chibon 209c7e
Pierre-Yves Chibon f12b4a
        # Invalid PR
Pierre-Yves Chibon f12b4a
        output = self.app.post(
Pierre-Yves Chibon f12b4a
            '/api/0/test/pull-request/2/close', headers=headers)
Pierre-Yves Chibon f12b4a
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon f12b4a
        self.assertDictEqual(
Pierre-Yves Chibon f12b4a
            data,
Pierre-Yves Chibon d661a4
            {'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
Pierre-Yves Chibon f12b4a
        )
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon f12b4a
        # Create a token for foo for this project
Pierre-Yves Chibon f12b4a
        item = pagure.lib.model.Token(
Pierre-Yves Chibon f12b4a
            id='foobar_token',
Pierre-Yves Chibon f12b4a
            user_id=2,
Pierre-Yves Chibon f12b4a
            project_id=1,
Pierre-Yves Chibon f12b4a
            expiration=datetime.datetime.utcnow() + datetime.timedelta(
Pierre-Yves Chibon f12b4a
                days=30)
Pierre-Yves Chibon f12b4a
        )
Pierre-Yves Chibon f12b4a
        self.session.add(item)
Pierre-Yves Chibon f12b4a
        self.session.commit()
Pierre-Yves Chibon c02e60
Pierre-Yves Chibon c02e60
        # Allow the token to close PR
Pierre-Yves Chibon b11d54
        acls = pagure.lib.get_acls(self.session)
Pierre-Yves Chibon b11d54
        for acl in acls:
Pierre-Yves Chibon b11d54
            if acl.name == 'pull_request_close':
Pierre-Yves Chibon b11d54
                break
Pierre-Yves Chibon f12b4a
        item = pagure.lib.model.TokenAcl(
Pierre-Yves Chibon f12b4a
            token_id='foobar_token',
Pierre-Yves Chibon b11d54
            acl_id=acl.id,
Pierre-Yves Chibon f12b4a
        )
Pierre-Yves Chibon f12b4a
        self.session.add(item)
Pierre-Yves Chibon f12b4a
        self.session.commit()
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon f12b4a
        headers = {'Authorization': 'token foobar_token'}
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon f12b4a
        # User not admin
Pierre-Yves Chibon f12b4a
        output = self.app.post(
Pierre-Yves Chibon f12b4a
            '/api/0/test/pull-request/1/close', headers=headers)
Pierre-Yves Chibon f12b4a
        self.assertEqual(output.status_code, 403)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon f12b4a
        self.assertDictEqual(
Pierre-Yves Chibon f12b4a
            data,
Pierre-Yves Chibon f12b4a
            {
Pierre-Yves Chibon f12b4a
                'error': 'You are not allowed to merge/close pull-request '
Pierre-Yves Chibon f12b4a
                    'for this project',
Pierre-Yves Chibon d661a4
                'error_code': "ENOPRCLOSE",
Pierre-Yves Chibon f12b4a
            }
Pierre-Yves Chibon f12b4a
        )
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon f12b4a
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon 209c7e
        # Close PR
Pierre-Yves Chibon 209c7e
        output = self.app.post(
Pierre-Yves Chibon 209c7e
            '/api/0/test/pull-request/1/close', headers=headers)
Pierre-Yves Chibon 209c7e
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 209c7e
        self.assertDictEqual(
Pierre-Yves Chibon 209c7e
            data,
Pierre-Yves Chibon 316f15
            {"message": "Pull-request closed!"}
Pierre-Yves Chibon 209c7e
        )
Pierre-Yves Chibon 209c7e
Pierre-Yves Chibon 7cc2d4
    @patch('pagure.lib.notify.send_email')
Patrick Uiterwijk 02a7cc
    def test_api_pull_request_merge(self, send_email):
Pierre-Yves Chibon a9c964
        """ Test the api_pull_request_merge method of the flask api. """
Pierre-Yves Chibon 7cc2d4
        send_email.return_value = True
Pierre-Yves Chibon a9c964
Pierre-Yves Chibon a9c964
        tests.create_projects(self.session)
Patrick Uiterwijk 02a7cc
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Patrick Uiterwijk 02a7cc
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Patrick Uiterwijk 02a7cc
                                  bare=True)
Patrick Uiterwijk 02a7cc
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Patrick Uiterwijk 02a7cc
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Patrick Uiterwijk 02a7cc
                                  branch='test')
Pierre-Yves Chibon a9c964
        tests.create_tokens(self.session)
Pierre-Yves Chibon a9c964
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon a9c964
Pierre-Yves Chibon a9c964
        # Create the pull-request to close
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon b130e5
        forked_repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon f9c5f9
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon a9c964
            session=self.session,
Pierre-Yves Chibon a9c964
            repo_from=forked_repo,
Patrick Uiterwijk 02a7cc
            branch_from='test',
Pierre-Yves Chibon a9c964
            repo_to=repo,
Pierre-Yves Chibon a9c964
            branch_to='master',
Pierre-Yves Chibon a9c964
            title='test pull-request',
Pierre-Yves Chibon a9c964
            user='pingou',
Pierre-Yves Chibon a9c964
            requestfolder=None,
Pierre-Yves Chibon a9c964
        )
Pierre-Yves Chibon a9c964
        self.session.commit()
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon a9c964
Pierre-Yves Chibon a9c964
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon a9c964
Pierre-Yves Chibon a9c964
        # Invalid project
Pierre-Yves Chibon a9c964
        output = self.app.post(
Pierre-Yves Chibon a9c964
            '/api/0/foo/pull-request/1/merge', headers=headers)
Pierre-Yves Chibon a9c964
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon a9c964
        self.assertDictEqual(
Pierre-Yves Chibon a9c964
            data,
Pierre-Yves Chibon a9c964
            {
Pierre-Yves Chibon a9c964
              "error": "Project not found",
Pierre-Yves Chibon d661a4
              "error_code": "ENOPROJECT",
Pierre-Yves Chibon a9c964
            }
Pierre-Yves Chibon a9c964
        )
Pierre-Yves Chibon a9c964
Pierre-Yves Chibon a9c964
        # Valid token, wrong project
Pierre-Yves Chibon a9c964
        output = self.app.post(
Pierre-Yves Chibon a9c964
            '/api/0/test2/pull-request/1/merge', headers=headers)
Pierre-Yves Chibon a9c964
        self.assertEqual(output.status_code, 401)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Jeremy Cline 099538
        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
Jeremy Cline 099538
                         data['error_code'])
Jeremy Cline 099538
        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
Pierre-Yves Chibon a9c964
Pierre-Yves Chibon f12b4a
        # Invalid PR
Pierre-Yves Chibon f12b4a
        output = self.app.post(
Pierre-Yves Chibon f12b4a
            '/api/0/test/pull-request/2/merge', headers=headers)
Pierre-Yves Chibon f12b4a
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon f12b4a
        self.assertDictEqual(
Pierre-Yves Chibon f12b4a
            data,
Pierre-Yves Chibon d661a4
            {'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
Pierre-Yves Chibon f12b4a
        )
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon f12b4a
        # Create a token for foo for this project
Pierre-Yves Chibon f12b4a
        item = pagure.lib.model.Token(
Pierre-Yves Chibon f12b4a
            id='foobar_token',
Pierre-Yves Chibon f12b4a
            user_id=2,
Pierre-Yves Chibon f12b4a
            project_id=1,
Pierre-Yves Chibon f12b4a
            expiration=datetime.datetime.utcnow() + datetime.timedelta(
Pierre-Yves Chibon f12b4a
                days=30)
Pierre-Yves Chibon f12b4a
        )
Pierre-Yves Chibon f12b4a
        self.session.add(item)
Pierre-Yves Chibon f12b4a
        self.session.commit()
Pierre-Yves Chibon c02e60
Pierre-Yves Chibon c02e60
        # Allow the token to merge PR
Pierre-Yves Chibon b11d54
        acls = pagure.lib.get_acls(self.session)
Pierre-Yves Chibon b11d54
        for acl in acls:
Pierre-Yves Chibon b11d54
            if acl.name == 'pull_request_merge':
Pierre-Yves Chibon b11d54
                break
Pierre-Yves Chibon f12b4a
        item = pagure.lib.model.TokenAcl(
Pierre-Yves Chibon f12b4a
            token_id='foobar_token',
Pierre-Yves Chibon b11d54
            acl_id=acl.id,
Pierre-Yves Chibon f12b4a
        )
Pierre-Yves Chibon f12b4a
        self.session.add(item)
Pierre-Yves Chibon dea6ca
        self.session.commit()
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        headers = {'Authorization': 'token foobar_token'}
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        # User not admin
Pierre-Yves Chibon dea6ca
        output = self.app.post(
Pierre-Yves Chibon dea6ca
            '/api/0/test/pull-request/1/merge', headers=headers)
Pierre-Yves Chibon dea6ca
        self.assertEqual(output.status_code, 403)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon dea6ca
        self.assertDictEqual(
Pierre-Yves Chibon dea6ca
            data,
Pierre-Yves Chibon dea6ca
            {
Pierre-Yves Chibon dea6ca
                'error': 'You are not allowed to merge/close pull-request '
Pierre-Yves Chibon dea6ca
                    'for this project',
Pierre-Yves Chibon dea6ca
                'error_code': "ENOPRCLOSE",
Pierre-Yves Chibon dea6ca
            }
Pierre-Yves Chibon dea6ca
        )
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        # Merge PR
Pierre-Yves Chibon dea6ca
        output = self.app.post(
Pierre-Yves Chibon dea6ca
            '/api/0/test/pull-request/1/merge', headers=headers)
Pierre-Yves Chibon dea6ca
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon dea6ca
        self.assertDictEqual(
Pierre-Yves Chibon dea6ca
            data,
Pierre-Yves Chibon dea6ca
            {"message": "Changes merged!"}
Pierre-Yves Chibon dea6ca
        )
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
    @patch('pagure.lib.notify.send_email')
Patrick Uiterwijk 02a7cc
    def test_api_pull_request_merge_user_token(self, send_email):
Pierre-Yves Chibon dea6ca
        """ Test the api_pull_request_merge method of the flask api. """
Pierre-Yves Chibon dea6ca
        send_email.return_value = True
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        tests.create_projects(self.session)
Patrick Uiterwijk 02a7cc
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Patrick Uiterwijk 02a7cc
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Patrick Uiterwijk 02a7cc
                                  bare=True)
Patrick Uiterwijk 02a7cc
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Patrick Uiterwijk 02a7cc
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Patrick Uiterwijk 02a7cc
                                  branch='test')
Pierre-Yves Chibon dea6ca
        tests.create_tokens(self.session, project_id=None)
Pierre-Yves Chibon dea6ca
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        # Create the pull-request to close
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon b130e5
        forked_repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon dea6ca
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon dea6ca
            session=self.session,
Pierre-Yves Chibon dea6ca
            repo_from=forked_repo,
Patrick Uiterwijk 02a7cc
            branch_from='test',
Pierre-Yves Chibon dea6ca
            repo_to=repo,
Pierre-Yves Chibon dea6ca
            branch_to='master',
Pierre-Yves Chibon dea6ca
            title='test pull-request',
Pierre-Yves Chibon dea6ca
            user='pingou',
Pierre-Yves Chibon dea6ca
            requestfolder=None,
Pierre-Yves Chibon dea6ca
        )
Pierre-Yves Chibon dea6ca
        self.session.commit()
Pierre-Yves Chibon dea6ca
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon dea6ca
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        # Invalid project
Pierre-Yves Chibon dea6ca
        output = self.app.post(
Pierre-Yves Chibon dea6ca
            '/api/0/foo/pull-request/1/merge', headers=headers)
Pierre-Yves Chibon dea6ca
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon dea6ca
        self.assertDictEqual(
Pierre-Yves Chibon dea6ca
            data,
Pierre-Yves Chibon dea6ca
            {
Pierre-Yves Chibon dea6ca
              "error": "Project not found",
Pierre-Yves Chibon dea6ca
              "error_code": "ENOPROJECT",
Pierre-Yves Chibon dea6ca
            }
Pierre-Yves Chibon dea6ca
        )
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        # Valid token, invalid PR
Pierre-Yves Chibon dea6ca
        output = self.app.post(
Pierre-Yves Chibon dea6ca
            '/api/0/test2/pull-request/1/merge', headers=headers)
Pierre-Yves Chibon dea6ca
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon dea6ca
        self.assertDictEqual(
Pierre-Yves Chibon dea6ca
            data,
Pierre-Yves Chibon dea6ca
            {'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
Pierre-Yves Chibon dea6ca
        )
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        # Valid token, invalid PR - other project
Pierre-Yves Chibon dea6ca
        output = self.app.post(
Pierre-Yves Chibon dea6ca
            '/api/0/test/pull-request/2/merge', headers=headers)
Pierre-Yves Chibon dea6ca
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon dea6ca
        self.assertDictEqual(
Pierre-Yves Chibon dea6ca
            data,
Pierre-Yves Chibon dea6ca
            {'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
Pierre-Yves Chibon dea6ca
        )
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        # Create a token for foo for this project
Pierre-Yves Chibon dea6ca
        item = pagure.lib.model.Token(
Pierre-Yves Chibon dea6ca
            id='foobar_token',
Pierre-Yves Chibon dea6ca
            user_id=2,
Pierre-Yves Chibon dea6ca
            project_id=1,
Pierre-Yves Chibon dea6ca
            expiration=datetime.datetime.utcnow() + datetime.timedelta(
Pierre-Yves Chibon dea6ca
                days=30)
Pierre-Yves Chibon dea6ca
        )
Pierre-Yves Chibon dea6ca
        self.session.add(item)
Pierre-Yves Chibon dea6ca
        self.session.commit()
Pierre-Yves Chibon dea6ca
Pierre-Yves Chibon dea6ca
        # Allow the token to merge PR
Pierre-Yves Chibon dea6ca
        acls = pagure.lib.get_acls(self.session)
Pierre-Yves Chibon dea6ca
        acl = None
Pierre-Yves Chibon dea6ca
        for acl in acls:
Pierre-Yves Chibon dea6ca
            if acl.name == 'pull_request_merge':
Pierre-Yves Chibon dea6ca
                break
Pierre-Yves Chibon dea6ca
        item = pagure.lib.model.TokenAcl(
Pierre-Yves Chibon dea6ca
            token_id='foobar_token',
Pierre-Yves Chibon dea6ca
            acl_id=acl.id,
Pierre-Yves Chibon dea6ca
        )
Pierre-Yves Chibon dea6ca
        self.session.add(item)
Pierre-Yves Chibon f12b4a
        self.session.commit()
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon f12b4a
        headers = {'Authorization': 'token foobar_token'}
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon f12b4a
        # User not admin
Pierre-Yves Chibon f12b4a
        output = self.app.post(
Pierre-Yves Chibon f12b4a
            '/api/0/test/pull-request/1/merge', headers=headers)
Pierre-Yves Chibon f12b4a
        self.assertEqual(output.status_code, 403)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon f12b4a
        self.assertDictEqual(
Pierre-Yves Chibon f12b4a
            data,
Pierre-Yves Chibon f12b4a
            {
Pierre-Yves Chibon f12b4a
                'error': 'You are not allowed to merge/close pull-request '
Pierre-Yves Chibon f12b4a
                    'for this project',
Pierre-Yves Chibon d661a4
                'error_code': "ENOPRCLOSE",
Pierre-Yves Chibon f12b4a
            }
Pierre-Yves Chibon f12b4a
        )
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon f12b4a
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon f12b4a
Pierre-Yves Chibon f12b4a
        # Merge PR
Pierre-Yves Chibon a9c964
        output = self.app.post(
Pierre-Yves Chibon a9c964
            '/api/0/test/pull-request/1/merge', headers=headers)
Pierre-Yves Chibon a9c964
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon a9c964
        self.assertDictEqual(
Pierre-Yves Chibon a9c964
            data,
Pierre-Yves Chibon a9c964
            {"message": "Changes merged!"}
Pierre-Yves Chibon a9c964
        )
Pierre-Yves Chibon a9c964
Pierre-Yves Chibon 4eb5ad
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 4eb5ad
    def test_api_pull_request_add_comment(self, mockemail):
Pierre-Yves Chibon 9ba77b
        """ Test the api_pull_request_add_comment method of the flask api. """
Pierre-Yves Chibon 4eb5ad
        mockemail.return_value = True
Pierre-Yves Chibon 4eb5ad
Pierre-Yves Chibon 9ba77b
        tests.create_projects(self.session)
Pierre-Yves Chibon 9ba77b
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9ba77b
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        # Invalid project
Pierre-Yves Chibon 9ba77b
        output = self.app.post(
Pierre-Yves Chibon 9ba77b
            '/api/0/foo/pull-request/1/comment', headers=headers)
Pierre-Yves Chibon 9ba77b
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9ba77b
        self.assertDictEqual(
Pierre-Yves Chibon 9ba77b
            data,
Pierre-Yves Chibon 9ba77b
            {
Pierre-Yves Chibon 9ba77b
              "error": "Project not found",
Pierre-Yves Chibon d661a4
              "error_code": "ENOPROJECT",
Pierre-Yves Chibon 9ba77b
            }
Pierre-Yves Chibon 9ba77b
        )
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        # Valid token, wrong project
Pierre-Yves Chibon 9ba77b
        output = self.app.post(
Pierre-Yves Chibon 9ba77b
            '/api/0/test2/pull-request/1/comment', headers=headers)
Pierre-Yves Chibon 9ba77b
        self.assertEqual(output.status_code, 401)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Jeremy Cline 099538
        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
Jeremy Cline 099538
                         data['error_code'])
Jeremy Cline 099538
        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        # No input
Pierre-Yves Chibon 9ba77b
        output = self.app.post(
Pierre-Yves Chibon 9ba77b
            '/api/0/test/pull-request/1/comment', headers=headers)
Pierre-Yves Chibon 9ba77b
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9ba77b
        self.assertDictEqual(
Pierre-Yves Chibon 9ba77b
            data,
Pierre-Yves Chibon 9ba77b
            {
Pierre-Yves Chibon 9ba77b
              "error": "Pull-Request not found",
Pierre-Yves Chibon d661a4
              "error_code": "ENOREQ",
Pierre-Yves Chibon 9ba77b
            }
Pierre-Yves Chibon 9ba77b
        )
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        # Create a pull-request
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon b130e5
        forked_repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon f9c5f9
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon 9ba77b
            session=self.session,
Pierre-Yves Chibon 9ba77b
            repo_from=forked_repo,
Pierre-Yves Chibon 9ba77b
            branch_from='master',
Pierre-Yves Chibon 9ba77b
            repo_to=repo,
Pierre-Yves Chibon 9ba77b
            branch_to='master',
Pierre-Yves Chibon 9ba77b
            title='test pull-request',
Pierre-Yves Chibon 9ba77b
            user='pingou',
Pierre-Yves Chibon 9ba77b
            requestfolder=None,
Pierre-Yves Chibon 9ba77b
        )
Pierre-Yves Chibon 9ba77b
        self.session.commit()
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        # Check comments before
Aurélien Bompard 13bcde
        self.session.commit()
Pierre-Yves Chibon 9ba77b
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 9ba77b
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 9ba77b
        self.assertEqual(len(request.comments), 0)
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        data = {
Pierre-Yves Chibon 9ba77b
            'title': 'test issue',
Pierre-Yves Chibon 9ba77b
        }
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        # Incomplete request
Pierre-Yves Chibon 9ba77b
        output = self.app.post(
Pierre-Yves Chibon 9ba77b
            '/api/0/test/pull-request/1/comment', data=data, headers=headers)
Pierre-Yves Chibon 9ba77b
        self.assertEqual(output.status_code, 400)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9ba77b
        self.assertDictEqual(
Pierre-Yves Chibon 9ba77b
            data,
Pierre-Yves Chibon 9ba77b
            {
René Genz dadd94
              "error": "Invalid or incomplete input submitted",
Pierre-Yves Chibon d661a4
              "error_code": "EINVALIDREQ",
Pierre-Yves Chibon f7fcaa
              "errors": {"comment": ["This field is required."]}
Pierre-Yves Chibon 9ba77b
            }
Pierre-Yves Chibon 9ba77b
        )
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        # No change
Aurélien Bompard 13bcde
        self.session.commit()
Pierre-Yves Chibon 9ba77b
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 9ba77b
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 9ba77b
        self.assertEqual(len(request.comments), 0)
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        data = {
Pierre-Yves Chibon 9ba77b
            'comment': 'This is a very interesting question',
Pierre-Yves Chibon 9ba77b
        }
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        # Valid request
Pierre-Yves Chibon 9ba77b
        output = self.app.post(
Pierre-Yves Chibon 9ba77b
            '/api/0/test/pull-request/1/comment', data=data, headers=headers)
Pierre-Yves Chibon 9ba77b
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9ba77b
        self.assertDictEqual(
Pierre-Yves Chibon 9ba77b
            data,
Pierre-Yves Chibon 9ba77b
            {'message': 'Comment added'}
Pierre-Yves Chibon 9ba77b
        )
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon 9ba77b
        # One comment added
Aurélien Bompard 13bcde
        self.session.commit()
Pierre-Yves Chibon 9ba77b
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 9ba77b
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 9ba77b
        self.assertEqual(len(request.comments), 1)
Pierre-Yves Chibon 9ba77b
Pierre-Yves Chibon e18f81
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 1dfd94
    def test_api_pull_request_add_comment_user_token(self, mockemail):
Pierre-Yves Chibon 1dfd94
        """ Test the api_pull_request_add_comment method of the flask api. """
Pierre-Yves Chibon 1dfd94
        mockemail.return_value = True
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        tests.create_projects(self.session)
Pierre-Yves Chibon 1dfd94
        tests.create_tokens(self.session, project_id=None)
Pierre-Yves Chibon 1dfd94
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        # Invalid project
Pierre-Yves Chibon 1dfd94
        output = self.app.post(
Pierre-Yves Chibon 1dfd94
            '/api/0/foo/pull-request/1/comment', headers=headers)
Pierre-Yves Chibon 1dfd94
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 1dfd94
        self.assertDictEqual(
Pierre-Yves Chibon 1dfd94
            data,
Pierre-Yves Chibon 1dfd94
            {
Pierre-Yves Chibon 1dfd94
              "error": "Project not found",
Pierre-Yves Chibon 1dfd94
              "error_code": "ENOPROJECT",
Pierre-Yves Chibon 1dfd94
            }
Pierre-Yves Chibon 1dfd94
        )
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        # Valid token, invalid request
Pierre-Yves Chibon 1dfd94
        output = self.app.post(
Pierre-Yves Chibon 1dfd94
            '/api/0/test2/pull-request/1/comment', headers=headers)
Pierre-Yves Chibon 1dfd94
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 1dfd94
        self.assertDictEqual(
Pierre-Yves Chibon 1dfd94
            data,
Pierre-Yves Chibon 1dfd94
            {
Pierre-Yves Chibon 1dfd94
              "error": "Pull-Request not found",
Pierre-Yves Chibon 1dfd94
              "error_code": "ENOREQ",
Pierre-Yves Chibon 1dfd94
            }
Pierre-Yves Chibon 1dfd94
        )
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        # Valid token, invalid request in another project
Pierre-Yves Chibon 1dfd94
        output = self.app.post(
Pierre-Yves Chibon 1dfd94
            '/api/0/test/pull-request/1/comment', headers=headers)
Pierre-Yves Chibon 1dfd94
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 1dfd94
        self.assertDictEqual(
Pierre-Yves Chibon 1dfd94
            data,
Pierre-Yves Chibon 1dfd94
            {
Pierre-Yves Chibon 1dfd94
              "error": "Pull-Request not found",
Pierre-Yves Chibon 1dfd94
              "error_code": "ENOREQ",
Pierre-Yves Chibon 1dfd94
            }
Pierre-Yves Chibon 1dfd94
        )
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        # Create a pull-request
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon b130e5
        forked_repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 1dfd94
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon 1dfd94
            session=self.session,
Pierre-Yves Chibon 1dfd94
            repo_from=forked_repo,
Pierre-Yves Chibon 1dfd94
            branch_from='master',
Pierre-Yves Chibon 1dfd94
            repo_to=repo,
Pierre-Yves Chibon 1dfd94
            branch_to='master',
Pierre-Yves Chibon 1dfd94
            title='test pull-request',
Pierre-Yves Chibon 1dfd94
            user='pingou',
Pierre-Yves Chibon 1dfd94
            requestfolder=None,
Pierre-Yves Chibon 1dfd94
        )
Pierre-Yves Chibon 1dfd94
        self.session.commit()
Pierre-Yves Chibon 1dfd94
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon 1dfd94
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        # Check comments before
Aurélien Bompard 13bcde
        self.session.commit()
Pierre-Yves Chibon 1dfd94
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 1dfd94
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 1dfd94
        self.assertEqual(len(request.comments), 0)
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        data = {
Pierre-Yves Chibon 1dfd94
            'title': 'test issue',
Pierre-Yves Chibon 1dfd94
        }
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        # Incomplete request
Pierre-Yves Chibon 1dfd94
        output = self.app.post(
Pierre-Yves Chibon 1dfd94
            '/api/0/test/pull-request/1/comment', data=data, headers=headers)
Pierre-Yves Chibon 1dfd94
        self.assertEqual(output.status_code, 400)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 1dfd94
        self.assertDictEqual(
Pierre-Yves Chibon 1dfd94
            data,
Pierre-Yves Chibon 1dfd94
            {
René Genz dadd94
              "error": "Invalid or incomplete input submitted",
Pierre-Yves Chibon 1dfd94
              "error_code": "EINVALIDREQ",
Pierre-Yves Chibon 1dfd94
              "errors": {"comment": ["This field is required."]}
Pierre-Yves Chibon 1dfd94
            }
Pierre-Yves Chibon 1dfd94
        )
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        # No change
Aurélien Bompard 13bcde
        self.session.commit()
Pierre-Yves Chibon 1dfd94
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 1dfd94
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 1dfd94
        self.assertEqual(len(request.comments), 0)
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        data = {
Pierre-Yves Chibon 1dfd94
            'comment': 'This is a very interesting question',
Pierre-Yves Chibon 1dfd94
        }
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        # Valid request
Pierre-Yves Chibon 1dfd94
        output = self.app.post(
Pierre-Yves Chibon 1dfd94
            '/api/0/test/pull-request/1/comment', data=data, headers=headers)
Pierre-Yves Chibon 1dfd94
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 1dfd94
        self.assertDictEqual(
Pierre-Yves Chibon 1dfd94
            data,
Pierre-Yves Chibon 1dfd94
            {'message': 'Comment added'}
Pierre-Yves Chibon 1dfd94
        )
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 1dfd94
        # One comment added
Aurélien Bompard 13bcde
        self.session.commit()
Pierre-Yves Chibon 1dfd94
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 1dfd94
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 1dfd94
        self.assertEqual(len(request.comments), 1)
Pierre-Yves Chibon 1dfd94
Pierre-Yves Chibon 4f5301
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 4f5301
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 4f5301
    def test_api_subscribe_pull_request(self, p_send_email, p_ugt):
Pierre-Yves Chibon 4f5301
        """ Test the api_subscribe_pull_request method of the flask api. """
Pierre-Yves Chibon 4f5301
        p_send_email.return_value = True
Pierre-Yves Chibon 4f5301
        p_ugt.return_value = True
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        item = pagure.lib.model.User(
Pierre-Yves Chibon 4f5301
            user='bar',
Pierre-Yves Chibon 4f5301
            fullname='bar foo',
Pierre-Yves Chibon 4f5301
            password='foo',
Pierre-Yves Chibon 4f5301
            default_email='bar@bar.com',
Pierre-Yves Chibon 4f5301
        )
Pierre-Yves Chibon 4f5301
        self.session.add(item)
Pierre-Yves Chibon 4f5301
        item = pagure.lib.model.UserEmail(
Pierre-Yves Chibon 4f5301
            user_id=3,
Pierre-Yves Chibon 4f5301
            email='bar@bar.com')
Pierre-Yves Chibon 4f5301
        self.session.add(item)
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        self.session.commit()
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        tests.create_projects(self.session)
Pierre-Yves Chibon 4f5301
        tests.create_tokens(self.session, user_id=3)
Pierre-Yves Chibon 4f5301
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # Invalid project
Pierre-Yves Chibon 4f5301
        output = self.app.post(
Pierre-Yves Chibon 4f5301
            '/api/0/foo/pull-request/1/subscribe', headers=headers)
Pierre-Yves Chibon 4f5301
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 4f5301
        self.assertDictEqual(
Pierre-Yves Chibon 4f5301
            data,
Pierre-Yves Chibon 4f5301
            {
Pierre-Yves Chibon 4f5301
              "error": "Project not found",
Pierre-Yves Chibon 4f5301
              "error_code": "ENOPROJECT",
Pierre-Yves Chibon 4f5301
            }
Pierre-Yves Chibon 4f5301
        )
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # Valid token, wrong project
Pierre-Yves Chibon 4f5301
        output = self.app.post(
Pierre-Yves Chibon 4f5301
            '/api/0/test2/pull-request/1/subscribe', headers=headers)
Pierre-Yves Chibon 7186a4
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 7186a4
        self.assertEqual(pagure.api.APIERROR.ENOREQ.name,
Pierre-Yves Chibon 4f5301
                         data['error_code'])
Pierre-Yves Chibon 7186a4
        self.assertEqual(pagure.api.APIERROR.ENOREQ.value, data['error'])
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # No input
Pierre-Yves Chibon 4f5301
        output = self.app.post(
Pierre-Yves Chibon 4f5301
            '/api/0/test/pull-request/1/subscribe', headers=headers)
Pierre-Yves Chibon 4f5301
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 4f5301
        self.assertDictEqual(
Pierre-Yves Chibon 4f5301
            data,
Pierre-Yves Chibon 4f5301
            {
Aurélien Bompard 626417
                'error': 'Pull-Request not found',
Aurélien Bompard 626417
                'error_code': 'ENOREQ'
Pierre-Yves Chibon 4f5301
            }
Pierre-Yves Chibon 4f5301
        )
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # Create pull-request
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 4f5301
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon 4f5301
            session=self.session,
Pierre-Yves Chibon 4f5301
            repo_from=repo,
Pierre-Yves Chibon 4f5301
            branch_from='feature',
Pierre-Yves Chibon 4f5301
            repo_to=repo,
Pierre-Yves Chibon 4f5301
            branch_to='master',
Pierre-Yves Chibon 4f5301
            title='test pull-request',
Pierre-Yves Chibon 4f5301
            user='pingou',
Pierre-Yves Chibon 4f5301
            requestfolder=None,
Pierre-Yves Chibon 4f5301
        )
Pierre-Yves Chibon 4f5301
        self.session.commit()
Pierre-Yves Chibon 4f5301
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon 4f5301
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # Check subscribtion before
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 4f5301
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 4f5301
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 4f5301
        self.assertEqual(
Pierre-Yves Chibon 4f5301
            pagure.lib.get_watch_list(self.session, request),
Pierre-Yves Chibon 4f5301
            set(['pingou']))
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # Unsubscribe - no changes
Pierre-Yves Chibon 4f5301
        data = {}
Pierre-Yves Chibon 4f5301
        output = self.app.post(
Pierre-Yves Chibon 4f5301
            '/api/0/test/pull-request/1/subscribe',
Pierre-Yves Chibon 4f5301
            data=data, headers=headers)
Pierre-Yves Chibon 4f5301
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 4f5301
        self.assertDictEqual(
Pierre-Yves Chibon 4f5301
            data,
Pierre-Yves Chibon 4f5301
            {'message': 'You are no longer watching this pull-request'}
Pierre-Yves Chibon 4f5301
        )
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        data = {}
Pierre-Yves Chibon 4f5301
        output = self.app.post(
Pierre-Yves Chibon 4f5301
            '/api/0/test/pull-request/1/subscribe',
Pierre-Yves Chibon 4f5301
            data=data, headers=headers)
Pierre-Yves Chibon 4f5301
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 4f5301
        self.assertDictEqual(
Pierre-Yves Chibon 4f5301
            data,
Pierre-Yves Chibon 4f5301
            {'message': 'You are no longer watching this pull-request'}
Pierre-Yves Chibon 4f5301
        )
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # No change
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 4f5301
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 4f5301
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 4f5301
        self.assertEqual(
Pierre-Yves Chibon 4f5301
            pagure.lib.get_watch_list(self.session, request),
Pierre-Yves Chibon 4f5301
            set(['pingou']))
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # Subscribe
Pierre-Yves Chibon 4f5301
        data = {'status': True}
Pierre-Yves Chibon 4f5301
        output = self.app.post(
Pierre-Yves Chibon 4f5301
            '/api/0/test/pull-request/1/subscribe',
Pierre-Yves Chibon 4f5301
            data=data, headers=headers)
Pierre-Yves Chibon 4f5301
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 4f5301
        self.assertDictEqual(
Pierre-Yves Chibon 4f5301
            data,
Pierre-Yves Chibon 4f5301
            {'message': 'You are now watching this pull-request'}
Pierre-Yves Chibon 4f5301
        )
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # Subscribe - no changes
Pierre-Yves Chibon 4f5301
        data = {'status': True}
Pierre-Yves Chibon 4f5301
        output = self.app.post(
Pierre-Yves Chibon 4f5301
            '/api/0/test/pull-request/1/subscribe',
Pierre-Yves Chibon 4f5301
            data=data, headers=headers)
Pierre-Yves Chibon 4f5301
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 4f5301
        self.assertDictEqual(
Pierre-Yves Chibon 4f5301
            data,
Pierre-Yves Chibon 4f5301
            {'message': 'You are now watching this pull-request'}
Pierre-Yves Chibon 4f5301
        )
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 4f5301
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 4f5301
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 4f5301
        self.assertEqual(
Pierre-Yves Chibon 4f5301
            pagure.lib.get_watch_list(self.session, request),
Pierre-Yves Chibon 4f5301
            set(['pingou', 'bar']))
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 4f5301
        # Unsubscribe
Pierre-Yves Chibon 4f5301
        data = {}
Pierre-Yves Chibon 4f5301
        output = self.app.post(
Pierre-Yves Chibon 4f5301
            '/api/0/test/pull-request/1/subscribe',
Pierre-Yves Chibon 4f5301
            data=data, headers=headers)
Pierre-Yves Chibon 4f5301
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 4f5301
        self.assertDictEqual(
Pierre-Yves Chibon 4f5301
            data,
Pierre-Yves Chibon 4f5301
            {'message': 'You are no longer watching this pull-request'}
Pierre-Yves Chibon 4f5301
        )
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 4f5301
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 4f5301
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 4f5301
        self.assertEqual(
Pierre-Yves Chibon 4f5301
            pagure.lib.get_watch_list(self.session, request),
Pierre-Yves Chibon 4f5301
            set(['pingou']))
Pierre-Yves Chibon 4f5301
Pierre-Yves Chibon 335a73
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 335a73
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 335a73
    def test_api_subscribe_pull_request_logged_in(self, p_send_email, p_ugt):
Pierre-Yves Chibon 335a73
        """ Test the api_subscribe_pull_request method of the flask api
Pierre-Yves Chibon 335a73
        when the user is logged in via the UI. """
Pierre-Yves Chibon 335a73
        p_send_email.return_value = True
Pierre-Yves Chibon 335a73
        p_ugt.return_value = True
Pierre-Yves Chibon 335a73
Pierre-Yves Chibon 335a73
        item = pagure.lib.model.User(
Pierre-Yves Chibon 335a73
            user='bar',
Pierre-Yves Chibon 335a73
            fullname='bar foo',
Pierre-Yves Chibon 335a73
            password='foo',
Pierre-Yves Chibon 335a73
            default_email='bar@bar.com',
Pierre-Yves Chibon 335a73
        )
Pierre-Yves Chibon 335a73
        self.session.add(item)
Pierre-Yves Chibon 335a73
        item = pagure.lib.model.UserEmail(
Pierre-Yves Chibon 335a73
            user_id=3,
Pierre-Yves Chibon 335a73
            email='bar@bar.com')
Pierre-Yves Chibon 335a73
        self.session.add(item)
Pierre-Yves Chibon 335a73
Pierre-Yves Chibon 335a73
        self.session.commit()
Pierre-Yves Chibon 335a73
Pierre-Yves Chibon 335a73
        tests.create_projects(self.session)
Pierre-Yves Chibon 335a73
        tests.create_tokens(self.session, user_id=3)
Pierre-Yves Chibon 335a73
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 335a73
Pierre-Yves Chibon 335a73
        # Create pull-request
Pierre-Yves Chibon 335a73
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 335a73
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon 335a73
            session=self.session,
Pierre-Yves Chibon 335a73
            repo_from=repo,
Pierre-Yves Chibon 335a73
            branch_from='feature',
Pierre-Yves Chibon 335a73
            repo_to=repo,
Pierre-Yves Chibon 335a73
            branch_to='master',
Pierre-Yves Chibon 335a73
            title='test pull-request',
Pierre-Yves Chibon 335a73
            user='pingou',
Pierre-Yves Chibon 335a73
            requestfolder=None,
Pierre-Yves Chibon 335a73
        )
Pierre-Yves Chibon 335a73
        self.session.commit()
Pierre-Yves Chibon 335a73
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon 335a73
        self.assertEqual(req.title, 'test pull-request')
Pierre-Yves Chibon 335a73
Pierre-Yves Chibon 335a73
        # Check subscribtion before
Pierre-Yves Chibon 335a73
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 335a73
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 335a73
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 335a73
        self.assertEqual(
Pierre-Yves Chibon 335a73
            pagure.lib.get_watch_list(self.session, request),
Pierre-Yves Chibon 335a73
            set(['pingou']))
Pierre-Yves Chibon 335a73
Pierre-Yves Chibon 335a73
        # Subscribe
Pierre-Yves Chibon 335a73
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon 335a73
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 335a73
            data = {'status': True}
Pierre-Yves Chibon 335a73
            output = self.app.post(
Pierre-Yves Chibon 335a73
                '/api/0/test/pull-request/1/subscribe', data=data)
Pierre-Yves Chibon 335a73
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 335a73
            data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 335a73
            self.assertDictEqual(
Pierre-Yves Chibon 335a73
                data,
Pierre-Yves Chibon 335a73
                {'message': 'You are now watching this pull-request'}
Pierre-Yves Chibon 335a73
            )
Pierre-Yves Chibon 335a73
Pierre-Yves Chibon 335a73
        # Check subscribtions after
Pierre-Yves Chibon 335a73
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 335a73
        request = pagure.lib.search_pull_requests(
Pierre-Yves Chibon 335a73
            self.session, project_id=1, requestid=1)
Pierre-Yves Chibon 335a73
        self.assertEqual(
Pierre-Yves Chibon 335a73
            pagure.lib.get_watch_list(self.session, request),
Pierre-Yves Chibon 335a73
            set(['pingou', 'foo']))
Pierre-Yves Chibon 335a73
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open_invalid_project(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api when
Pierre-Yves Chibon 9811e6
        not the project doesn't exist.
Pierre-Yves Chibon 9811e6
        """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'initial_comment': 'Nothing much, the changes speak for themselves',
Pierre-Yves Chibon 9811e6
            'branch_to': 'master',
Pierre-Yves Chibon 9811e6
            'branch_from': 'test',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/foobar/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Aurélien Bompard 626417
            {'error': 'Project not found', 'error_code': 'ENOPROJECT'}
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open_missing_title(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api when
Pierre-Yves Chibon 9811e6
        not title is submitted.
Pierre-Yves Chibon 9811e6
        """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'initial_comment': 'Nothing much, the changes speak for themselves',
Pierre-Yves Chibon 9811e6
            'branch_to': 'master',
Pierre-Yves Chibon 9811e6
            'branch_from': 'test',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/test/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 400)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Pierre-Yves Chibon 9811e6
            {
Aurélien Bompard 626417
                'error': 'Invalid or incomplete input submitted',
Aurélien Bompard 626417
                'error_code': 'EINVALIDREQ',
Aurélien Bompard 626417
                'errors': {'title': ['This field is required.']}
Pierre-Yves Chibon 9811e6
            }
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open_missing_branch_to(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api when
Pierre-Yves Chibon 9811e6
        not branch to is submitted.
Pierre-Yves Chibon 9811e6
        """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'title': 'Test PR',
Pierre-Yves Chibon 9811e6
            'initial_comment': 'Nothing much, the changes speak for themselves',
Pierre-Yves Chibon 9811e6
            'branch_from': 'test',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/test/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 400)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Pierre-Yves Chibon 9811e6
            {
Aurélien Bompard 626417
                'error': 'Invalid or incomplete input submitted',
Aurélien Bompard 626417
                'error_code': 'EINVALIDREQ',
Aurélien Bompard 626417
                'errors': {'branch_to': ['This field is required.']}
Pierre-Yves Chibon 9811e6
            }
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open_missing_branch_from(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api when
Pierre-Yves Chibon 9811e6
        not branch from is submitted.
Pierre-Yves Chibon 9811e6
        """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'title': 'Test PR',
Pierre-Yves Chibon 9811e6
            'initial_comment': 'Nothing much, the changes speak for themselves',
Pierre-Yves Chibon 9811e6
            'branch_to': 'master',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/test/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 400)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Pierre-Yves Chibon 9811e6
            {
Aurélien Bompard 626417
                'error': 'Invalid or incomplete input submitted',
Aurélien Bompard 626417
                'error_code': 'EINVALIDREQ',
Aurélien Bompard 626417
                'errors': {'branch_from': ['This field is required.']}
Pierre-Yves Chibon 9811e6
            }
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open_pr_disabled(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api when
Pierre-Yves Chibon 9811e6
        the parent repo disabled pull-requests.
Pierre-Yves Chibon 9811e6
        """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        # Check the behavior if the project disabled the issue tracker
Pierre-Yves Chibon 9811e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 9811e6
        settings = repo.settings
Pierre-Yves Chibon 9811e6
        settings['pull_requests'] = False
Pierre-Yves Chibon 9811e6
        repo.settings = settings
Pierre-Yves Chibon 9811e6
        self.session.add(repo)
Pierre-Yves Chibon 9811e6
        self.session.commit()
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'title': 'Test PR',
Pierre-Yves Chibon 9811e6
            'initial_comment': 'Nothing much, the changes speak for themselves',
Pierre-Yves Chibon 9811e6
            'branch_to': 'master',
Pierre-Yves Chibon 9811e6
            'branch_from': 'test',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/test/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 404)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Pierre-Yves Chibon 9811e6
            {
Aurélien Bompard 626417
                'error': 'Pull-Request have been deactivated for this project',
Aurélien Bompard 626417
                'error_code': 'EPULLREQUESTSDISABLED'
Pierre-Yves Chibon 9811e6
            }
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open_signed_pr(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api when
Pierre-Yves Chibon 9811e6
        the parent repo enforces signed-off pull-requests.
Pierre-Yves Chibon 9811e6
        """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        # Check the behavior if the project disabled the issue tracker
Pierre-Yves Chibon 9811e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 9811e6
        settings = repo.settings
Pierre-Yves Chibon 9811e6
        settings['Enforce_signed-off_commits_in_pull-request'] = True
Pierre-Yves Chibon 9811e6
        repo.settings = settings
Pierre-Yves Chibon 9811e6
        self.session.add(repo)
Pierre-Yves Chibon 9811e6
        self.session.commit()
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'title': 'Test PR',
Pierre-Yves Chibon 9811e6
            'initial_comment': 'Nothing much, the changes speak for themselves',
Pierre-Yves Chibon 9811e6
            'branch_to': 'master',
Pierre-Yves Chibon 9811e6
            'branch_from': 'test',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/test/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 400)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Pierre-Yves Chibon 9811e6
            {
Aurélien Bompard 626417
                'error': 'This repo enforces that all commits are signed '
Pierre-Yves Chibon 9811e6
                   'off by their author.',
Aurélien Bompard 626417
                'error_code': 'ENOSIGNEDOFF'
Pierre-Yves Chibon 9811e6
            }
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open_invalid_branch_from(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api when
Pierre-Yves Chibon 9811e6
        the branch from does not exist.
Pierre-Yves Chibon 9811e6
        """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        # Check the behavior if the project disabled the issue tracker
Pierre-Yves Chibon 9811e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 9811e6
        settings = repo.settings
Pierre-Yves Chibon 9811e6
        settings['Enforce_signed-off_commits_in_pull-request'] = True
Pierre-Yves Chibon 9811e6
        repo.settings = settings
Pierre-Yves Chibon 9811e6
        self.session.add(repo)
Pierre-Yves Chibon 9811e6
        self.session.commit()
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'title': 'Test PR',
Pierre-Yves Chibon 9811e6
            'initial_comment': 'Nothing much, the changes speak for themselves',
Pierre-Yves Chibon 9811e6
            'branch_to': 'master',
Pierre-Yves Chibon 9811e6
            'branch_from': 'foobarbaz',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/test/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 400)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Pierre-Yves Chibon 9811e6
            {
Aurélien Bompard 626417
                'error': 'Invalid or incomplete input submitted',
Aurélien Bompard 626417
                'error_code': 'EINVALIDREQ',
Aurélien Bompard 626417
                'errors': 'Branch foobarbaz does not exist'
Pierre-Yves Chibon 9811e6
            }
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open_invalid_branch_to(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api when
Pierre-Yves Chibon 9811e6
        the branch to does not exist.
Pierre-Yves Chibon 9811e6
        """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        # Check the behavior if the project disabled the issue tracker
Pierre-Yves Chibon 9811e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 9811e6
        settings = repo.settings
Pierre-Yves Chibon 9811e6
        settings['Enforce_signed-off_commits_in_pull-request'] = True
Pierre-Yves Chibon 9811e6
        repo.settings = settings
Pierre-Yves Chibon 9811e6
        self.session.add(repo)
Pierre-Yves Chibon 9811e6
        self.session.commit()
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'title': 'Test PR',
Pierre-Yves Chibon 9811e6
            'initial_comment': 'Nothing much, the changes speak for themselves',
Pierre-Yves Chibon 9811e6
            'branch_to': 'foobarbaz',
Pierre-Yves Chibon 9811e6
            'branch_from': 'test',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/test/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 400)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Pierre-Yves Chibon 9811e6
            {
Aurélien Bompard 626417
                'error': 'Invalid or incomplete input submitted',
Aurélien Bompard 626417
                'error_code': 'EINVALIDREQ',
Aurélien Bompard 626417
                'errors': 'Branch foobarbaz could not be found in the '
Pierre-Yves Chibon 9811e6
                    'target repo'
Pierre-Yves Chibon 9811e6
            }
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api. """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'title': 'Test PR',
Pierre-Yves Chibon 9811e6
            'initial_comment': 'Nothing much, the changes speak for themselves',
Pierre-Yves Chibon 9811e6
            'branch_to': 'master',
Pierre-Yves Chibon 9811e6
            'branch_from': 'test',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/test/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Aurélien Bompard 626417
        data['project']['date_created'] = '1516348115'
Aurélien Bompard 626417
        data['project']['date_modified'] = '1516348115'
Aurélien Bompard 626417
        data['repo_from']['date_created'] = '1516348115'
Aurélien Bompard 626417
        data['repo_from']['date_modified'] = '1516348115'
Aurélien Bompard 626417
        data['uid'] = 'e8b68df8711648deac67c3afed15a798'
Aurélien Bompard 626417
        data['commit_start'] = '114f1b468a5f05e635fcb6394273f3f907386eab'
Aurélien Bompard 626417
        data['commit_stop'] = '114f1b468a5f05e635fcb6394273f3f907386eab'
Aurélien Bompard 626417
        data['date_created'] = '1516348115'
Aurélien Bompard 626417
        data['last_updated'] = '1516348115'
Aurélien Bompard 626417
        data['updated_on'] = '1516348115'
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Pierre-Yves Chibon 9811e6
            {
Aurélien Bompard 626417
                'assignee': None,
Aurélien Bompard 626417
                'branch': 'master',
Aurélien Bompard 626417
                'branch_from': 'test',
Aurélien Bompard 626417
                'cached_merge_status': 'unknown',
Aurélien Bompard 626417
                'closed_at': None,
Aurélien Bompard 626417
                'closed_by': None,
Aurélien Bompard 626417
                'comments': [],
Aurélien Bompard 626417
                'commit_start': '114f1b468a5f05e635fcb6394273f3f907386eab',
Aurélien Bompard 626417
                'commit_stop': '114f1b468a5f05e635fcb6394273f3f907386eab',
Aurélien Bompard 626417
                'date_created': '1516348115',
Aurélien Bompard 626417
                'id': 1,
Aurélien Bompard 626417
                'initial_comment': 'Nothing much, the changes speak for themselves',
Aurélien Bompard 626417
                'last_updated': '1516348115',
Aurélien Bompard 626417
                'project': {'access_groups': {'admin': [],
Aurélien Bompard 626417
                                                'commit': [],
Aurélien Bompard 626417
                                                'ticket':[]},
Aurélien Bompard 626417
                             'access_users': {'admin': [],
Aurélien Bompard 626417
                                               'commit': [],
Aurélien Bompard 626417
                                               'owner': ['pingou'],
Aurélien Bompard 626417
                                               'ticket': []},
Aurélien Bompard 626417
                             'close_status': ['Invalid',
Aurélien Bompard 626417
                                               'Insufficient data',
Aurélien Bompard 626417
                                               'Fixed',
Aurélien Bompard 626417
                                               'Duplicate'],
Aurélien Bompard 626417
                             'custom_keys': [],
Aurélien Bompard 626417
                             'date_created': '1516348115',
Aurélien Bompard 626417
                             'date_modified': '1516348115',
Aurélien Bompard 626417
                             'description': 'test project #1',
Aurélien Bompard 626417
                             'fullname': 'test',
Aurélien Bompard 626417
                             'id': 1,
Aurélien Bompard 626417
                             'milestones': {},
Aurélien Bompard 626417
                             'name': 'test',
Aurélien Bompard 626417
                             'namespace': None,
Aurélien Bompard 626417
                             'parent': None,
Aurélien Bompard 626417
                             'priorities': {},
Aurélien Bompard 626417
                             'tags': [],
Aurélien Bompard 626417
                             'url_path': 'test',
Aurélien Bompard 626417
                             'user': {'fullname': 'PY C', 'name': 'pingou'}},
Aurélien Bompard 626417
                'remote_git': None,
Aurélien Bompard 626417
                'repo_from': {'access_groups': {'admin': [],
Aurélien Bompard 626417
                                                  'commit': [],
Aurélien Bompard 626417
                                                  'ticket': []},
Aurélien Bompard 626417
                               'access_users': {'admin': [],
Aurélien Bompard 626417
                                                 'commit': [],
Aurélien Bompard 626417
                                                 'owner': ['pingou'],
Aurélien Bompard 626417
                                                 'ticket': []},
Aurélien Bompard 626417
                               'close_status': ['Invalid',
Aurélien Bompard 626417
                                                 'Insufficient data',
Aurélien Bompard 626417
                                                 'Fixed',
Aurélien Bompard 626417
                                                 'Duplicate'],
Aurélien Bompard 626417
                               'custom_keys': [],
Aurélien Bompard 626417
                               'date_created': '1516348115',
Aurélien Bompard 626417
                               'date_modified': '1516348115',
Aurélien Bompard 626417
                               'description': 'test project #1',
Aurélien Bompard 626417
                               'fullname': 'test',
Aurélien Bompard 626417
                               'id': 1,
Aurélien Bompard 626417
                               'milestones': {},
Aurélien Bompard 626417
                               'name': 'test',
Aurélien Bompard 626417
                               'namespace': None,
Aurélien Bompard 626417
                               'parent': None,
Aurélien Bompard 626417
                               'priorities': {},
Aurélien Bompard 626417
                               'tags': [],
Aurélien Bompard 626417
                               'url_path': 'test',
Aurélien Bompard 626417
                               'user': {'fullname': 'PY C', 'name': 'pingou'}},
Aurélien Bompard 626417
                'status': 'Open',
Aurélien Bompard 626417
                'title': 'Test PR',
Aurélien Bompard 626417
                'uid': 'e8b68df8711648deac67c3afed15a798',
Aurélien Bompard 626417
                'updated_on': '1516348115',
Aurélien Bompard 626417
                'user': {'fullname': 'PY C', 'name': 'pingou'}
Pierre-Yves Chibon 9811e6
            }
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 9811e6
    def test_api_pull_request_open_missing_initial_comment(self):
Pierre-Yves Chibon 9811e6
        """ Test the api_pull_request_create method of the flask api when
Pierre-Yves Chibon 9811e6
        not initial comment is submitted.
Pierre-Yves Chibon 9811e6
        """
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        tests.create_projects(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 9811e6
        tests.create_projects_git(os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 9811e6
                                  bare=True)
Pierre-Yves Chibon 9811e6
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 9811e6
        tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 9811e6
                                  branch='test')
Pierre-Yves Chibon 9811e6
        tests.create_tokens(self.session)
Pierre-Yves Chibon 9811e6
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        headers = {'Authorization': 'token aaabbbcccddd'}
Pierre-Yves Chibon 9811e6
        data = {
Pierre-Yves Chibon 9811e6
            'title': 'Test PR',
Pierre-Yves Chibon 9811e6
            'branch_to': 'master',
Pierre-Yves Chibon 9811e6
            'branch_from': 'test',
Pierre-Yves Chibon 9811e6
        }
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon 9811e6
        output = self.app.post(
Pierre-Yves Chibon 9811e6
            '/api/0/test/pull-request/new', headers=headers, data=data)
Pierre-Yves Chibon 9811e6
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Aurélien Bompard 626417
        data['project']['date_created'] = '1516348115'
Aurélien Bompard 626417
        data['project']['date_modified'] = '1516348115'
Aurélien Bompard 626417
        data['repo_from']['date_created'] = '1516348115'
Aurélien Bompard 626417
        data['repo_from']['date_modified'] = '1516348115'
Aurélien Bompard 626417
        data['uid'] = 'e8b68df8711648deac67c3afed15a798'
Aurélien Bompard 626417
        data['commit_start'] = '114f1b468a5f05e635fcb6394273f3f907386eab'
Aurélien Bompard 626417
        data['commit_stop'] = '114f1b468a5f05e635fcb6394273f3f907386eab'
Aurélien Bompard 626417
        data['date_created'] = '1516348115'
Aurélien Bompard 626417
        data['last_updated'] = '1516348115'
Aurélien Bompard 626417
        data['updated_on'] = '1516348115'
Pierre-Yves Chibon 9811e6
        self.assertDictEqual(
Pierre-Yves Chibon 9811e6
            data,
Pierre-Yves Chibon 9811e6
            {
Aurélien Bompard 626417
                'assignee': None,
Aurélien Bompard 626417
                'branch': 'master',
Aurélien Bompard 626417
                'branch_from': 'test',
Aurélien Bompard 626417
                'cached_merge_status': 'unknown',
Aurélien Bompard 626417
                'closed_at': None,
Aurélien Bompard 626417
                'closed_by': None,
Aurélien Bompard 626417
                'comments': [],
Aurélien Bompard 626417
                'commit_start': '114f1b468a5f05e635fcb6394273f3f907386eab',
Aurélien Bompard 626417
                'commit_stop': '114f1b468a5f05e635fcb6394273f3f907386eab',
Aurélien Bompard 626417
                'date_created': '1516348115',
Aurélien Bompard 626417
                'id': 1,
Aurélien Bompard 626417
                'initial_comment': None,
Aurélien Bompard 626417
                'last_updated': '1516348115',
Aurélien Bompard 626417
                'project': {'access_groups': {'admin': [],
Aurélien Bompard 626417
                                                'commit': [],
Aurélien Bompard 626417
                                                'ticket':[]},
Aurélien Bompard 626417
                             'access_users': {'admin': [],
Aurélien Bompard 626417
                                               'commit': [],
Aurélien Bompard 626417
                                               'owner': ['pingou'],
Aurélien Bompard 626417
                                               'ticket': []},
Aurélien Bompard 626417
                             'close_status': ['Invalid',
Aurélien Bompard 626417
                                               'Insufficient data',
Aurélien Bompard 626417
                                               'Fixed',
Aurélien Bompard 626417
                                               'Duplicate'],
Aurélien Bompard 626417
                             'custom_keys': [],
Aurélien Bompard 626417
                             'date_created': '1516348115',
Aurélien Bompard 626417
                             'date_modified': '1516348115',
Aurélien Bompard 626417
                             'description': 'test project #1',
Aurélien Bompard 626417
                             'fullname': 'test',
Aurélien Bompard 626417
                             'id': 1,
Aurélien Bompard 626417
                             'milestones': {},
Aurélien Bompard 626417
                             'name': 'test',
Aurélien Bompard 626417
                             'namespace': None,
Aurélien Bompard 626417
                             'parent': None,
Aurélien Bompard 626417
                             'priorities': {},
Aurélien Bompard 626417
                             'tags': [],
Aurélien Bompard 626417
                             'url_path': 'test',
Aurélien Bompard 626417
                             'user': {'fullname': 'PY C', 'name': 'pingou'}},
Aurélien Bompard 626417
                'remote_git': None,
Aurélien Bompard 626417
                'repo_from': {'access_groups': {'admin': [],
Aurélien Bompard 626417
                                                  'commit': [],
Aurélien Bompard 626417
                                                  'ticket': []},
Aurélien Bompard 626417
                               'access_users': {'admin': [],
Aurélien Bompard 626417
                                                 'commit': [],
Aurélien Bompard 626417
                                                 'owner': ['pingou'],
Aurélien Bompard 626417
                                                 'ticket': []},
Aurélien Bompard 626417
                               'close_status': ['Invalid',
Aurélien Bompard 626417
                                                 'Insufficient data',
Aurélien Bompard 626417
                                                 'Fixed',
Aurélien Bompard 626417
                                                 'Duplicate'],
Aurélien Bompard 626417
                               'custom_keys': [],
Aurélien Bompard 626417
                               'date_created': '1516348115',
Aurélien Bompard 626417
                               'date_modified': '1516348115',
Aurélien Bompard 626417
                               'description': 'test project #1',
Aurélien Bompard 626417
                               'fullname': 'test',
Aurélien Bompard 626417
                               'id': 1,
Aurélien Bompard 626417
                               'milestones': {},
Aurélien Bompard 626417
                               'name': 'test',
Aurélien Bompard 626417
                               'namespace': None,
Aurélien Bompard 626417
                               'parent': None,
Aurélien Bompard 626417
                               'priorities': {},
Aurélien Bompard 626417
                               'tags': [],
Aurélien Bompard 626417
                               'url_path': 'test',
Aurélien Bompard 626417
                               'user': {'fullname': 'PY C', 'name': 'pingou'}},
Aurélien Bompard 626417
                'status': 'Open',
Aurélien Bompard 626417
                'title': 'Test PR',
Aurélien Bompard 626417
                'uid': 'e8b68df8711648deac67c3afed15a798',
Aurélien Bompard 626417
                'updated_on': '1516348115',
Aurélien Bompard 626417
                'user': {'fullname': 'PY C', 'name': 'pingou'}
Pierre-Yves Chibon 9811e6
            }
Pierre-Yves Chibon 9811e6
        )
Pierre-Yves Chibon 9811e6
Pierre-Yves Chibon c71c2d
Pierre-Yves Chibon c71c2d
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)