|
Pierre-Yves Chibon |
62f012 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
"""
|
|
Pierre-Yves Chibon |
62f012 |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
Authors:
|
|
Pierre-Yves Chibon |
62f012 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
"""
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
62f012 |
import pkg_resources
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
import unittest
|
|
Pierre-Yves Chibon |
62f012 |
import shutil
|
|
Pierre-Yves Chibon |
62f012 |
import sys
|
|
Pierre-Yves Chibon |
62f012 |
import os
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
import json
|
|
Pierre-Yves Chibon |
62f012 |
from mock import patch
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
62f012 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
b130e5 |
import pagure.flask_app
|
|
Pierre-Yves Chibon |
fe5017 |
import pagure.lib
|
|
Pierre-Yves Chibon |
62f012 |
import tests
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Clement Verna |
109c4b |
class PagureFlaskApitests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Tests for flask API controller of pagure """
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
def test_api_version(self):
|
|
Pierre-Yves Chibon |
62f012 |
""" Test the api_version function. """
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
output = self.app.get('/api/0/version')
|
|
Pierre-Yves Chibon |
62f012 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
62f012 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
fe5017 |
self.assertEqual(data['version'], pagure.__api_version__)
|
|
Pierre-Yves Chibon |
62f012 |
self.assertEqual(data.keys(), ['version'])
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
dbea26 |
def test_api_project_tags(self):
|
|
Pierre-Yves Chibon |
dbea26 |
""" Test the api_project_tags function. """
|
|
Pierre-Yves Chibon |
dbea26 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
dbea26 |
|
|
Pierre-Yves Chibon |
dbea26 |
output = self.app.get('/api/0/foo/tags/')
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
dbea26 |
data = json.loads(output.data)
|
|
Aurélien Bompard |
f61bb3 |
self.assertEqual(set(data.keys()), set(['output', 'error']))
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(data['output'], 'notok')
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(data['error'], 'Project not found')
|
|
Pierre-Yves Chibon |
dbea26 |
|
|
Pierre-Yves Chibon |
dbea26 |
output = self.app.get('/api/0/test/tags/')
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
dbea26 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
226628 |
self.assertEqual(sorted(data.keys()), ['tags', 'total_tags'])
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(data['tags'], [])
|
|
Pierre-Yves Chibon |
226628 |
self.assertEqual(data['total_tags'], 0)
|
|
Pierre-Yves Chibon |
dbea26 |
|
|
Pierre-Yves Chibon |
dbea26 |
# Add an issue and tag it so that we can list them
|
|
Pierre-Yves Chibon |
fe5017 |
item = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
dbea26 |
id=1,
|
|
Pierre-Yves Chibon |
dbea26 |
uid='foobar',
|
|
Pierre-Yves Chibon |
dbea26 |
project_id=1,
|
|
Pierre-Yves Chibon |
dbea26 |
title='issue',
|
|
Pierre-Yves Chibon |
dbea26 |
content='a bug report',
|
|
Pierre-Yves Chibon |
dbea26 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
dbea26 |
)
|
|
Pierre-Yves Chibon |
dbea26 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
dbea26 |
self.session.commit()
|
|
Pierre-Yves Chibon |
a8f682 |
item = pagure.lib.model.TagColored(
|
|
Mark Reynolds |
403d8f |
tag='tag1', tag_color='DeepBlueSky', project_id=1,
|
|
Pierre-Yves Chibon |
dbea26 |
)
|
|
Pierre-Yves Chibon |
dbea26 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
dbea26 |
self.session.commit()
|
|
Pierre-Yves Chibon |
a8f682 |
item = pagure.lib.model.TagIssueColored(
|
|
Pierre-Yves Chibon |
dbea26 |
issue_uid='foobar',
|
|
Pierre-Yves Chibon |
a8f682 |
tag_id=item.id
|
|
Pierre-Yves Chibon |
dbea26 |
)
|
|
Pierre-Yves Chibon |
dbea26 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
dbea26 |
self.session.commit()
|
|
Pierre-Yves Chibon |
dbea26 |
|
|
Pierre-Yves Chibon |
dbea26 |
output = self.app.get('/api/0/test/tags/')
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
dbea26 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
226628 |
self.assertEqual(sorted(data.keys()), ['tags', 'total_tags'])
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(data['tags'], ['tag1'])
|
|
Pierre-Yves Chibon |
226628 |
self.assertEqual(data['total_tags'], 1)
|
|
Pierre-Yves Chibon |
dbea26 |
|
|
Pierre-Yves Chibon |
dbea26 |
output = self.app.get('/api/0/test/tags/?pattern=t')
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
dbea26 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
226628 |
self.assertEqual(sorted(data.keys()), ['tags', 'total_tags'])
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(data['tags'], ['tag1'])
|
|
Pierre-Yves Chibon |
226628 |
self.assertEqual(data['total_tags'], 1)
|
|
Pierre-Yves Chibon |
dbea26 |
|
|
Pierre-Yves Chibon |
dbea26 |
output = self.app.get('/api/0/test/tags/?pattern=p')
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
dbea26 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
226628 |
self.assertEqual(sorted(data.keys()), ['tags', 'total_tags'])
|
|
Pierre-Yves Chibon |
dbea26 |
self.assertEqual(data['tags'], [])
|
|
Pierre-Yves Chibon |
226628 |
self.assertEqual(data['total_tags'], 0)
|
|
Pierre-Yves Chibon |
dbea26 |
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|