|
Pierre-Yves Chibon |
5a9017 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
(c) 2019 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
Authors:
|
|
Pierre-Yves Chibon |
5a9017 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
from __future__ import unicode_literals, absolute_import
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
import arrow
|
|
Pierre-Yves Chibon |
5a9017 |
import copy
|
|
Pierre-Yves Chibon |
5a9017 |
import datetime
|
|
Pierre-Yves Chibon |
5a9017 |
import unittest
|
|
Pierre-Yves Chibon |
5a9017 |
import shutil
|
|
Pierre-Yves Chibon |
5a9017 |
import sys
|
|
Pierre-Yves Chibon |
5a9017 |
import time
|
|
Pierre-Yves Chibon |
5a9017 |
import os
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
import flask
|
|
Pierre-Yves Chibon |
5a9017 |
import json
|
|
Pierre-Yves Chibon |
5a9017 |
import munch
|
|
Pierre-Yves Chibon |
5a9017 |
from mock import patch, MagicMock
|
|
Pierre-Yves Chibon |
5a9017 |
from sqlalchemy.exc import SQLAlchemyError
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
5a9017 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
5a9017 |
import tests
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
class PagureFlaskApiForkUpdatetests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Tests for the flask API of pagure for updating a PR """
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
maxDiff = None
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
@patch('pagure.lib.git.update_git', MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
5a9017 |
@patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
5a9017 |
def setUp(self):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
5a9017 |
super(PagureFlaskApiForkUpdatetests, self).setUp()
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
5a9017 |
tests.add_content_git_repo(
|
|
Pierre-Yves Chibon |
5a9017 |
os.path.join(self.path, "repos", "test.git"))
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# Fork
|
|
Pierre-Yves Chibon |
5a9017 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
5a9017 |
self.session, 'test')
|
|
Pierre-Yves Chibon |
5a9017 |
task = pagure.lib.query.fork_project(
|
|
Pierre-Yves Chibon |
5a9017 |
session=self.session,
|
|
Pierre-Yves Chibon |
5a9017 |
user='pingou',
|
|
Pierre-Yves Chibon |
5a9017 |
repo=project,
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
self.session.commit()
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
task.get(),
|
|
Pierre-Yves Chibon |
5a9017 |
{'endpoint': 'ui_ns.view_repo',
|
|
Pierre-Yves Chibon |
5a9017 |
'repo': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'namespace': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'username': 'pingou'})
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
tests.add_readme_git_repo(
|
|
Pierre-Yves Chibon |
5a9017 |
os.path.join(self.path, "repos", "forks", "pingou", "test.git"))
|
|
Pierre-Yves Chibon |
5a9017 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
5a9017 |
self.session, 'test')
|
|
Pierre-Yves Chibon |
5a9017 |
fork = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
5a9017 |
self.session,
|
|
Pierre-Yves Chibon |
5a9017 |
'test',
|
|
Pierre-Yves Chibon |
5a9017 |
user='pingou',
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
5a9017 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
req = pagure.lib.query.new_pull_request(
|
|
Pierre-Yves Chibon |
5a9017 |
session=self.session,
|
|
Pierre-Yves Chibon |
5a9017 |
repo_from=fork,
|
|
Pierre-Yves Chibon |
5a9017 |
branch_from='master',
|
|
Pierre-Yves Chibon |
5a9017 |
repo_to=project,
|
|
Pierre-Yves Chibon |
5a9017 |
branch_to='master',
|
|
Pierre-Yves Chibon |
5a9017 |
title='test pull-request',
|
|
Pierre-Yves Chibon |
5a9017 |
user='pingou',
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
self.session.commit()
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# Assert the PR is open
|
|
Pierre-Yves Chibon |
5a9017 |
self.session = pagure.lib.query.create_session(self.dbpath)
|
|
Pierre-Yves Chibon |
5a9017 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
5a9017 |
self.session, 'test')
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(len(project.requests), 1)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(project.requests[0].status, "Open")
|
|
Pierre-Yves Chibon |
5a9017 |
# Check how the PR renders in the API and the UI
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.get('/api/0/test/pull-request/1')
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
def test_api_pull_request_update_invalid_project_namespace(self):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Test api_pull_request_update method when the project doesn't exist.
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
5a9017 |
'/api/0/somenamespace/test3/pull-request/1', headers=headers)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
5a9017 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
data,
|
|
Pierre-Yves Chibon |
5a9017 |
{'error': 'Invalid or expired token. Please visit '
|
|
Pierre-Yves Chibon |
5a9017 |
'http://localhost.localdomain/settings#api-keys to get or renew your '
|
|
Pierre-Yves Chibon |
5a9017 |
'API token.',
|
|
Pierre-Yves Chibon |
5a9017 |
'error_code': 'EINVALIDTOK'}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
def test_api_pull_request_update_invalid_project(self):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Test api_pull_request_update method when the project doesn't exist.
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# Invalid project
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.post('/api/0/foo/pull-request/1', headers=headers)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
5a9017 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
data,
|
|
Pierre-Yves Chibon |
5a9017 |
{
|
|
Pierre-Yves Chibon |
5a9017 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
5a9017 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
5a9017 |
}
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
def test_api_pull_request_update_invalid_project_token(self):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Test api_pull_request_update method when the token doesn't correspond
|
|
Pierre-Yves Chibon |
5a9017 |
to the project.
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.post('/api/0/test2/pull-request/1', headers=headers)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
5a9017 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
def test_api_pull_request_update_invalid_pr(self):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Test api_assign_pull_request method when asking for an invalid PR
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# Invalid PR id
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.post('/api/0/test/pull-request/404', headers=headers)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
5a9017 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
data,
|
|
Pierre-Yves Chibon |
5a9017 |
{'error': 'Pull-Request not found', 'error_code': 'ENOREQ'}
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
def test_api_pull_request_update_no_input(self):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Test api_assign_pull_request method when no input is specified
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# No input
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.post('/api/0/test/pull-request/1', headers=headers)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
5a9017 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
data,
|
|
Pierre-Yves Chibon |
5a9017 |
{
|
|
Pierre-Yves Chibon |
5a9017 |
'error': 'Invalid or incomplete input submitted',
|
|
Pierre-Yves Chibon |
5a9017 |
'error_code': 'EINVALIDREQ',
|
|
Pierre-Yves Chibon |
5a9017 |
'errors': {'title': ['This field is required.']}
|
|
Pierre-Yves Chibon |
5a9017 |
}
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
def test_api_pull_request_update_insufficient_input(self):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Test api_assign_pull_request method when no input is specified
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
5a9017 |
data = {'initial_comment': 'will not work'}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# Missing the required title field
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.post('/api/0/test/pull-request/1', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
5a9017 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
data,
|
|
Pierre-Yves Chibon |
5a9017 |
{
|
|
Pierre-Yves Chibon |
5a9017 |
'error': 'Invalid or incomplete input submitted',
|
|
Pierre-Yves Chibon |
5a9017 |
'error_code': 'EINVALIDREQ',
|
|
Pierre-Yves Chibon |
5a9017 |
'errors': {'title': ['This field is required.']}
|
|
Pierre-Yves Chibon |
5a9017 |
}
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
def test_api_pull_request_update_edited(self):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Test api_assign_pull_request method when with valid input
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
data = {
|
|
Pierre-Yves Chibon |
5a9017 |
'title': 'edited test PR',
|
|
Pierre-Yves Chibon |
5a9017 |
'initial_comment': 'Edited initial comment',
|
|
Pierre-Yves Chibon |
5a9017 |
}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# Valid request
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
5a9017 |
'/api/0/test/pull-request/1', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5a9017 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5a9017 |
# Hard-code all the values that will change from a test to another
|
|
Pierre-Yves Chibon |
5a9017 |
# because either random or time-based
|
|
Pierre-Yves Chibon |
5a9017 |
data['date_created'] = '1551276260'
|
|
Pierre-Yves Chibon |
5a9017 |
data['last_updated'] = '1551276261'
|
|
Pierre-Yves Chibon |
5a9017 |
data['updated_on'] = '1551276260'
|
|
Pierre-Yves Chibon |
5a9017 |
data['commit_start'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
|
|
Pierre-Yves Chibon |
5a9017 |
data['commit_stop'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
|
|
Pierre-Yves Chibon |
5a9017 |
data['project']['date_created'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['project']['date_modified'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['repo_from']['date_created'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['repo_from']['date_modified'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['repo_from']['parent']['date_created'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['repo_from']['parent']['date_modified'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['uid'] = 'a2bddecc8ea548e88c22a0df77670092'
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
data,
|
|
Pierre-Yves Chibon |
5a9017 |
{
|
|
Pierre-Yves Chibon |
5a9017 |
'assignee': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'branch': 'master',
|
|
Pierre-Yves Chibon |
5a9017 |
'branch_from': 'master',
|
|
Pierre-Yves Chibon |
5a9017 |
'cached_merge_status': 'unknown',
|
|
Pierre-Yves Chibon |
5a9017 |
'closed_at': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'closed_by': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'comments': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit_start': '5f5d609db65d447f77ba00e25afd17ba5053344b',
|
|
Pierre-Yves Chibon |
5a9017 |
'commit_stop': '5f5d609db65d447f77ba00e25afd17ba5053344b',
|
|
Pierre-Yves Chibon |
5a9017 |
'date_created': '1551276260',
|
|
Pierre-Yves Chibon |
5a9017 |
'id': 1,
|
|
Pierre-Yves Chibon |
5a9017 |
'initial_comment': 'Edited initial comment',
|
|
Pierre-Yves Chibon |
5a9017 |
'last_updated': '1551276261',
|
|
Pierre-Yves Chibon |
5a9017 |
'project': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'access_users': {'admin': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'owner': ['pingou'],
|
|
Pierre-Yves Chibon |
5a9017 |
'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'close_status': ['Invalid',
|
|
Pierre-Yves Chibon |
5a9017 |
'Insufficient data',
|
|
Pierre-Yves Chibon |
5a9017 |
'Fixed',
|
|
Pierre-Yves Chibon |
5a9017 |
'Duplicate'],
|
|
Pierre-Yves Chibon |
5a9017 |
'custom_keys': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'date_created': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'date_modified': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'description': 'test project #1',
|
|
Pierre-Yves Chibon |
5a9017 |
'fullname': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'id': 1,
|
|
Pierre-Yves Chibon |
5a9017 |
'milestones': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'name': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'namespace': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'parent': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'priorities': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'tags': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'url_path': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'user': {'fullname': 'PY C', 'name': 'pingou'}},
|
|
Pierre-Yves Chibon |
5a9017 |
'remote_git': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'repo_from': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'access_users': {'admin': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'owner': ['pingou'],
|
|
Pierre-Yves Chibon |
5a9017 |
'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'close_status': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'custom_keys': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'date_created': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'date_modified': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'description': 'test project #1',
|
|
Pierre-Yves Chibon |
5a9017 |
'fullname': 'forks/pingou/test',
|
|
Pierre-Yves Chibon |
5a9017 |
'id': 4,
|
|
Pierre-Yves Chibon |
5a9017 |
'milestones': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'name': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'namespace': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'parent': {'access_groups': {'admin': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'access_users': {'admin': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'owner': ['pingou'],
|
|
Pierre-Yves Chibon |
5a9017 |
'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'close_status': ['Invalid',
|
|
Pierre-Yves Chibon |
5a9017 |
'Insufficient data',
|
|
Pierre-Yves Chibon |
5a9017 |
'Fixed',
|
|
Pierre-Yves Chibon |
5a9017 |
'Duplicate'],
|
|
Pierre-Yves Chibon |
5a9017 |
'custom_keys': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'date_created': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'date_modified': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'description': 'test project #1',
|
|
Pierre-Yves Chibon |
5a9017 |
'fullname': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'id': 1,
|
|
Pierre-Yves Chibon |
5a9017 |
'milestones': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'name': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'namespace': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'parent': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'priorities': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'tags': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'url_path': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'user': {'fullname': 'PY C', 'name': 'pingou'}},
|
|
Pierre-Yves Chibon |
5a9017 |
'priorities': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'tags': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'url_path': 'fork/pingou/test',
|
|
Pierre-Yves Chibon |
5a9017 |
'user': {'fullname': 'PY C', 'name': 'pingou'}},
|
|
Pierre-Yves Chibon |
5a9017 |
'status': 'Open',
|
|
Pierre-Yves Chibon |
5a9017 |
'tags': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'threshold_reached': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'title': 'edited test PR',
|
|
Pierre-Yves Chibon |
5a9017 |
'uid': 'a2bddecc8ea548e88c22a0df77670092',
|
|
Pierre-Yves Chibon |
5a9017 |
'updated_on': '1551276260',
|
|
Pierre-Yves Chibon |
5a9017 |
'user': {'fullname': 'PY C', 'name': 'pingou'}
|
|
Pierre-Yves Chibon |
5a9017 |
}
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
def test_api_pull_request_update_edited_no_comment(self):
|
|
Pierre-Yves Chibon |
5a9017 |
""" Test api_assign_pull_request method when with valid input
|
|
Pierre-Yves Chibon |
5a9017 |
"""
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
data = {
|
|
Pierre-Yves Chibon |
5a9017 |
'title': 'edited test PR',
|
|
Pierre-Yves Chibon |
5a9017 |
}
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
# Valid request
|
|
Pierre-Yves Chibon |
5a9017 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
5a9017 |
'/api/0/test/pull-request/1', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5a9017 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5a9017 |
# Hard-code all the values that will change from a test to another
|
|
Pierre-Yves Chibon |
5a9017 |
# because either random or time-based
|
|
Pierre-Yves Chibon |
5a9017 |
data['date_created'] = '1551276260'
|
|
Pierre-Yves Chibon |
5a9017 |
data['last_updated'] = '1551276261'
|
|
Pierre-Yves Chibon |
5a9017 |
data['updated_on'] = '1551276260'
|
|
Pierre-Yves Chibon |
5a9017 |
data['commit_start'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
|
|
Pierre-Yves Chibon |
5a9017 |
data['commit_stop'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
|
|
Pierre-Yves Chibon |
5a9017 |
data['project']['date_created'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['project']['date_modified'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['repo_from']['date_created'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['repo_from']['date_modified'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['repo_from']['parent']['date_created'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['repo_from']['parent']['date_modified'] = '1551276259'
|
|
Pierre-Yves Chibon |
5a9017 |
data['uid'] = 'a2bddecc8ea548e88c22a0df77670092'
|
|
Pierre-Yves Chibon |
5a9017 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
5a9017 |
data,
|
|
Pierre-Yves Chibon |
5a9017 |
{
|
|
Pierre-Yves Chibon |
5a9017 |
'assignee': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'branch': 'master',
|
|
Pierre-Yves Chibon |
5a9017 |
'branch_from': 'master',
|
|
Pierre-Yves Chibon |
5a9017 |
'cached_merge_status': 'unknown',
|
|
Pierre-Yves Chibon |
5a9017 |
'closed_at': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'closed_by': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'comments': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit_start': '5f5d609db65d447f77ba00e25afd17ba5053344b',
|
|
Pierre-Yves Chibon |
5a9017 |
'commit_stop': '5f5d609db65d447f77ba00e25afd17ba5053344b',
|
|
Pierre-Yves Chibon |
5a9017 |
'date_created': '1551276260',
|
|
Pierre-Yves Chibon |
5a9017 |
'id': 1,
|
|
Pierre-Yves Chibon |
5a9017 |
'initial_comment': '',
|
|
Pierre-Yves Chibon |
5a9017 |
'last_updated': '1551276261',
|
|
Pierre-Yves Chibon |
5a9017 |
'project': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'access_users': {'admin': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'owner': ['pingou'],
|
|
Pierre-Yves Chibon |
5a9017 |
'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'close_status': ['Invalid',
|
|
Pierre-Yves Chibon |
5a9017 |
'Insufficient data',
|
|
Pierre-Yves Chibon |
5a9017 |
'Fixed',
|
|
Pierre-Yves Chibon |
5a9017 |
'Duplicate'],
|
|
Pierre-Yves Chibon |
5a9017 |
'custom_keys': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'date_created': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'date_modified': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'description': 'test project #1',
|
|
Pierre-Yves Chibon |
5a9017 |
'fullname': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'id': 1,
|
|
Pierre-Yves Chibon |
5a9017 |
'milestones': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'name': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'namespace': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'parent': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'priorities': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'tags': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'url_path': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'user': {'fullname': 'PY C', 'name': 'pingou'}},
|
|
Pierre-Yves Chibon |
5a9017 |
'remote_git': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'repo_from': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'access_users': {'admin': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'owner': ['pingou'],
|
|
Pierre-Yves Chibon |
5a9017 |
'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'close_status': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'custom_keys': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'date_created': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'date_modified': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'description': 'test project #1',
|
|
Pierre-Yves Chibon |
5a9017 |
'fullname': 'forks/pingou/test',
|
|
Pierre-Yves Chibon |
5a9017 |
'id': 4,
|
|
Pierre-Yves Chibon |
5a9017 |
'milestones': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'name': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'namespace': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'parent': {'access_groups': {'admin': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'access_users': {'admin': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'commit': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'owner': ['pingou'],
|
|
Pierre-Yves Chibon |
5a9017 |
'ticket': []},
|
|
Pierre-Yves Chibon |
5a9017 |
'close_status': ['Invalid',
|
|
Pierre-Yves Chibon |
5a9017 |
'Insufficient data',
|
|
Pierre-Yves Chibon |
5a9017 |
'Fixed',
|
|
Pierre-Yves Chibon |
5a9017 |
'Duplicate'],
|
|
Pierre-Yves Chibon |
5a9017 |
'custom_keys': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'date_created': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'date_modified': '1551276259',
|
|
Pierre-Yves Chibon |
5a9017 |
'description': 'test project #1',
|
|
Pierre-Yves Chibon |
5a9017 |
'fullname': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'id': 1,
|
|
Pierre-Yves Chibon |
5a9017 |
'milestones': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'name': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'namespace': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'parent': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'priorities': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'tags': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'url_path': 'test',
|
|
Pierre-Yves Chibon |
5a9017 |
'user': {'fullname': 'PY C', 'name': 'pingou'}},
|
|
Pierre-Yves Chibon |
5a9017 |
'priorities': {},
|
|
Pierre-Yves Chibon |
5a9017 |
'tags': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'url_path': 'fork/pingou/test',
|
|
Pierre-Yves Chibon |
5a9017 |
'user': {'fullname': 'PY C', 'name': 'pingou'}},
|
|
Pierre-Yves Chibon |
5a9017 |
'status': 'Open',
|
|
Pierre-Yves Chibon |
5a9017 |
'tags': [],
|
|
Pierre-Yves Chibon |
5a9017 |
'threshold_reached': None,
|
|
Pierre-Yves Chibon |
5a9017 |
'title': 'edited test PR',
|
|
Pierre-Yves Chibon |
5a9017 |
'uid': 'a2bddecc8ea548e88c22a0df77670092',
|
|
Pierre-Yves Chibon |
5a9017 |
'updated_on': '1551276260',
|
|
Pierre-Yves Chibon |
5a9017 |
'user': {'fullname': 'PY C', 'name': 'pingou'}
|
|
Pierre-Yves Chibon |
5a9017 |
}
|
|
Pierre-Yves Chibon |
5a9017 |
)
|
|
Pierre-Yves Chibon |
5a9017 |
|
|
Pierre-Yves Chibon |
5a9017 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
5a9017 |
unittest.main(verbosity=2)
|