|
Pierre-Yves Chibon |
8fc633 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
"""
|
|
Pierre-Yves Chibon |
8fc633 |
(c) 2015-2016 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
Authors:
|
|
Pierre-Yves Chibon |
8fc633 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
"""
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
8fc633 |
import pkg_resources
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
import datetime
|
|
Pierre-Yves Chibon |
8fc633 |
import unittest
|
|
Pierre-Yves Chibon |
8fc633 |
import shutil
|
|
Pierre-Yves Chibon |
8fc633 |
import sys
|
|
Pierre-Yves Chibon |
8fc633 |
import os
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
import json
|
|
Pierre-Yves Chibon |
8fc633 |
from mock import patch
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
8fc633 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
import pagure.api
|
|
Pierre-Yves Chibon |
8fc633 |
import pagure.lib
|
|
Pierre-Yves Chibon |
d6ddc4 |
import pagure.lib.model as model
|
|
Pierre-Yves Chibon |
8fc633 |
import tests
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
class PagureFlaskApiUSertests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
8fc633 |
""" Tests for the flask API of pagure for issue """
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
def setUp(self):
|
|
Pierre-Yves Chibon |
8fc633 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
8fc633 |
super(PagureFlaskApiUSertests, self).setUp()
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
8fc633 |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
8fc633 |
pagure.api.SESSION = self.session
|
|
Pierre-Yves Chibon |
8fc633 |
pagure.api.fork.SESSION = self.session
|
|
Pierre-Yves Chibon |
8fc633 |
pagure.api.user.SESSION = self.session
|
|
Pierre-Yves Chibon |
8fc633 |
pagure.lib.SESSION = self.session
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
pagure.APP.config['REQUESTS_FOLDER'] = None
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
def test_api_users(self):
|
|
Pierre-Yves Chibon |
8fc633 |
""" Test the api_users function. """
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
output = self.app.get('/api/0/users')
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8fc633 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(sorted(data['users']), ['foo', 'pingou'])
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(sorted(data.keys()), ['mention', 'total_users', 'users'])
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(data['total_users'], 2)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
output = self.app.get('/api/0/users?pattern=p')
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8fc633 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(data['users'], ['pingou'])
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(sorted(data.keys()), ['mention', 'total_users', 'users'])
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(data['total_users'], 1)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Clement Verna |
8ed9ee |
def test_api_view_user(self):
|
|
Clement Verna |
8ed9ee |
"""
|
|
Clement Verna |
8ed9ee |
Test the api_view_user method of the flask api
|
|
Clement Verna |
8ed9ee |
The tested user has no project or forks.
|
|
Clement Verna |
8ed9ee |
"""
|
|
Clement Verna |
8ed9ee |
output = self.app.get('/api/0/user/pingou')
|
|
Clement Verna |
8ed9ee |
self.assertEqual(output.status_code, 200)
|
|
Clement Verna |
8ed9ee |
exp = {
|
|
Clement Verna |
8ed9ee |
"forks": [],
|
|
Clement Verna |
8ed9ee |
"repos": [],
|
|
Clement Verna |
8ed9ee |
"user": { "fullname": "PY C", "name": "pingou"}}
|
|
Clement Verna |
8ed9ee |
data = json.loads(output.data)
|
|
Clement Verna |
8ed9ee |
self.assertEqual(data, exp)
|
|
Clement Verna |
8ed9ee |
|
|
Clement Verna |
8ed9ee |
def test_api_view_user_with_project(self):
|
|
Clement Verna |
8ed9ee |
"""
|
|
Clement Verna |
8ed9ee |
Test the api_view_user method of the flask api,
|
|
Clement Verna |
8ed9ee |
this time the user has some project defined.
|
|
Clement Verna |
8ed9ee |
"""
|
|
Clement Verna |
8ed9ee |
tests.create_projects(self.session)
|
|
Clement Verna |
8ed9ee |
|
|
Clement Verna |
8ed9ee |
output = self.app.get('/api/0/user/pingou')
|
|
Clement Verna |
8ed9ee |
self.assertEqual(output.status_code, 200)
|
|
Clement Verna |
8ed9ee |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
c9e619 |
data['repos'][0]['date_created'] = "1490272832"
|
|
Clement Verna |
cd6e30 |
data['repos'][0]['date_modified'] = "1490272832"
|
|
Pierre-Yves Chibon |
c9e619 |
data['repos'][1]['date_created'] = "1490272832"
|
|
Clement Verna |
cd6e30 |
data['repos'][1]['date_modified'] = "1490272832"
|
|
Pierre-Yves Chibon |
c9e619 |
data['repos'][2]['date_created'] = "1490272832"
|
|
Clement Verna |
cd6e30 |
data['repos'][2]['date_modified'] = "1490272832"
|
|
Matt Prahl |
6bf79a |
expected_data = {
|
|
Clement Verna |
8ed9ee |
"forks": [],
|
|
Pierre-Yves Chibon |
c9e619 |
"repos": [
|
|
Pierre-Yves Chibon |
c9e619 |
{
|
|
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 |
},
|
|
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 |
],
|
|
Matt Prahl |
6bf79a |
"custom_keys": [],
|
|
Matt Prahl |
6bf79a |
"date_created": "1490272832",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1490272832",
|
|
Matt Prahl |
6bf79a |
"description": "test project #1",
|
|
Matt Prahl |
6bf79a |
"fullname": "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 |
"settings": {
|
|
Matt Prahl |
6bf79a |
"Enforce_signed-off_commits_in_pull-request": False,
|
|
Matt Prahl |
6bf79a |
"Minimum_score_to_merge_pull-request": -1,
|
|
Matt Prahl |
6bf79a |
"Only_assignee_can_merge_pull-request": False,
|
|
Matt Prahl |
6bf79a |
"Web-hooks": None,
|
|
Matt Prahl |
6bf79a |
"always_merge": False,
|
|
Matt Prahl |
6bf79a |
"fedmsg_notifications": True,
|
|
Matt Prahl |
6bf79a |
"issue_tracker": True,
|
|
Matt Prahl |
6bf79a |
"issues_default_to_private": False,
|
|
Matt Prahl |
6bf79a |
"pull_request_access_only": False,
|
|
Matt Prahl |
6bf79a |
"project_documentation": False,
|
|
Matt Prahl |
6bf79a |
"pull_requests": True
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"tags": [],
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Matt Prahl |
6bf79a |
}
|
|
Clement Verna |
8ed9ee |
},
|
|
Clement Verna |
8ed9ee |
{
|
|
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 |
},
|
|
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 |
],
|
|
Matt Prahl |
6bf79a |
"custom_keys": [],
|
|
Matt Prahl |
6bf79a |
"date_created": "1490272832",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1490272832",
|
|
Matt Prahl |
6bf79a |
"description": "test project #2",
|
|
Matt Prahl |
6bf79a |
"fullname": "test2",
|
|
Matt Prahl |
6bf79a |
"id": 2,
|
|
Matt Prahl |
6bf79a |
"milestones": {},
|
|
Matt Prahl |
6bf79a |
"name": "test2",
|
|
Matt Prahl |
6bf79a |
"namespace": None,
|
|
Matt Prahl |
6bf79a |
"parent": None,
|
|
Matt Prahl |
6bf79a |
"priorities": {},
|
|
Matt Prahl |
6bf79a |
"settings": {
|
|
Matt Prahl |
6bf79a |
"Enforce_signed-off_commits_in_pull-request": False,
|
|
Matt Prahl |
6bf79a |
"Minimum_score_to_merge_pull-request": -1,
|
|
Matt Prahl |
6bf79a |
"Only_assignee_can_merge_pull-request": False,
|
|
Matt Prahl |
6bf79a |
"Web-hooks": None,
|
|
Matt Prahl |
6bf79a |
"always_merge": False,
|
|
Matt Prahl |
6bf79a |
"fedmsg_notifications": True,
|
|
Matt Prahl |
6bf79a |
"issue_tracker": True,
|
|
Matt Prahl |
6bf79a |
"issues_default_to_private": False,
|
|
Matt Prahl |
6bf79a |
"pull_request_access_only": False,
|
|
Matt Prahl |
6bf79a |
"project_documentation": False,
|
|
Matt Prahl |
6bf79a |
"pull_requests": True
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"tags": [],
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Matt Prahl |
6bf79a |
}
|
|
Clement Verna |
8ed9ee |
},
|
|
Clement Verna |
8ed9ee |
{
|
|
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 |
},
|
|
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 |
],
|
|
Matt Prahl |
6bf79a |
"custom_keys": [],
|
|
Matt Prahl |
6bf79a |
"date_created": "1490272832",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1490272832",
|
|
Matt Prahl |
6bf79a |
"description": "namespaced test project",
|
|
Matt Prahl |
6bf79a |
"fullname": "somenamespace/test3",
|
|
Matt Prahl |
6bf79a |
"id": 3,
|
|
Matt Prahl |
6bf79a |
"milestones": {},
|
|
Matt Prahl |
6bf79a |
"name": "test3",
|
|
Matt Prahl |
6bf79a |
"namespace": "somenamespace",
|
|
Matt Prahl |
6bf79a |
"parent": None,
|
|
Matt Prahl |
6bf79a |
"priorities": {},
|
|
Matt Prahl |
6bf79a |
"settings": {
|
|
Matt Prahl |
6bf79a |
"Enforce_signed-off_commits_in_pull-request": False,
|
|
Matt Prahl |
6bf79a |
"Minimum_score_to_merge_pull-request": -1,
|
|
Matt Prahl |
6bf79a |
"Only_assignee_can_merge_pull-request": False,
|
|
Matt Prahl |
6bf79a |
"Web-hooks": None,
|
|
Matt Prahl |
6bf79a |
"always_merge": False,
|
|
Matt Prahl |
6bf79a |
"fedmsg_notifications": True,
|
|
Matt Prahl |
6bf79a |
"issue_tracker": True,
|
|
Matt Prahl |
6bf79a |
"issues_default_to_private": False,
|
|
Matt Prahl |
6bf79a |
"project_documentation": False,
|
|
Matt Prahl |
6bf79a |
"pull_request_access_only": False,
|
|
Matt Prahl |
6bf79a |
"pull_requests": True
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"tags": [],
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Matt Prahl |
6bf79a |
}
|
|
Pierre-Yves Chibon |
c9e619 |
}
|
|
Clement Verna |
8ed9ee |
],
|
|
Clement Verna |
8ed9ee |
"user": {
|
|
Clement Verna |
8ed9ee |
"fullname": "PY C",
|
|
Clement Verna |
8ed9ee |
"name": "pingou"
|
|
Clement Verna |
8ed9ee |
}
|
|
Clement Verna |
8ed9ee |
}
|
|
Matt Prahl |
6bf79a |
self.assertEqual(data, expected_data)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
8fc633 |
def test_api_view_user_activity_stats(self, mockemail):
|
|
Pierre-Yves Chibon |
8fc633 |
""" Test the api_view_user_activity_stats method of the flask user
|
|
Pierre-Yves Chibon |
8fc633 |
api. """
|
|
Pierre-Yves Chibon |
8fc633 |
mockemail.return_value = True
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
8fc633 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
8fc633 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
# Create a pull-request
|
|
Farhaan Bukhsh |
83f8bc |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Farhaan Bukhsh |
83f8bc |
forked_repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
8fc633 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
8fc633 |
session=self.session,
|
|
Pierre-Yves Chibon |
8fc633 |
repo_from=forked_repo,
|
|
Pierre-Yves Chibon |
8fc633 |
branch_from='master',
|
|
Pierre-Yves Chibon |
8fc633 |
repo_to=repo,
|
|
Pierre-Yves Chibon |
8fc633 |
branch_to='master',
|
|
Pierre-Yves Chibon |
8fc633 |
title='test pull-request',
|
|
Pierre-Yves Chibon |
8fc633 |
user='pingou',
|
|
Pierre-Yves Chibon |
8fc633 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
8fc633 |
)
|
|
Pierre-Yves Chibon |
8fc633 |
self.session.commit()
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
# Check comments before
|
|
Pierre-Yves Chibon |
8fc633 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
8fc633 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(len(request.comments), 0)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
data = {
|
|
Pierre-Yves Chibon |
8fc633 |
'comment': 'This is a very interesting question',
|
|
Pierre-Yves Chibon |
8fc633 |
}
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
# Valid request
|
|
Pierre-Yves Chibon |
8fc633 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
8fc633 |
'/api/0/test/pull-request/1/comment', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8fc633 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
8fc633 |
data,
|
|
Pierre-Yves Chibon |
8fc633 |
{'message': 'Comment added'}
|
|
Pierre-Yves Chibon |
8fc633 |
)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
# One comment added
|
|
Pierre-Yves Chibon |
8fc633 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
8fc633 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(len(request.comments), 1)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
# Close PR
|
|
Pierre-Yves Chibon |
8fc633 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
8fc633 |
'/api/0/test/pull-request/1/close', headers=headers)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8fc633 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
8fc633 |
data,
|
|
Pierre-Yves Chibon |
8fc633 |
{"message": "Pull-request closed!"}
|
|
Pierre-Yves Chibon |
8fc633 |
)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
# PR closed
|
|
Pierre-Yves Chibon |
8fc633 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
8fc633 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(request.status, 'Closed')
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
# Finally retrieve the user's logs
|
|
Pierre-Yves Chibon |
8fc633 |
output = self.app.get('/api/0/user/pingou/activity/stats')
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8fc633 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
8fc633 |
date = datetime.datetime.utcnow().date().strftime('%Y-%m-%d')
|
|
Pierre-Yves Chibon |
f1bbc3 |
# There seems to be a difference in the JSON generated between
|
|
Pierre-Yves Chibon |
f1bbc3 |
# flask-0.10.1 (F23) and 0.11.1 (jenkins)
|
|
Pierre-Yves Chibon |
7507e1 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
f1bbc3 |
data == {date: 4}
|
|
Pierre-Yves Chibon |
f1bbc3 |
or
|
|
Pierre-Yves Chibon |
f1bbc3 |
data == [[date, 4]]
|
|
Pierre-Yves Chibon |
f1bbc3 |
)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
8fc633 |
def test_api_view_user_activity_date(self, mockemail):
|
|
Pierre-Yves Chibon |
8fc633 |
""" Test the api_view_user_activity_date method of the flask user
|
|
Pierre-Yves Chibon |
8fc633 |
api. """
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
self.test_api_view_user_activity_stats()
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
fa2aba |
# Invalid date
|
|
Pierre-Yves Chibon |
fa2aba |
output = self.app.get('/api/0/user/pingou/activity/AABB')
|
|
Pierre-Yves Chibon |
fa2aba |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
fa2aba |
|
|
Pierre-Yves Chibon |
fa2aba |
# Invalid date
|
|
Pierre-Yves Chibon |
fa2aba |
output = self.app.get('/api/0/user/pingou/activity/2016asd')
|
|
Pierre-Yves Chibon |
fa2aba |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fa2aba |
exp = {
|
|
Pierre-Yves Chibon |
fa2aba |
"activities": [],
|
|
Pierre-Yves Chibon |
fa2aba |
"date": "2016-01-01"
|
|
Pierre-Yves Chibon |
fa2aba |
}
|
|
Pierre-Yves Chibon |
fa2aba |
self.assertEqual(json.loads(output.data), exp)
|
|
Pierre-Yves Chibon |
fa2aba |
|
|
Pierre-Yves Chibon |
fa2aba |
# Date parsed, just not really as expected
|
|
Pierre-Yves Chibon |
fa2aba |
output = self.app.get('/api/0/user/pingou/activity/20161245')
|
|
Pierre-Yves Chibon |
fa2aba |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fa2aba |
exp = {
|
|
Pierre-Yves Chibon |
fa2aba |
"activities": [],
|
|
Pierre-Yves Chibon |
fa2aba |
"date": "1970-08-22"
|
|
Pierre-Yves Chibon |
fa2aba |
}
|
|
Pierre-Yves Chibon |
fa2aba |
self.assertEqual(json.loads(output.data), exp)
|
|
Pierre-Yves Chibon |
fa2aba |
|
|
Pierre-Yves Chibon |
8fc633 |
date = datetime.datetime.utcnow().date().strftime('%Y-%m-%d')
|
|
Pierre-Yves Chibon |
8fc633 |
# Retrieve the user's logs for today
|
|
Pierre-Yves Chibon |
8fc633 |
output = self.app.get('/api/0/user/pingou/activity/%s' % date)
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8fc633 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
8fc633 |
exp = {
|
|
Pierre-Yves Chibon |
8fc633 |
"activities": [
|
|
Pierre-Yves Chibon |
8fc633 |
{
|
|
Pierre-Yves Chibon |
8fc633 |
"date": date,
|
|
Pierre-Yves Chibon |
8fc633 |
"date_created": "1477558752",
|
|
Pierre-Yves Chibon |
263695 |
"type": "pull-request",
|
|
Pierre-Yves Chibon |
8fc633 |
"description_mk": "pingou created PR test#1 ",
|
|
Pierre-Yves Chibon |
8fc633 |
"id": 1,
|
|
Pierre-Yves Chibon |
a3362c |
"ref_id": "1",
|
|
Pierre-Yves Chibon |
a3362c |
"type": "created",
|
|
Pierre-Yves Chibon |
8fc633 |
"user": {
|
|
Pierre-Yves Chibon |
8fc633 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
8fc633 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
8fc633 |
}
|
|
Pierre-Yves Chibon |
8fc633 |
},
|
|
Pierre-Yves Chibon |
8fc633 |
{
|
|
Pierre-Yves Chibon |
8fc633 |
"date": date,
|
|
Pierre-Yves Chibon |
8fc633 |
"date_created": "1477558752",
|
|
Pierre-Yves Chibon |
263695 |
"type": "pull-request",
|
|
Clement Verna |
6c4ede |
"description_mk": "pingou commented on PR test#1 ",
|
|
Pierre-Yves Chibon |
8fc633 |
"id": 2,
|
|
Pierre-Yves Chibon |
a3362c |
"ref_id": "1",
|
|
Pierre-Yves Chibon |
a3362c |
"type": "commented",
|
|
Pierre-Yves Chibon |
8fc633 |
"user": {
|
|
Pierre-Yves Chibon |
8fc633 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
8fc633 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
8fc633 |
}
|
|
Pierre-Yves Chibon |
8fc633 |
},
|
|
Pierre-Yves Chibon |
8fc633 |
{
|
|
Pierre-Yves Chibon |
8fc633 |
"date": date,
|
|
Pierre-Yves Chibon |
8fc633 |
"date_created": "1477558752",
|
|
Pierre-Yves Chibon |
263695 |
"type": "pull-request",
|
|
Pierre-Yves Chibon |
8fc633 |
"description_mk": "pingou closed PR test#1 ",
|
|
Pierre-Yves Chibon |
8fc633 |
"id": 3,
|
|
Pierre-Yves Chibon |
a3362c |
"ref_id": "1",
|
|
Pierre-Yves Chibon |
a3362c |
"type": "closed",
|
|
Pierre-Yves Chibon |
8fc633 |
"user": {
|
|
Pierre-Yves Chibon |
8fc633 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
8fc633 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
8fc633 |
}
|
|
Pierre-Yves Chibon |
8fc633 |
},
|
|
Pierre-Yves Chibon |
8fc633 |
{
|
|
Pierre-Yves Chibon |
8fc633 |
"date": date,
|
|
Pierre-Yves Chibon |
8fc633 |
"date_created": "1477558752",
|
|
Pierre-Yves Chibon |
263695 |
"type": "pull-request",
|
|
Clement Verna |
6c4ede |
"description_mk": "pingou commented on PR test#1 ",
|
|
Pierre-Yves Chibon |
8fc633 |
"id": 4,
|
|
Pierre-Yves Chibon |
a3362c |
"ref_id": "1",
|
|
Pierre-Yves Chibon |
a3362c |
"type": "commented",
|
|
Pierre-Yves Chibon |
8fc633 |
"user": {
|
|
Pierre-Yves Chibon |
8fc633 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
8fc633 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
8fc633 |
}
|
|
Pierre-Yves Chibon |
8fc633 |
}
|
|
Pierre-Yves Chibon |
fa2aba |
],
|
|
Pierre-Yves Chibon |
fa2aba |
"date": date,
|
|
Pierre-Yves Chibon |
8fc633 |
}
|
|
Pierre-Yves Chibon |
8fc633 |
for idx, act in enumerate(data['activities']):
|
|
Pierre-Yves Chibon |
8fc633 |
act['date_created'] = '1477558752'
|
|
Pierre-Yves Chibon |
8fc633 |
data['activities'][idx] = act
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
self.assertEqual(data, exp)
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
d6ddc4 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
d6ddc4 |
def test_api_view_user_activity_date_1_activity(self, mockemail):
|
|
Pierre-Yves Chibon |
d6ddc4 |
""" Test the api_view_user_activity_date method of the flask user
|
|
Pierre-Yves Chibon |
d6ddc4 |
api when the user only did one action. """
|
|
Pierre-Yves Chibon |
d6ddc4 |
|
|
Pierre-Yves Chibon |
d6ddc4 |
tests.create_projects(self.session)
|
|
Farhaan Bukhsh |
940880 |
repo = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
d6ddc4 |
|
|
Pierre-Yves Chibon |
d6ddc4 |
now = datetime.datetime.utcnow()
|
|
Pierre-Yves Chibon |
d6ddc4 |
date = now.date().strftime('%Y-%m-%d')
|
|
Pierre-Yves Chibon |
d6ddc4 |
# Create a single commit log
|
|
Pierre-Yves Chibon |
d6ddc4 |
log = model.PagureLog(
|
|
Pierre-Yves Chibon |
d6ddc4 |
user_id=1,
|
|
Pierre-Yves Chibon |
d6ddc4 |
user_email='foo@bar.com',
|
|
Pierre-Yves Chibon |
d6ddc4 |
project_id=1,
|
|
Pierre-Yves Chibon |
d6ddc4 |
log_type='committed',
|
|
Pierre-Yves Chibon |
d6ddc4 |
ref_id='githash',
|
|
Pierre-Yves Chibon |
d6ddc4 |
date=now.date(),
|
|
Pierre-Yves Chibon |
d6ddc4 |
date_created=now
|
|
Pierre-Yves Chibon |
d6ddc4 |
)
|
|
Pierre-Yves Chibon |
d6ddc4 |
self.session.add(log)
|
|
Pierre-Yves Chibon |
d6ddc4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
d6ddc4 |
|
|
Pierre-Yves Chibon |
d6ddc4 |
# Retrieve the user's logs for today
|
|
Pierre-Yves Chibon |
d6ddc4 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
d6ddc4 |
'/api/0/user/pingou/activity/%s?grouped=1' % date)
|
|
Pierre-Yves Chibon |
d6ddc4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
d6ddc4 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
d6ddc4 |
exp = {
|
|
Pierre-Yves Chibon |
d6ddc4 |
"activities": [
|
|
Pierre-Yves Chibon |
d6ddc4 |
{
|
|
Pierre-Yves Chibon |
d6ddc4 |
"description_mk": "pingou committed on test#githash "
|
|
Pierre-Yves Chibon |
d6ddc4 |
}
|
|
Pierre-Yves Chibon |
d6ddc4 |
],
|
|
Pierre-Yves Chibon |
d6ddc4 |
"date": date,
|
|
Pierre-Yves Chibon |
d6ddc4 |
}
|
|
Pierre-Yves Chibon |
d6ddc4 |
self.assertEqual(data, exp)
|
|
Pierre-Yves Chibon |
d6ddc4 |
|
|
Pierre-Yves Chibon |
8fc633 |
|
|
Pierre-Yves Chibon |
8fc633 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|