2014-01-31 21:19:29 +00:00
|
|
|
import unittest
|
2014-02-06 19:40:36 +00:00
|
|
|
import json as py_json
|
2014-01-31 21:19:29 +00:00
|
|
|
|
2014-03-25 19:17:02 +00:00
|
|
|
from urllib import urlencode
|
|
|
|
from urlparse import urlparse, urlunparse, parse_qs
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
from endpoints.api import api_bp, api
|
2014-02-26 20:19:07 +00:00
|
|
|
from endpoints.webhooks import webhooks
|
2014-03-19 00:32:37 +00:00
|
|
|
from endpoints.trigger import BuildTrigger as BuildTriggerBase
|
2014-01-31 21:19:29 +00:00
|
|
|
from app import app
|
|
|
|
from initdb import setup_database_for_testing, finished_database_for_testing
|
2014-02-26 20:19:07 +00:00
|
|
|
from data import model, database
|
2014-01-31 21:19:29 +00:00
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
from endpoints.api.team import TeamMember, TeamMemberList, OrganizationTeam
|
|
|
|
from endpoints.api.tag import RepositoryTagImages, RepositoryTag
|
|
|
|
from endpoints.api.search import FindRepositories, EntitySearch
|
|
|
|
from endpoints.api.image import RepositoryImage, RepositoryImageList
|
|
|
|
from endpoints.api.build import RepositoryBuildStatus, RepositoryBuildLogs, RepositoryBuildList
|
|
|
|
from endpoints.api.robot import UserRobotList, OrgRobot, OrgRobotList, UserRobot
|
|
|
|
from endpoints.api.trigger import (BuildTriggerActivate, BuildTriggerSources, BuildTriggerSubdirs,
|
|
|
|
TriggerBuildList, ActivateBuildTrigger, BuildTrigger,
|
2014-04-03 03:33:58 +00:00
|
|
|
BuildTriggerList, BuildTriggerAnalyze)
|
2014-03-18 23:34:26 +00:00
|
|
|
from endpoints.api.webhook import Webhook, WebhookList
|
2014-03-25 00:57:02 +00:00
|
|
|
from endpoints.api.user import (PrivateRepositories, ConvertToOrganization, Signout, Signin, User,
|
|
|
|
UserAuthorizationList, UserAuthorization)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
from endpoints.api.repotoken import RepositoryToken, RepositoryTokenList
|
|
|
|
from endpoints.api.prototype import PermissionPrototype, PermissionPrototypeList
|
|
|
|
from endpoints.api.logs import UserLogs, OrgLogs
|
|
|
|
from endpoints.api.billing import (UserCard, UserPlan, ListPlans, OrganizationCard,
|
|
|
|
OrganizationPlan)
|
|
|
|
from endpoints.api.discovery import DiscoveryResource
|
|
|
|
from endpoints.api.organization import (OrganizationList, OrganizationMember,
|
|
|
|
OrgPrivateRepositories, OrgnaizationMemberList,
|
2014-03-20 19:46:13 +00:00
|
|
|
Organization, ApplicationInformation,
|
|
|
|
OrganizationApplications, OrganizationApplicationResource,
|
|
|
|
OrganizationApplicationResetClientSecret)
|
2014-03-18 23:34:26 +00:00
|
|
|
from endpoints.api.repository import RepositoryList, RepositoryVisibility, Repository
|
|
|
|
from endpoints.api.permission import (RepositoryUserPermission, RepositoryTeamPermission,
|
|
|
|
RepositoryTeamPermissionList, RepositoryUserPermissionList)
|
|
|
|
|
2014-03-19 22:21:58 +00:00
|
|
|
try:
|
|
|
|
app.register_blueprint(api_bp, url_prefix='/api')
|
|
|
|
except ValueError:
|
|
|
|
# This blueprint was already registered
|
|
|
|
pass
|
|
|
|
|
2014-02-26 20:19:07 +00:00
|
|
|
app.register_blueprint(webhooks, url_prefix='/webhooks')
|
2014-01-31 21:19:29 +00:00
|
|
|
|
|
|
|
NO_ACCESS_USER = 'freshuser'
|
|
|
|
READ_ACCESS_USER = 'reader'
|
|
|
|
ADMIN_ACCESS_USER = 'devtable'
|
2014-02-03 23:18:33 +00:00
|
|
|
PUBLIC_USER = 'public'
|
|
|
|
|
|
|
|
ORG_REPO = 'orgrepo'
|
|
|
|
|
2014-01-31 21:19:29 +00:00
|
|
|
ORGANIZATION = 'buynlarge'
|
|
|
|
|
2014-01-31 22:54:01 +00:00
|
|
|
NEW_USER_DETAILS = {
|
|
|
|
'username': 'bobby',
|
|
|
|
'password': 'password',
|
|
|
|
'email': 'bobby@tables.com',
|
|
|
|
}
|
|
|
|
|
2014-03-20 19:46:13 +00:00
|
|
|
FAKE_APPLICATION_CLIENT_ID = 'deadbeef'
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-03-25 19:17:02 +00:00
|
|
|
CSRF_TOKEN_KEY = '_csrf_token'
|
|
|
|
CSRF_TOKEN = '123csrfforme'
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-01-31 21:19:29 +00:00
|
|
|
class ApiTestCase(unittest.TestCase):
|
2014-03-25 19:17:02 +00:00
|
|
|
@staticmethod
|
|
|
|
def _add_csrf(without_csrf):
|
|
|
|
parts = urlparse(without_csrf)
|
|
|
|
query = parse_qs(parts[4])
|
|
|
|
query[CSRF_TOKEN_KEY] = CSRF_TOKEN
|
|
|
|
return urlunparse(list(parts[0:4]) + [urlencode(query)] + list(parts[5:]))
|
|
|
|
|
|
|
|
def url_for(self, resource_name, params={}):
|
|
|
|
url = api.url_for(resource_name, **params)
|
|
|
|
url = ApiTestCase._add_csrf(url)
|
|
|
|
return url
|
|
|
|
|
2014-01-31 21:19:29 +00:00
|
|
|
def setUp(self):
|
|
|
|
setup_database_for_testing(self)
|
|
|
|
self.app = app.test_client()
|
|
|
|
self.ctx = app.test_request_context()
|
|
|
|
self.ctx.__enter__()
|
2014-03-25 19:17:02 +00:00
|
|
|
self.setCsrfToken(CSRF_TOKEN)
|
2014-01-31 21:19:29 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
finished_database_for_testing(self)
|
|
|
|
self.ctx.__exit__(True, None, None)
|
|
|
|
|
2014-03-25 19:17:02 +00:00
|
|
|
def setCsrfToken(self, token):
|
|
|
|
with self.app.session_transaction() as sess:
|
|
|
|
sess[CSRF_TOKEN_KEY] = token
|
|
|
|
|
2014-03-19 00:32:37 +00:00
|
|
|
def getJsonResponse(self, resource_name, params={}, expected_code=200):
|
2014-03-18 23:34:26 +00:00
|
|
|
rv = self.app.get(api.url_for(resource_name, **params))
|
2014-03-19 00:32:37 +00:00
|
|
|
self.assertEquals(expected_code, rv.status_code)
|
2014-01-31 22:54:01 +00:00
|
|
|
data = rv.data
|
2014-02-06 19:40:36 +00:00
|
|
|
parsed = py_json.loads(data)
|
2014-01-31 22:54:01 +00:00
|
|
|
return parsed
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
def postResponse(self, resource_name, params={}, data={}, expected_code=200):
|
2014-03-25 19:17:02 +00:00
|
|
|
rv = self.app.post(self.url_for(resource_name, params),
|
2014-02-06 19:40:36 +00:00
|
|
|
data=py_json.dumps(data),
|
|
|
|
headers={"Content-Type": "application/json"})
|
2014-01-31 22:54:01 +00:00
|
|
|
self.assertEquals(rv.status_code, expected_code)
|
|
|
|
return rv.data
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
def getResponse(self, resource_name, params={}, expected_code=200):
|
|
|
|
rv = self.app.get(api.url_for(resource_name, **params))
|
2014-01-31 22:54:01 +00:00
|
|
|
self.assertEquals(rv.status_code, expected_code)
|
|
|
|
return rv.data
|
|
|
|
|
2014-03-26 23:42:29 +00:00
|
|
|
def putResponse(self, resource_name, params={}, data={}, expected_code=200):
|
|
|
|
rv = self.app.put(self.url_for(resource_name, params),
|
2014-02-28 05:12:09 +00:00
|
|
|
data=py_json.dumps(data),
|
|
|
|
headers={"Content-Type": "application/json"})
|
|
|
|
self.assertEquals(rv.status_code, expected_code)
|
|
|
|
return rv.data
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
def deleteResponse(self, resource_name, params={}, expected_code=204):
|
2014-03-25 19:17:02 +00:00
|
|
|
rv = self.app.delete(self.url_for(resource_name, params))
|
2014-01-31 23:54:31 +00:00
|
|
|
self.assertEquals(rv.status_code, expected_code)
|
|
|
|
return rv.data
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
def postJsonResponse(self, resource_name, params={}, data={},
|
2014-02-06 19:40:36 +00:00
|
|
|
expected_code=200):
|
2014-03-25 19:17:02 +00:00
|
|
|
rv = self.app.post(self.url_for(resource_name, params),
|
2014-02-06 19:40:36 +00:00
|
|
|
data=py_json.dumps(data),
|
|
|
|
headers={"Content-Type": "application/json"})
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
if rv.status_code != expected_code:
|
2014-03-18 23:34:26 +00:00
|
|
|
print 'Mismatch data for resource POST %s: %s' % (resource_name, rv.data)
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
self.assertEquals(rv.status_code, expected_code)
|
2014-01-31 21:19:29 +00:00
|
|
|
data = rv.data
|
2014-02-06 19:40:36 +00:00
|
|
|
parsed = py_json.loads(data)
|
2014-01-31 21:19:29 +00:00
|
|
|
return parsed
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
def putJsonResponse(self, resource_name, params={}, data={},
|
2014-02-06 19:40:36 +00:00
|
|
|
expected_code=200):
|
2014-03-25 19:17:02 +00:00
|
|
|
rv = self.app.put(self.url_for(resource_name, params),
|
2014-03-18 23:34:26 +00:00
|
|
|
data=py_json.dumps(data),
|
2014-02-06 19:40:36 +00:00
|
|
|
headers={"Content-Type": "application/json"})
|
2014-01-31 21:19:29 +00:00
|
|
|
|
2014-01-31 22:54:01 +00:00
|
|
|
if rv.status_code != expected_code:
|
2014-03-18 23:34:26 +00:00
|
|
|
print 'Mismatch data for resource PUT %s: %s' % (resource_name, rv.data)
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
self.assertEquals(rv.status_code, expected_code)
|
|
|
|
data = rv.data
|
2014-02-06 19:40:36 +00:00
|
|
|
parsed = py_json.loads(data)
|
2014-01-31 22:54:01 +00:00
|
|
|
return parsed
|
|
|
|
|
|
|
|
def login(self, username, password='password'):
|
2014-03-18 23:34:26 +00:00
|
|
|
return self.postJsonResponse(Signin, data=dict(username=username, password=password))
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-01-31 22:54:01 +00:00
|
|
|
|
2014-03-25 19:17:02 +00:00
|
|
|
class TestCSRFFailure(ApiTestCase):
|
|
|
|
def test_csrf_failure(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
|
|
|
|
|
|
|
# Make sure a simple post call succeeds.
|
|
|
|
self.putJsonResponse(User,
|
|
|
|
data=dict(password='newpasswordiscool'))
|
|
|
|
|
|
|
|
# Change the session's CSRF token.
|
|
|
|
self.setCsrfToken('someinvalidtoken')
|
|
|
|
|
|
|
|
# Verify that the call now fails.
|
|
|
|
self.putJsonResponse(User,
|
|
|
|
data=dict(password='newpasswordiscool'),
|
|
|
|
expected_code=403)
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-01-31 22:54:01 +00:00
|
|
|
|
2014-01-31 21:19:29 +00:00
|
|
|
class TestDiscovery(ApiTestCase):
|
|
|
|
def test_discovery(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(DiscoveryResource)
|
2014-03-19 00:32:37 +00:00
|
|
|
assert 'apis' in json
|
2014-01-31 21:19:29 +00:00
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-01-31 21:19:29 +00:00
|
|
|
class TestPlans(ApiTestCase):
|
|
|
|
def test_plans(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(ListPlans)
|
2014-01-31 21:19:29 +00:00
|
|
|
found = set([])
|
|
|
|
for method_info in json['plans']:
|
|
|
|
found.add(method_info['stripeId'])
|
|
|
|
|
|
|
|
assert 'free' in found
|
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-01-31 21:19:29 +00:00
|
|
|
class TestLoggedInUser(ApiTestCase):
|
|
|
|
def test_guest(self):
|
2014-03-19 00:32:37 +00:00
|
|
|
self.getJsonResponse(User, expected_code=401)
|
2014-01-31 21:19:29 +00:00
|
|
|
|
|
|
|
def test_user(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(User)
|
2014-01-31 21:19:29 +00:00
|
|
|
assert json['anonymous'] == False
|
|
|
|
assert json['username'] == READ_ACCESS_USER
|
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-03-06 23:36:52 +00:00
|
|
|
class TestGetUserPrivateAllowed(ApiTestCase):
|
2014-01-31 21:19:29 +00:00
|
|
|
def test_nonallowed(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(PrivateRepositories)
|
2014-01-31 21:19:29 +00:00
|
|
|
assert json['privateCount'] == 0
|
2014-03-06 23:36:52 +00:00
|
|
|
assert not json['privateAllowed']
|
2014-01-31 21:19:29 +00:00
|
|
|
|
|
|
|
def test_allowed(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(PrivateRepositories)
|
2014-01-31 21:19:29 +00:00
|
|
|
assert json['privateCount'] == 6
|
2014-03-06 23:36:52 +00:00
|
|
|
assert json['privateAllowed']
|
2014-01-31 21:19:29 +00:00
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-01-31 22:54:01 +00:00
|
|
|
class TestConvertToOrganization(ApiTestCase):
|
|
|
|
def test_sameadminuser(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(ConvertToOrganization,
|
2014-02-06 19:40:36 +00:00
|
|
|
data={'adminUser': READ_ACCESS_USER,
|
2014-03-19 00:32:37 +00:00
|
|
|
'adminPassword': 'password',
|
|
|
|
'plan': 'free'},
|
2014-01-31 22:54:01 +00:00
|
|
|
expected_code=400)
|
|
|
|
|
|
|
|
self.assertEqual('The admin user is not valid', json['message'])
|
|
|
|
|
|
|
|
def test_invalidadminuser(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(ConvertToOrganization,
|
2014-02-06 19:40:36 +00:00
|
|
|
data={'adminUser': 'unknownuser',
|
2014-03-19 00:32:37 +00:00
|
|
|
'adminPassword': 'password',
|
|
|
|
'plan': 'free'},
|
2014-01-31 22:54:01 +00:00
|
|
|
expected_code=400)
|
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
self.assertEqual('The admin user credentials are not valid',
|
|
|
|
json['message'])
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
def test_invalidadminpassword(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(ConvertToOrganization,
|
2014-02-06 19:40:36 +00:00
|
|
|
data={'adminUser': ADMIN_ACCESS_USER,
|
2014-03-19 00:32:37 +00:00
|
|
|
'adminPassword': 'invalidpass',
|
|
|
|
'plan': 'free'},
|
2014-01-31 22:54:01 +00:00
|
|
|
expected_code=400)
|
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
self.assertEqual('The admin user credentials are not valid',
|
|
|
|
json['message'])
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
def test_convert(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(ConvertToOrganization,
|
2014-01-31 22:54:01 +00:00
|
|
|
data={'adminUser': ADMIN_ACCESS_USER,
|
|
|
|
'adminPassword': 'password',
|
|
|
|
'plan': 'free'})
|
|
|
|
|
|
|
|
self.assertEqual(True, json['success'])
|
|
|
|
|
|
|
|
# Verify the organization exists.
|
|
|
|
organization = model.get_organization(READ_ACCESS_USER)
|
|
|
|
assert organization is not None
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
# Verify the admin user is the org's admin.
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Organization,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=READ_ACCESS_USER))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
self.assertEquals(READ_ACCESS_USER, json['name'])
|
|
|
|
self.assertEquals(True, json['is_admin'])
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestChangeUserDetails(ApiTestCase):
|
|
|
|
def test_changepassword(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(User,
|
2014-02-06 19:40:36 +00:00
|
|
|
data=dict(password='newpasswordiscool'))
|
2014-01-31 22:54:01 +00:00
|
|
|
self.login(READ_ACCESS_USER, password='newpasswordiscool')
|
|
|
|
|
|
|
|
def test_changeinvoiceemail(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.putJsonResponse(User,
|
2014-02-06 19:40:36 +00:00
|
|
|
data=dict(invoice_email=True))
|
2014-01-31 22:54:01 +00:00
|
|
|
self.assertEquals(True, json['invoice_email'])
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.putJsonResponse(User,
|
2014-02-06 19:40:36 +00:00
|
|
|
data=dict(invoice_email=False))
|
2014-01-31 22:54:01 +00:00
|
|
|
self.assertEquals(False, json['invoice_email'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestCreateNewUser(ApiTestCase):
|
|
|
|
def test_existingusername(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(User,
|
2014-01-31 22:54:01 +00:00
|
|
|
data=dict(username=READ_ACCESS_USER,
|
|
|
|
password='password',
|
|
|
|
email='test@example.com'),
|
|
|
|
expected_code=400)
|
|
|
|
|
|
|
|
self.assertEquals('The username already exists', json['message'])
|
2014-04-08 00:37:02 +00:00
|
|
|
|
|
|
|
def test_trycreatetooshort(self):
|
|
|
|
json = self.postJsonResponse(User,
|
|
|
|
data=dict(username='a',
|
|
|
|
password='password',
|
|
|
|
email='test@example.com'),
|
|
|
|
expected_code=400)
|
|
|
|
|
|
|
|
self.assertEquals('Invalid username a: Username must be between 4 and 30 characters in length', json['error_description'])
|
|
|
|
|
|
|
|
def test_trycreateregexmismatch(self):
|
|
|
|
json = self.postJsonResponse(User,
|
|
|
|
data=dict(username='auserName',
|
|
|
|
password='password',
|
|
|
|
email='test@example.com'),
|
|
|
|
expected_code=400)
|
|
|
|
|
|
|
|
self.assertEquals('Invalid username auserName: Username must match expression [a-z0-9_]+', json['error_description'])
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
def test_createuser(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
data = self.postResponse(User,
|
2014-01-31 22:54:01 +00:00
|
|
|
data=NEW_USER_DETAILS,
|
|
|
|
expected_code=201)
|
2014-03-19 00:32:37 +00:00
|
|
|
self.assertEquals('"Created"', data)
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestSignout(ApiTestCase):
|
|
|
|
def test_signout(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(User)
|
2014-01-31 22:54:01 +00:00
|
|
|
assert json['username'] == READ_ACCESS_USER
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
self.postResponse(Signout)
|
2014-01-31 22:54:01 +00:00
|
|
|
|
2014-03-19 00:32:37 +00:00
|
|
|
# Make sure we're now signed out.
|
|
|
|
self.getJsonResponse(User, expected_code=401)
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestGetMatchingEntities(ApiTestCase):
|
|
|
|
def test_notinorg(self):
|
|
|
|
self.login(NO_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(EntitySearch,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(prefix='o', namespace=ORGANIZATION,
|
2014-02-17 22:28:20 +00:00
|
|
|
includeTeams='true'))
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
names = set([r['name'] for r in json['results']])
|
|
|
|
assert 'outsideorg' in names
|
|
|
|
assert not 'owners' in names
|
|
|
|
|
|
|
|
def test_inorg(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(EntitySearch,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(prefix='o', namespace=ORGANIZATION,
|
2014-02-17 22:28:20 +00:00
|
|
|
includeTeams='true'))
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
names = set([r['name'] for r in json['results']])
|
|
|
|
assert 'outsideorg' in names
|
|
|
|
assert 'owners' in names
|
|
|
|
|
|
|
|
|
|
|
|
class TestCreateOrganization(ApiTestCase):
|
|
|
|
def test_existinguser(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(OrganizationList,
|
2014-03-19 00:32:37 +00:00
|
|
|
data=dict(name=ADMIN_ACCESS_USER, email='testorg@example.com'),
|
2014-01-31 22:54:01 +00:00
|
|
|
expected_code=400)
|
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
self.assertEquals('A user or organization with this name already exists',
|
|
|
|
json['message'])
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
def test_existingorg(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(OrganizationList,
|
2014-03-19 00:32:37 +00:00
|
|
|
data=dict(name=ORGANIZATION, email='testorg@example.com'),
|
2014-01-31 22:54:01 +00:00
|
|
|
expected_code=400)
|
2014-03-19 00:32:37 +00:00
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
self.assertEquals('A user or organization with this name already exists',
|
|
|
|
json['message'])
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
def test_createorg(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
data = self.postResponse(OrganizationList,
|
2014-02-06 19:40:36 +00:00
|
|
|
data=dict(name='neworg',
|
2014-03-19 00:32:37 +00:00
|
|
|
email='testorg@example.com'),
|
2014-01-31 22:54:01 +00:00
|
|
|
expected_code=201)
|
|
|
|
|
2014-03-19 00:32:37 +00:00
|
|
|
self.assertEquals('"Created"', data)
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
# Ensure the org was created.
|
|
|
|
organization = model.get_organization('neworg')
|
|
|
|
assert organization is not None
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
# Verify the admin user is the org's admin.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Organization,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname='neworg'))
|
2014-01-31 23:54:31 +00:00
|
|
|
self.assertEquals('neworg', json['name'])
|
|
|
|
self.assertEquals(True, json['is_admin'])
|
|
|
|
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
class TestGetOrganization(ApiTestCase):
|
|
|
|
def test_unknownorg(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
self.getResponse(Organization, params=dict(orgname='notvalid'),
|
2014-01-31 22:54:01 +00:00
|
|
|
expected_code=403)
|
|
|
|
|
|
|
|
def test_cannotaccess(self):
|
|
|
|
self.login(NO_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
self.getResponse(Organization, params=dict(orgname=ORGANIZATION),
|
2014-01-31 22:54:01 +00:00
|
|
|
expected_code=403)
|
|
|
|
|
|
|
|
def test_getorganization(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Organization,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
self.assertEquals(ORGANIZATION, json['name'])
|
|
|
|
self.assertEquals(False, json['is_admin'])
|
|
|
|
|
|
|
|
def test_getorganization_asadmin(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Organization,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
2014-01-31 22:54:01 +00:00
|
|
|
|
|
|
|
self.assertEquals(ORGANIZATION, json['name'])
|
|
|
|
self.assertEquals(True, json['is_admin'])
|
|
|
|
|
2014-01-31 23:54:31 +00:00
|
|
|
|
2014-01-31 22:54:01 +00:00
|
|
|
class TestChangeOrganizationDetails(ApiTestCase):
|
|
|
|
def test_changeinvoiceemail(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.putJsonResponse(Organization,
|
2014-01-31 22:54:01 +00:00
|
|
|
params=dict(orgname=ORGANIZATION),
|
|
|
|
data=dict(invoice_email=True))
|
|
|
|
|
|
|
|
self.assertEquals(True, json['invoice_email'])
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.putJsonResponse(Organization,
|
2014-01-31 22:54:01 +00:00
|
|
|
params=dict(orgname=ORGANIZATION),
|
|
|
|
data=dict(invoice_email=False))
|
|
|
|
self.assertEquals(False, json['invoice_email'])
|
|
|
|
|
|
|
|
|
|
|
|
def test_changemail(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.putJsonResponse(Organization,
|
2014-01-31 22:54:01 +00:00
|
|
|
params=dict(orgname=ORGANIZATION),
|
|
|
|
data=dict(email='newemail@example.com'))
|
|
|
|
|
|
|
|
self.assertEquals('newemail@example.com', json['email'])
|
|
|
|
|
|
|
|
|
2014-01-31 23:54:31 +00:00
|
|
|
class TestGetOrganizationPrototypes(ApiTestCase):
|
|
|
|
def test_getprototypes(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(PermissionPrototypeList,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
assert len(json['prototypes']) > 0
|
|
|
|
|
|
|
|
|
|
|
|
class TestCreateOrganizationPrototypes(ApiTestCase):
|
|
|
|
def test_invaliduser(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(PermissionPrototypeList,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION),
|
|
|
|
data=dict(activating_user={'name': 'unknownuser'},
|
|
|
|
role='read',
|
|
|
|
delegate={'kind': 'team', 'name': 'owners'}),
|
|
|
|
expected_code=400)
|
|
|
|
|
|
|
|
self.assertEquals('Unknown activating user', json['message'])
|
|
|
|
|
|
|
|
|
|
|
|
def test_missingdelegate(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-19 00:32:37 +00:00
|
|
|
self.postJsonResponse(PermissionPrototypeList,
|
|
|
|
params=dict(orgname=ORGANIZATION),
|
|
|
|
data=dict(role='read'),
|
|
|
|
expected_code=400)
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_createprototype(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(PermissionPrototypeList,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION),
|
2014-02-06 19:40:36 +00:00
|
|
|
data=dict(role='read',
|
|
|
|
delegate={'kind': 'team',
|
|
|
|
'name': 'readers'}))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
self.assertEquals('read', json['role'])
|
|
|
|
pid = json['id']
|
|
|
|
|
|
|
|
# Verify the prototype exists.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(PermissionPrototypeList,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
ids = set([p['id'] for p in json['prototypes']])
|
|
|
|
assert pid in ids
|
|
|
|
|
|
|
|
|
|
|
|
class TestDeleteOrganizationPrototypes(ApiTestCase):
|
|
|
|
def test_deleteprototype(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Get the existing prototypes
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(PermissionPrototypeList,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
ids = [p['id'] for p in json['prototypes']]
|
|
|
|
pid = ids[0]
|
|
|
|
|
|
|
|
# Delete a prototype.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(PermissionPrototype,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION, prototypeid=pid))
|
|
|
|
|
|
|
|
# Verify the prototype no longer exists.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(PermissionPrototypeList,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
newids = [p['id'] for p in json['prototypes']]
|
|
|
|
assert not pid in newids
|
|
|
|
|
|
|
|
|
|
|
|
class TestUpdateOrganizationPrototypes(ApiTestCase):
|
|
|
|
def test_updateprototype(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Get the existing prototypes
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(PermissionPrototypeList,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
ids = [p['id'] for p in json['prototypes']]
|
|
|
|
pid = ids[0]
|
|
|
|
|
|
|
|
# Update a prototype.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.putJsonResponse(PermissionPrototype,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION,
|
|
|
|
prototypeid=pid), data=dict(role='admin'))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
self.assertEquals('admin', json['role'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetOrganiaztionMembers(ApiTestCase):
|
|
|
|
def test_getmembers(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(OrgnaizationMemberList,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
assert ADMIN_ACCESS_USER in json['members']
|
|
|
|
assert READ_ACCESS_USER in json['members']
|
|
|
|
assert not NO_ACCESS_USER in json['members']
|
|
|
|
|
|
|
|
def test_getspecificmember(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(OrganizationMember,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION,
|
|
|
|
membername=ADMIN_ACCESS_USER))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
self.assertEquals(ADMIN_ACCESS_USER, json['member']['name'])
|
|
|
|
self.assertEquals('user', json['member']['kind'])
|
|
|
|
|
|
|
|
assert 'owners' in json['member']['teams']
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetOrganizationPrivateAllowed(ApiTestCase):
|
|
|
|
def test_existingorg(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(OrgPrivateRepositories,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
self.assertEquals(True, json['privateAllowed'])
|
|
|
|
assert not 'reposAllowed' in json
|
|
|
|
|
|
|
|
|
|
|
|
def test_neworg(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
data = self.postResponse(OrganizationList,
|
2014-02-06 19:40:36 +00:00
|
|
|
data=dict(name='neworg',
|
|
|
|
email='test@example.com'),
|
2014-01-31 23:54:31 +00:00
|
|
|
expected_code=201)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(OrgPrivateRepositories,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname='neworg'))
|
|
|
|
|
|
|
|
self.assertEquals(False, json['privateAllowed'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestUpdateOrganizationTeam(ApiTestCase):
|
|
|
|
def test_updateexisting(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-19 00:32:37 +00:00
|
|
|
data = self.putJsonResponse(OrganizationTeam,
|
|
|
|
params=dict(orgname=ORGANIZATION,
|
|
|
|
teamname='readers'),
|
|
|
|
data=dict(description='My cool team',
|
|
|
|
role='creator'))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
self.assertEquals('My cool team', data['description'])
|
|
|
|
self.assertEquals('creator', data['role'])
|
|
|
|
|
|
|
|
def test_attemptchangeroleonowners(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-19 00:32:37 +00:00
|
|
|
self.putJsonResponse(OrganizationTeam,
|
|
|
|
params=dict(orgname=ORGANIZATION, teamname='owners'),
|
|
|
|
data=dict(role = 'creator'),
|
|
|
|
expected_code=400)
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
def test_createnewteam(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
data = self.putJsonResponse(OrganizationTeam,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION,
|
|
|
|
teamname='newteam'),
|
|
|
|
data=dict(description='My cool team',
|
2014-03-19 00:32:37 +00:00
|
|
|
role='member'))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
self.assertEquals('My cool team', data['description'])
|
|
|
|
self.assertEquals('member', data['role'])
|
|
|
|
|
|
|
|
# Verify the team was created.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Organization,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
2014-01-31 23:54:31 +00:00
|
|
|
assert 'newteam' in json['teams']
|
|
|
|
|
|
|
|
|
|
|
|
class TestDeleteOrganizationTeam(ApiTestCase):
|
|
|
|
def test_deleteteam(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(OrganizationTeam,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION, teamname='readers'))
|
|
|
|
|
|
|
|
# Make sure the team was deleted
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Organization,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
2014-01-31 23:54:31 +00:00
|
|
|
assert not 'readers' in json['teams']
|
|
|
|
|
|
|
|
def test_attemptdeleteowners(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(OrganizationTeam,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION, teamname='owners'),
|
|
|
|
expected_code=400)
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetOrganizationTeamMembers(ApiTestCase):
|
|
|
|
def test_invalidteam(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
self.getResponse(TeamMemberList,
|
2014-01-31 23:54:31 +00:00
|
|
|
params=dict(orgname=ORGANIZATION, teamname='notvalid'),
|
|
|
|
expected_code=404)
|
|
|
|
|
|
|
|
def test_getmembers(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(TeamMemberList,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION,
|
|
|
|
teamname='readers'))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
assert READ_ACCESS_USER in json['members']
|
|
|
|
|
|
|
|
|
|
|
|
class TestUpdateOrganizationTeamMember(ApiTestCase):
|
|
|
|
def test_addmember(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-19 00:32:37 +00:00
|
|
|
self.putJsonResponse(TeamMember,
|
|
|
|
params=dict(orgname=ORGANIZATION, teamname='readers',
|
|
|
|
membername=NO_ACCESS_USER))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Verify the user was added to the team.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(TeamMemberList,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION,
|
|
|
|
teamname='readers'))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
assert NO_ACCESS_USER in json['members']
|
|
|
|
|
|
|
|
|
|
|
|
class TestDeleteOrganizationTeamMember(ApiTestCase):
|
|
|
|
def test_deletemember(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(TeamMember,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION, teamname='readers',
|
|
|
|
membername=READ_ACCESS_USER))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Verify the user was removed from the team.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(TeamMemberList,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(orgname=ORGANIZATION,
|
|
|
|
teamname='readers'))
|
2014-01-31 23:54:31 +00:00
|
|
|
|
|
|
|
assert not READ_ACCESS_USER in json['members']
|
|
|
|
|
|
|
|
|
2014-02-01 00:45:44 +00:00
|
|
|
class TestCreateRepo(ApiTestCase):
|
|
|
|
def test_duplicaterepo(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(RepositoryList,
|
2014-02-06 19:40:36 +00:00
|
|
|
data=dict(repository='simple',
|
2014-03-19 00:32:37 +00:00
|
|
|
visibility='public',
|
|
|
|
description=''),
|
2014-02-01 00:45:44 +00:00
|
|
|
expected_code=400)
|
|
|
|
|
|
|
|
self.assertEquals('Repository already exists', json['message'])
|
|
|
|
|
|
|
|
|
|
|
|
def test_createrepo(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(RepositoryList,
|
2014-02-06 19:40:36 +00:00
|
|
|
data=dict(repository='newrepo',
|
|
|
|
visibility='public',
|
2014-03-19 00:32:37 +00:00
|
|
|
description=''),
|
|
|
|
expected_code=201)
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
self.assertEquals(ADMIN_ACCESS_USER, json['namespace'])
|
|
|
|
self.assertEquals('newrepo', json['name'])
|
|
|
|
|
|
|
|
|
|
|
|
def test_createrepo_underorg(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(RepositoryList,
|
2014-02-01 00:45:44 +00:00
|
|
|
data=dict(namespace=ORGANIZATION,
|
|
|
|
repository='newrepo',
|
|
|
|
visibility='private',
|
2014-03-19 00:32:37 +00:00
|
|
|
description=''),
|
|
|
|
expected_code=201)
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
self.assertEquals(ORGANIZATION, json['namespace'])
|
|
|
|
self.assertEquals('newrepo', json['name'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestFindRepos(ApiTestCase):
|
|
|
|
def test_findrepos_asguest(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(FindRepositories, params=dict(query='p'))
|
2014-02-16 23:59:24 +00:00
|
|
|
self.assertEquals(len(json['repositories']), 1)
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
self.assertEquals(json['repositories'][0]['namespace'], 'public')
|
|
|
|
self.assertEquals(json['repositories'][0]['name'], 'publicrepo')
|
|
|
|
|
|
|
|
def test_findrepos_asuser(self):
|
|
|
|
self.login(NO_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(FindRepositories, params=dict(query='p'))
|
2014-02-16 23:59:24 +00:00
|
|
|
self.assertEquals(len(json['repositories']), 1)
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
self.assertEquals(json['repositories'][0]['namespace'], 'public')
|
|
|
|
self.assertEquals(json['repositories'][0]['name'], 'publicrepo')
|
|
|
|
|
|
|
|
def test_findrepos_orgmember(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(FindRepositories, params=dict(query='p'))
|
2014-02-16 23:59:24 +00:00
|
|
|
self.assertGreater(len(json['repositories']), 1)
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestListRepos(ApiTestCase):
|
2014-02-19 00:15:14 +00:00
|
|
|
def test_listrepos_asguest(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryList, params=dict(public=True))
|
2014-02-16 23:59:24 +00:00
|
|
|
self.assertEquals(len(json['repositories']), 1)
|
2014-02-01 00:45:44 +00:00
|
|
|
|
2014-02-19 00:15:14 +00:00
|
|
|
def test_listrepos_orgmember(self):
|
2014-02-01 00:45:44 +00:00
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryList, params=dict(public=True))
|
2014-02-16 23:59:24 +00:00
|
|
|
self.assertGreater(len(json['repositories']), 1)
|
2014-02-01 00:45:44 +00:00
|
|
|
|
2014-02-19 00:15:14 +00:00
|
|
|
def test_listrepos_filter(self):
|
2014-02-01 00:45:44 +00:00
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryList,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(namespace=ORGANIZATION,
|
|
|
|
public=False))
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
for repo in json['repositories']:
|
|
|
|
self.assertEquals(ORGANIZATION, repo['namespace'])
|
|
|
|
|
2014-02-19 00:15:14 +00:00
|
|
|
def test_listrepos_limit(self):
|
2014-02-01 00:45:44 +00:00
|
|
|
self.login(READ_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryList, params=dict(limit=2))
|
2014-02-01 00:45:44 +00:00
|
|
|
|
2014-02-16 23:59:24 +00:00
|
|
|
self.assertEquals(len(json['repositories']), 2)
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestUpdateRepo(ApiTestCase):
|
2014-02-06 19:40:36 +00:00
|
|
|
SIMPLE_REPO = ADMIN_ACCESS_USER + '/simple'
|
|
|
|
def test_updatedescription(self):
|
2014-02-01 00:45:44 +00:00
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(Repository,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.SIMPLE_REPO),
|
2014-02-01 00:45:44 +00:00
|
|
|
data=dict(description='Some cool repo'))
|
|
|
|
|
|
|
|
# Verify the repo description was updated.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Repository,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.SIMPLE_REPO))
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
self.assertEquals('Some cool repo', json['description'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestChangeRepoVisibility(ApiTestCase):
|
2014-02-06 19:40:36 +00:00
|
|
|
SIMPLE_REPO = ADMIN_ACCESS_USER + '/simple'
|
|
|
|
def test_changevisibility(self):
|
2014-02-01 00:45:44 +00:00
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Make public.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.postJsonResponse(RepositoryVisibility,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.SIMPLE_REPO),
|
2014-02-01 00:45:44 +00:00
|
|
|
data=dict(visibility='public'))
|
|
|
|
|
|
|
|
# Verify the visibility.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Repository,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.SIMPLE_REPO))
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
self.assertEquals(True, json['is_public'])
|
|
|
|
|
|
|
|
# Make private.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.postJsonResponse(RepositoryVisibility,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.SIMPLE_REPO),
|
2014-02-01 00:45:44 +00:00
|
|
|
data=dict(visibility='private'))
|
|
|
|
|
|
|
|
# Verify the visibility.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Repository,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.SIMPLE_REPO))
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
self.assertEquals(False, json['is_public'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestDeleteRepository(ApiTestCase):
|
2014-02-06 19:40:36 +00:00
|
|
|
SIMPLE_REPO = ADMIN_ACCESS_USER + '/simple'
|
|
|
|
def test_deleterepo(self):
|
2014-02-01 00:45:44 +00:00
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(Repository,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.SIMPLE_REPO))
|
2014-02-01 00:45:44 +00:00
|
|
|
|
|
|
|
# Verify the repo was deleted.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.getResponse(Repository,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.SIMPLE_REPO),
|
2014-02-01 00:45:44 +00:00
|
|
|
expected_code=404)
|
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-02-03 23:18:33 +00:00
|
|
|
class TestGetRepository(ApiTestCase):
|
2014-02-06 19:40:36 +00:00
|
|
|
PUBLIC_REPO = PUBLIC_USER + '/publicrepo'
|
2014-03-11 17:38:44 +00:00
|
|
|
|
|
|
|
def test_getrepo_badnames(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-11 18:42:53 +00:00
|
|
|
bad_names = ['logs', 'build', 'tokens', 'foo.bar', 'foo-bar', 'foo_bar']
|
2014-03-11 17:38:44 +00:00
|
|
|
|
|
|
|
# For each bad name, create the repo.
|
|
|
|
for bad_name in bad_names:
|
2014-03-19 19:39:44 +00:00
|
|
|
json = self.postJsonResponse(RepositoryList, expected_code=201,
|
|
|
|
data=dict(repository=bad_name, visibility='public',
|
2014-03-11 17:38:44 +00:00
|
|
|
description=''))
|
|
|
|
|
|
|
|
# Make sure we can retrieve its information.
|
2014-03-19 19:39:44 +00:00
|
|
|
json = self.getJsonResponse(Repository,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/' + bad_name))
|
2014-03-11 17:38:44 +00:00
|
|
|
|
|
|
|
self.assertEquals(ADMIN_ACCESS_USER, json['namespace'])
|
|
|
|
self.assertEquals(bad_name, json['name'])
|
|
|
|
self.assertEquals(True, json['is_public'])
|
|
|
|
|
|
|
|
|
2014-02-03 23:18:33 +00:00
|
|
|
def test_getrepo_public_asguest(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Repository,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.PUBLIC_REPO))
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
self.assertEquals(PUBLIC_USER, json['namespace'])
|
|
|
|
self.assertEquals('publicrepo', json['name'])
|
|
|
|
|
|
|
|
self.assertEquals(True, json['is_public'])
|
|
|
|
self.assertEquals(False, json['is_organization'])
|
|
|
|
self.assertEquals(False, json['is_building'])
|
|
|
|
|
|
|
|
self.assertEquals(False, json['can_write'])
|
|
|
|
self.assertEquals(False, json['can_admin'])
|
|
|
|
|
|
|
|
assert 'latest' in json['tags']
|
|
|
|
|
|
|
|
def test_getrepo_public_asowner(self):
|
|
|
|
self.login(PUBLIC_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Repository,
|
2014-02-06 19:40:36 +00:00
|
|
|
params=dict(repository=self.PUBLIC_REPO))
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
self.assertEquals(False, json['is_organization'])
|
|
|
|
self.assertEquals(True, json['can_write'])
|
|
|
|
self.assertEquals(True, json['can_admin'])
|
|
|
|
|
|
|
|
def test_getrepo_building(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Repository,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/building'))
|
|
|
|
|
|
|
|
self.assertEquals(True, json['can_write'])
|
|
|
|
self.assertEquals(True, json['can_admin'])
|
|
|
|
self.assertEquals(True, json['is_building'])
|
|
|
|
self.assertEquals(False, json['is_organization'])
|
|
|
|
|
|
|
|
def test_getrepo_org_asnonmember(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
self.getResponse(Repository,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ORGANIZATION + '/' + ORG_REPO),
|
2014-03-19 17:57:36 +00:00
|
|
|
expected_code=401)
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
def test_getrepo_org_asreader(self):
|
|
|
|
self.login(READ_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Repository,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ORGANIZATION + '/' + ORG_REPO))
|
|
|
|
|
|
|
|
self.assertEquals(ORGANIZATION, json['namespace'])
|
|
|
|
self.assertEquals(ORG_REPO, json['name'])
|
|
|
|
|
|
|
|
self.assertEquals(False, json['can_write'])
|
|
|
|
self.assertEquals(False, json['can_admin'])
|
|
|
|
|
|
|
|
self.assertEquals(True, json['is_organization'])
|
|
|
|
|
|
|
|
def test_getrepo_org_asadmin(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Repository,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ORGANIZATION + '/' + ORG_REPO))
|
|
|
|
|
|
|
|
self.assertEquals(True, json['can_write'])
|
|
|
|
self.assertEquals(True, json['can_admin'])
|
|
|
|
|
|
|
|
self.assertEquals(True, json['is_organization'])
|
|
|
|
|
|
|
|
|
2014-02-26 20:19:07 +00:00
|
|
|
class TestRepoBuilds(ApiTestCase):
|
2014-02-03 23:18:33 +00:00
|
|
|
def test_getrepo_nobuilds(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryBuildList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
|
|
|
|
|
|
|
assert len(json['builds']) == 0
|
|
|
|
|
|
|
|
def test_getrepobuilds(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryBuildList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/building'))
|
|
|
|
|
|
|
|
assert len(json['builds']) > 0
|
|
|
|
build = json['builds'][0]
|
|
|
|
|
|
|
|
assert 'id' in build
|
|
|
|
assert 'status' in build
|
|
|
|
|
2014-02-26 20:19:07 +00:00
|
|
|
# Check the status endpoint.
|
2014-03-18 23:34:26 +00:00
|
|
|
status_json = self.getJsonResponse(RepositoryBuildStatus,
|
2014-02-26 20:19:07 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/building', build_uuid=build['id']))
|
2014-02-03 23:18:33 +00:00
|
|
|
|
2014-02-26 20:19:07 +00:00
|
|
|
self.assertEquals(status_json, build)
|
|
|
|
|
|
|
|
# Check the logs.
|
2014-03-18 23:34:26 +00:00
|
|
|
logs_json = self.getJsonResponse(RepositoryBuildLogs,
|
2014-02-26 20:19:07 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/building', build_uuid=build['id']))
|
|
|
|
|
|
|
|
assert 'logs' in logs_json
|
2014-02-03 23:18:33 +00:00
|
|
|
|
2014-02-25 23:22:02 +00:00
|
|
|
class TestRequestRepoBuild(ApiTestCase):
|
2014-02-03 23:18:33 +00:00
|
|
|
def test_requestrepobuild(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-04-02 01:49:06 +00:00
|
|
|
# Ensure we are not yet building.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryBuildList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
|
|
|
|
|
|
|
assert len(json['builds']) == 0
|
|
|
|
|
|
|
|
# Request a (fake) build.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.postResponse(RepositoryBuildList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
2014-02-25 23:22:02 +00:00
|
|
|
data=dict(file_id='foobarbaz'),
|
2014-02-03 23:18:33 +00:00
|
|
|
expected_code=201)
|
|
|
|
|
|
|
|
# Check for the build.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryBuildList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/building'))
|
|
|
|
|
|
|
|
assert len(json['builds']) > 0
|
|
|
|
|
2014-04-02 01:49:06 +00:00
|
|
|
def test_requestrepobuild_with_robot(self):
|
2014-03-27 22:33:13 +00:00
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-04-02 01:49:06 +00:00
|
|
|
# Ensure we are not yet building.
|
2014-03-27 22:33:13 +00:00
|
|
|
json = self.getJsonResponse(RepositoryBuildList,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
|
|
|
|
|
|
|
assert len(json['builds']) == 0
|
|
|
|
|
|
|
|
# Request a (fake) build.
|
2014-04-02 01:49:06 +00:00
|
|
|
pull_robot = ADMIN_ACCESS_USER + '+dtrobot'
|
2014-03-27 22:33:13 +00:00
|
|
|
self.postResponse(RepositoryBuildList,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
2014-04-02 01:49:06 +00:00
|
|
|
data=dict(file_id='foobarbaz', pull_robot=pull_robot),
|
2014-03-27 22:33:13 +00:00
|
|
|
expected_code=201)
|
|
|
|
|
|
|
|
# Check for the build.
|
|
|
|
json = self.getJsonResponse(RepositoryBuildList,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/building'))
|
|
|
|
|
|
|
|
assert len(json['builds']) > 0
|
2014-04-02 01:49:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_requestrepobuild_with_invalid_robot(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Request a (fake) build.
|
|
|
|
pull_robot = ADMIN_ACCESS_USER + '+invalidrobot'
|
|
|
|
self.postResponse(RepositoryBuildList,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
|
|
|
data=dict(file_id='foobarbaz', pull_robot=pull_robot),
|
|
|
|
expected_code=404)
|
|
|
|
|
|
|
|
def test_requestrepobuild_with_unauthorized_robot(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Request a (fake) build.
|
|
|
|
pull_robot = 'freshuser+anotherrobot'
|
|
|
|
self.postResponse(RepositoryBuildList,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
|
|
|
data=dict(file_id='foobarbaz', pull_robot=pull_robot),
|
|
|
|
expected_code=403)
|
|
|
|
|
2014-03-27 22:33:13 +00:00
|
|
|
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
class TestWebhooks(ApiTestCase):
|
|
|
|
def test_webhooks(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Add a webhook.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(WebhookList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
2014-03-19 00:32:37 +00:00
|
|
|
data=dict(url='http://example.com'),
|
|
|
|
expected_code=201)
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
self.assertEquals('http://example.com', json['parameters']['url'])
|
|
|
|
wid = json['public_id']
|
|
|
|
|
|
|
|
# Get the webhook.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(Webhook,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', public_id=wid))
|
|
|
|
|
|
|
|
self.assertEquals(wid, json['public_id'])
|
|
|
|
self.assertEquals('http://example.com', json['parameters']['url'])
|
|
|
|
|
|
|
|
# Verify the webhook is listed.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(WebhookList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
|
|
|
|
|
|
|
ids = [w['public_id'] for w in json['webhooks']]
|
|
|
|
assert wid in ids
|
|
|
|
|
|
|
|
# Delete the webhook.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(Webhook,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', public_id=wid),
|
|
|
|
expected_code=204)
|
|
|
|
|
|
|
|
# Verify the webhook is gone.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.getResponse(Webhook,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', public_id=wid),
|
|
|
|
expected_code=404)
|
|
|
|
|
|
|
|
|
|
|
|
class TestListAndGetImage(ApiTestCase):
|
|
|
|
def test_listandgetimages(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryImageList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
|
|
|
|
|
|
|
assert len(json['images']) > 0
|
|
|
|
for image in json['images']:
|
|
|
|
assert 'id' in image
|
|
|
|
assert 'tags' in image
|
|
|
|
assert 'created' in image
|
|
|
|
assert 'comment' in image
|
|
|
|
assert 'command' in image
|
|
|
|
assert 'ancestors' in image
|
|
|
|
assert 'dbid' in image
|
|
|
|
assert 'size' in image
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
ijson = self.getJsonResponse(RepositoryImage,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple',
|
|
|
|
image_id=image['id']))
|
|
|
|
|
|
|
|
self.assertEquals(image['id'], ijson['id'])
|
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-02-03 23:18:33 +00:00
|
|
|
class TestGetImageChanges(ApiTestCase):
|
|
|
|
def test_getimagechanges(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Find an image to check.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryImageList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
|
|
|
|
|
|
|
image_id = json['images'][0]['id']
|
|
|
|
|
|
|
|
# Lookup the image's changes.
|
|
|
|
# TODO: Fix me once we can get fake changes into the test data
|
2014-03-18 23:34:26 +00:00
|
|
|
#self.getJsonResponse(RepositoryImageChanges,
|
2014-02-03 23:18:33 +00:00
|
|
|
# params=dict(repository=ADMIN_ACCESS_USER + '/simple',
|
|
|
|
# image_id=image_id))
|
|
|
|
|
|
|
|
|
|
|
|
class TestListAndDeleteTag(ApiTestCase):
|
2014-02-28 05:12:09 +00:00
|
|
|
def test_listdeletecreateandmovetag(self):
|
2014-02-03 23:18:33 +00:00
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# List the images for prod.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryTagImages,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='prod'))
|
|
|
|
|
|
|
|
prod_images = json['images']
|
|
|
|
assert len(prod_images) > 0
|
|
|
|
|
|
|
|
# List the images for staging.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryTagImages,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='staging'))
|
|
|
|
|
|
|
|
staging_images = json['images']
|
|
|
|
assert len(prod_images) == len(staging_images) + 1
|
|
|
|
|
|
|
|
# Delete prod.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(RepositoryTag,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='prod'),
|
|
|
|
expected_code=204)
|
|
|
|
|
|
|
|
# Make sure the tag is gone.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.getResponse(RepositoryTagImages,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='prod'),
|
|
|
|
expected_code=404)
|
|
|
|
|
|
|
|
# Make the sure the staging images are still there.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryTagImages,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='staging'))
|
|
|
|
|
|
|
|
self.assertEquals(staging_images, json['images'])
|
|
|
|
|
2014-02-28 05:12:09 +00:00
|
|
|
# Add a new tag to the staging image.
|
2014-03-26 23:42:29 +00:00
|
|
|
self.putResponse(RepositoryTag,
|
2014-02-28 05:12:09 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='sometag'),
|
|
|
|
data=dict(image=staging_images[0]['id']),
|
|
|
|
expected_code=201)
|
|
|
|
|
|
|
|
# Make sure the tag is present.
|
2014-03-26 23:42:29 +00:00
|
|
|
json = self.getJsonResponse(RepositoryTagImages,
|
2014-02-28 05:12:09 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='sometag'))
|
|
|
|
|
|
|
|
sometag_images = json['images']
|
|
|
|
self.assertEquals(sometag_images, staging_images)
|
|
|
|
|
|
|
|
# Move the tag.
|
2014-03-26 23:42:29 +00:00
|
|
|
self.putResponse(RepositoryTag,
|
2014-02-28 05:12:09 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='sometag'),
|
|
|
|
data=dict(image=staging_images[-1]['id']),
|
|
|
|
expected_code=201)
|
|
|
|
|
|
|
|
# Make sure the tag has moved.
|
2014-03-26 23:42:29 +00:00
|
|
|
json = self.getJsonResponse(RepositoryTagImages,
|
2014-02-28 05:12:09 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='sometag'))
|
|
|
|
|
|
|
|
sometag_new_images = json['images']
|
|
|
|
self.assertEquals(1, len(sometag_new_images))
|
|
|
|
self.assertEquals(staging_images[-1], sometag_new_images[0])
|
|
|
|
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
def test_deletesubtag(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# List the images for prod.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryTagImages,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='prod'))
|
|
|
|
|
|
|
|
prod_images = json['images']
|
|
|
|
assert len(prod_images) > 0
|
|
|
|
|
|
|
|
# Delete staging.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(RepositoryTag,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='staging'),
|
|
|
|
expected_code=204)
|
|
|
|
|
|
|
|
# Make sure the prod images are still around.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryTagImages,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/complex', tag='prod'))
|
|
|
|
|
|
|
|
self.assertEquals(prod_images, json['images'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestRepoPermissions(ApiTestCase):
|
|
|
|
def listUserPermissions(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
return self.getJsonResponse(RepositoryUserPermissionList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))['permissions']
|
|
|
|
|
|
|
|
def listTeamPermissions(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
return self.getJsonResponse(RepositoryTeamPermissionList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ORGANIZATION + '/' + ORG_REPO))['permissions']
|
|
|
|
|
|
|
|
def test_userpermissions(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# The repo should start with just the admin as a user perm.
|
|
|
|
permissions = self.listUserPermissions()
|
|
|
|
|
|
|
|
self.assertEquals(1, len(permissions))
|
|
|
|
assert ADMIN_ACCESS_USER in permissions
|
|
|
|
self.assertEquals('admin', permissions[ADMIN_ACCESS_USER]['role'])
|
|
|
|
|
|
|
|
# Add another user.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(RepositoryUserPermission,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', username=NO_ACCESS_USER),
|
|
|
|
data=dict(role='read'))
|
|
|
|
|
|
|
|
# Verify the user is present.
|
|
|
|
permissions = self.listUserPermissions()
|
|
|
|
|
|
|
|
self.assertEquals(2, len(permissions))
|
|
|
|
assert NO_ACCESS_USER in permissions
|
|
|
|
self.assertEquals('read', permissions[NO_ACCESS_USER]['role'])
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryUserPermission,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', username=NO_ACCESS_USER))
|
|
|
|
self.assertEquals('read', json['role'])
|
|
|
|
|
|
|
|
# Change the user's permissions.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(RepositoryUserPermission,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', username=NO_ACCESS_USER),
|
|
|
|
data=dict(role='admin'))
|
|
|
|
|
|
|
|
# Verify.
|
|
|
|
permissions = self.listUserPermissions()
|
|
|
|
|
|
|
|
self.assertEquals(2, len(permissions))
|
|
|
|
assert NO_ACCESS_USER in permissions
|
|
|
|
self.assertEquals('admin', permissions[NO_ACCESS_USER]['role'])
|
|
|
|
|
|
|
|
# Delete the user's permission.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(RepositoryUserPermission,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', username=NO_ACCESS_USER))
|
|
|
|
|
|
|
|
# Verify.
|
|
|
|
permissions = self.listUserPermissions()
|
|
|
|
|
|
|
|
self.assertEquals(1, len(permissions))
|
|
|
|
assert not NO_ACCESS_USER in permissions
|
|
|
|
|
|
|
|
|
|
|
|
def test_teampermissions(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# The repo should start with just the readers as a team perm.
|
|
|
|
permissions = self.listTeamPermissions()
|
|
|
|
|
|
|
|
self.assertEquals(1, len(permissions))
|
|
|
|
assert 'readers' in permissions
|
|
|
|
self.assertEquals('read', permissions['readers']['role'])
|
|
|
|
|
|
|
|
# Add another team.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(RepositoryTeamPermission,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ORGANIZATION + '/' + ORG_REPO, teamname='owners'),
|
|
|
|
data=dict(role='write'))
|
|
|
|
|
|
|
|
# Verify the team is present.
|
|
|
|
permissions = self.listTeamPermissions()
|
|
|
|
|
|
|
|
self.assertEquals(2, len(permissions))
|
|
|
|
assert 'owners' in permissions
|
|
|
|
self.assertEquals('write', permissions['owners']['role'])
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryTeamPermission,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ORGANIZATION + '/' + ORG_REPO, teamname='owners'))
|
|
|
|
self.assertEquals('write', json['role'])
|
|
|
|
|
|
|
|
# Change the team's permissions.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(RepositoryTeamPermission,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ORGANIZATION + '/' + ORG_REPO, teamname='owners'),
|
|
|
|
data=dict(role='admin'))
|
|
|
|
|
|
|
|
# Verify.
|
|
|
|
permissions = self.listTeamPermissions()
|
|
|
|
|
|
|
|
self.assertEquals(2, len(permissions))
|
|
|
|
assert 'owners' in permissions
|
|
|
|
self.assertEquals('admin', permissions['owners']['role'])
|
|
|
|
|
|
|
|
# Delete the team's permission.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(RepositoryTeamPermission,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ORGANIZATION + '/' + ORG_REPO, teamname='owners'))
|
|
|
|
|
|
|
|
# Verify.
|
|
|
|
permissions = self.listTeamPermissions()
|
|
|
|
|
|
|
|
self.assertEquals(1, len(permissions))
|
|
|
|
assert not 'owners' in permissions
|
|
|
|
|
2014-02-06 19:40:36 +00:00
|
|
|
|
2014-02-03 23:18:33 +00:00
|
|
|
class TestApiTokens(ApiTestCase):
|
|
|
|
def listTokens(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
return self.getJsonResponse(RepositoryTokenList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))['tokens']
|
|
|
|
|
|
|
|
def test_tokens(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Create a new token.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(RepositoryTokenList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
|
|
|
data=dict(role='read', friendlyName='mytoken'),
|
|
|
|
expected_code=201)
|
|
|
|
|
|
|
|
self.assertEquals('mytoken', json['friendlyName'])
|
|
|
|
self.assertEquals('read', json['role'])
|
|
|
|
token_code = json['code']
|
|
|
|
|
|
|
|
# Verify.
|
|
|
|
tokens = self.listTokens()
|
|
|
|
assert token_code in tokens
|
|
|
|
self.assertEquals('mytoken', tokens[token_code]['friendlyName'])
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryToken,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', code=token_code))
|
|
|
|
self.assertEquals(tokens[token_code], json)
|
|
|
|
|
|
|
|
# Change the token's permission.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(RepositoryToken,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', code=token_code),
|
|
|
|
data=dict(role='write'))
|
|
|
|
|
|
|
|
# Verify.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(RepositoryToken,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', code=token_code))
|
|
|
|
self.assertEquals('write', json['role'])
|
|
|
|
|
|
|
|
# Delete the token.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(RepositoryToken,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', code=token_code))
|
|
|
|
|
|
|
|
# Verify.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.getResponse(RepositoryToken,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', code=token_code),
|
|
|
|
expected_code=404)
|
|
|
|
|
|
|
|
|
|
|
|
class TestUserCard(ApiTestCase):
|
|
|
|
def test_getusercard(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(UserCard)
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
self.assertEquals('4242', json['card']['last4'])
|
|
|
|
self.assertEquals('Visa', json['card']['type'])
|
|
|
|
|
|
|
|
def test_setusercard_error(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.postJsonResponse(UserCard,
|
2014-02-03 23:18:33 +00:00
|
|
|
data=dict(token='sometoken'),
|
|
|
|
expected_code=402)
|
|
|
|
assert 'carderror' in json
|
|
|
|
|
|
|
|
|
|
|
|
class TestOrgCard(ApiTestCase):
|
|
|
|
def test_getorgcard(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(OrganizationCard,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
self.assertEquals('4242', json['card']['last4'])
|
|
|
|
self.assertEquals('Visa', json['card']['type'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestUserSubscription(ApiTestCase):
|
|
|
|
def getSubscription(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
return self.getJsonResponse(UserPlan)
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
def test_updateplan(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Change the plan.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(UserPlan,
|
2014-02-03 23:18:33 +00:00
|
|
|
data=dict(plan='free'))
|
|
|
|
|
|
|
|
# Verify
|
|
|
|
sub = self.getSubscription()
|
|
|
|
self.assertEquals('free', sub['plan'])
|
|
|
|
|
|
|
|
# Change the plan.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(UserPlan,
|
2014-02-03 23:18:33 +00:00
|
|
|
data=dict(plan='bus-large'))
|
|
|
|
|
|
|
|
# Verify
|
|
|
|
sub = self.getSubscription()
|
|
|
|
self.assertEquals('bus-large', sub['plan'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestOrgSubscription(ApiTestCase):
|
|
|
|
def getSubscription(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
return self.getJsonResponse(OrganizationPlan, params=dict(orgname=ORGANIZATION))
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
def test_updateplan(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Change the plan.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(OrganizationPlan,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(orgname=ORGANIZATION),
|
|
|
|
data=dict(plan='free'))
|
|
|
|
|
|
|
|
# Verify
|
|
|
|
sub = self.getSubscription()
|
|
|
|
self.assertEquals('free', sub['plan'])
|
|
|
|
|
|
|
|
# Change the plan.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.putJsonResponse(OrganizationPlan,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(orgname=ORGANIZATION),
|
|
|
|
data=dict(plan='bus-large'))
|
|
|
|
|
|
|
|
# Verify
|
|
|
|
sub = self.getSubscription()
|
|
|
|
self.assertEquals('bus-large', sub['plan'])
|
|
|
|
|
|
|
|
|
|
|
|
class TestUserRobots(ApiTestCase):
|
|
|
|
def getRobotNames(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
return [r['name'] for r in self.getJsonResponse(UserRobotList)['robots']]
|
2014-02-03 23:18:33 +00:00
|
|
|
|
|
|
|
def test_robots(self):
|
|
|
|
self.login(NO_ACCESS_USER)
|
|
|
|
|
|
|
|
# Create a robot.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.putJsonResponse(UserRobot,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(robot_shortname='bender'),
|
|
|
|
expected_code=201)
|
|
|
|
|
|
|
|
self.assertEquals(NO_ACCESS_USER + '+bender', json['name'])
|
|
|
|
|
|
|
|
# Verify.
|
|
|
|
robots = self.getRobotNames()
|
|
|
|
assert NO_ACCESS_USER + '+bender' in robots
|
|
|
|
|
|
|
|
# Delete the robot.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(UserRobot,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(robot_shortname='bender'))
|
|
|
|
|
|
|
|
# Verify.
|
|
|
|
robots = self.getRobotNames()
|
|
|
|
assert not NO_ACCESS_USER + '+bender' in robots
|
|
|
|
|
|
|
|
|
|
|
|
class TestOrgRobots(ApiTestCase):
|
|
|
|
def getRobotNames(self):
|
2014-03-18 23:34:26 +00:00
|
|
|
return [r['name'] for r in self.getJsonResponse(OrgRobotList,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(orgname=ORGANIZATION))['robots']]
|
|
|
|
|
|
|
|
def test_robots(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Create a robot.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.putJsonResponse(OrgRobot,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(orgname=ORGANIZATION, robot_shortname='bender'),
|
|
|
|
expected_code=201)
|
|
|
|
|
|
|
|
self.assertEquals(ORGANIZATION + '+bender', json['name'])
|
|
|
|
|
|
|
|
# Verify.
|
|
|
|
robots = self.getRobotNames()
|
|
|
|
assert ORGANIZATION + '+bender' in robots
|
|
|
|
|
|
|
|
# Delete the robot.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(OrgRobot,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(orgname=ORGANIZATION, robot_shortname='bender'))
|
|
|
|
|
|
|
|
# Verify.
|
|
|
|
robots = self.getRobotNames()
|
|
|
|
assert not ORGANIZATION + '+bender' in robots
|
|
|
|
|
|
|
|
|
|
|
|
class TestLogs(ApiTestCase):
|
|
|
|
def test_user_logs(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(UserLogs)
|
2014-02-03 23:18:33 +00:00
|
|
|
assert 'logs' in json
|
|
|
|
assert 'start_time' in json
|
|
|
|
assert 'end_time' in json
|
|
|
|
|
|
|
|
def test_org_logs(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(OrgLogs, params=dict(orgname=ORGANIZATION))
|
2014-02-03 23:18:33 +00:00
|
|
|
assert 'logs' in json
|
|
|
|
assert 'start_time' in json
|
|
|
|
assert 'end_time' in json
|
|
|
|
|
|
|
|
def test_performer(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(OrgLogs, params=dict(orgname=ORGANIZATION))
|
2014-02-03 23:18:33 +00:00
|
|
|
all_logs = json['logs']
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(OrgLogs,
|
2014-02-03 23:18:33 +00:00
|
|
|
params=dict(performer=READ_ACCESS_USER, orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
assert len(json['logs']) < len(all_logs)
|
|
|
|
for log in json['logs']:
|
|
|
|
self.assertEquals(READ_ACCESS_USER, log['performer']['name'])
|
2014-02-01 00:45:44 +00:00
|
|
|
|
2014-02-26 20:19:07 +00:00
|
|
|
|
2014-03-20 19:46:13 +00:00
|
|
|
class TestApplicationInformation(ApiTestCase):
|
|
|
|
def test_get_info(self):
|
|
|
|
json = self.getJsonResponse(ApplicationInformation, params=dict(client_id=FAKE_APPLICATION_CLIENT_ID))
|
|
|
|
assert 'name' in json
|
|
|
|
assert 'uri' in json
|
|
|
|
assert 'organization' in json
|
|
|
|
|
|
|
|
def test_get_invalid_info(self):
|
|
|
|
self.getJsonResponse(ApplicationInformation, params=dict(client_id='invalid-code'),
|
|
|
|
expected_code=404)
|
|
|
|
|
|
|
|
|
|
|
|
class TestOrganizationApplications(ApiTestCase):
|
|
|
|
def test_list_create_applications(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
json = self.getJsonResponse(OrganizationApplications, params=dict(orgname=ORGANIZATION))
|
|
|
|
|
|
|
|
self.assertEquals(2, len(json['applications']))
|
|
|
|
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, json['applications'][0]['client_id'])
|
|
|
|
|
|
|
|
# Add a new application.
|
|
|
|
json = self.postJsonResponse(OrganizationApplications, params=dict(orgname=ORGANIZATION),
|
|
|
|
data=dict(name="Some cool app", description="foo"))
|
|
|
|
|
|
|
|
self.assertEquals("Some cool app", json['name'])
|
|
|
|
self.assertEquals("foo", json['description'])
|
|
|
|
|
|
|
|
# Retrieve the apps list again
|
|
|
|
list_json = self.getJsonResponse(OrganizationApplications, params=dict(orgname=ORGANIZATION))
|
|
|
|
self.assertEquals(3, len(list_json['applications']))
|
|
|
|
self.assertEquals(json, list_json['applications'][2])
|
|
|
|
|
|
|
|
|
|
|
|
class TestOrganizationApplicationResource(ApiTestCase):
|
|
|
|
def test_get_edit_delete_application(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Retrieve the application.
|
|
|
|
json = self.getJsonResponse(OrganizationApplicationResource,
|
|
|
|
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
|
|
|
|
|
|
|
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, json['client_id'])
|
|
|
|
|
|
|
|
# Edit the application.
|
|
|
|
edit_json = self.putJsonResponse(OrganizationApplicationResource,
|
|
|
|
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID),
|
|
|
|
data=dict(name="Some App", description="foo", application_uri="bar",
|
|
|
|
redirect_uri="baz", gravatar_email="meh"))
|
|
|
|
|
|
|
|
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, edit_json['client_id'])
|
|
|
|
self.assertEquals("Some App", edit_json['name'])
|
|
|
|
self.assertEquals("foo", edit_json['description'])
|
|
|
|
self.assertEquals("bar", edit_json['application_uri'])
|
|
|
|
self.assertEquals("baz", edit_json['redirect_uri'])
|
|
|
|
self.assertEquals("meh", edit_json['gravatar_email'])
|
|
|
|
|
|
|
|
# Retrieve the application again.
|
|
|
|
json = self.getJsonResponse(OrganizationApplicationResource,
|
|
|
|
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
|
|
|
|
|
|
|
self.assertEquals(json, edit_json)
|
|
|
|
|
|
|
|
# Delete the application.
|
|
|
|
self.deleteResponse(OrganizationApplicationResource,
|
|
|
|
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
|
|
|
|
|
|
|
# Make sure the application is gone.
|
|
|
|
self.getJsonResponse(OrganizationApplicationResource,
|
|
|
|
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID),
|
|
|
|
expected_code=404)
|
|
|
|
|
|
|
|
|
|
|
|
class TestOrganizationApplicationResetClientSecret(ApiTestCase):
|
|
|
|
def test_reset_client_secret(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Retrieve the application.
|
|
|
|
json = self.getJsonResponse(OrganizationApplicationResource,
|
|
|
|
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
|
|
|
|
|
|
|
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, json['client_id'])
|
|
|
|
|
|
|
|
# Reset the client secret.
|
|
|
|
reset_json = self.postJsonResponse(OrganizationApplicationResetClientSecret,
|
|
|
|
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
|
|
|
|
|
|
|
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, reset_json['client_id'])
|
|
|
|
self.assertNotEquals(reset_json['client_secret'], json['client_secret'])
|
|
|
|
|
|
|
|
# Verify it was changed in the DB.
|
|
|
|
json = self.getJsonResponse(OrganizationApplicationResource,
|
|
|
|
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
|
|
|
self.assertEquals(reset_json['client_secret'], json['client_secret'])
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-19 00:32:37 +00:00
|
|
|
class FakeBuildTrigger(BuildTriggerBase):
|
2014-02-26 20:19:07 +00:00
|
|
|
@classmethod
|
|
|
|
def service_name(cls):
|
|
|
|
return 'fakeservice'
|
|
|
|
|
|
|
|
def list_build_sources(self, auth_token):
|
|
|
|
return [{'first': 'source'}, {'second': auth_token}]
|
|
|
|
|
|
|
|
def list_build_subdirs(self, auth_token, config):
|
|
|
|
return [auth_token, 'foo', 'bar', config['somevalue']]
|
|
|
|
|
|
|
|
def handle_trigger_request(self, request, auth_token, config):
|
|
|
|
return ('foo', ['bar'], 'build-name', 'subdir')
|
|
|
|
|
|
|
|
def is_active(self, config):
|
|
|
|
return 'active' in config and config['active']
|
|
|
|
|
|
|
|
def activate(self, trigger_uuid, standard_webhook_url, auth_token, config):
|
|
|
|
config['active'] = True
|
|
|
|
return config
|
|
|
|
|
|
|
|
def deactivate(self, auth_token, config):
|
|
|
|
config['active'] = False
|
|
|
|
return config
|
|
|
|
|
|
|
|
def manual_start(self, auth_token, config):
|
|
|
|
return ('foo', ['bar'], 'build-name', 'subdir')
|
|
|
|
|
2014-04-03 03:33:58 +00:00
|
|
|
def dockerfile_url(self, auth_token, config):
|
|
|
|
return 'http://some/url'
|
|
|
|
|
|
|
|
def load_dockerfile_contents(self, auth_token, config):
|
|
|
|
if not 'dockerfile' in config:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return config['dockerfile']
|
|
|
|
|
2014-02-26 20:19:07 +00:00
|
|
|
|
|
|
|
class TestBuildTriggers(ApiTestCase):
|
|
|
|
def test_list_build_triggers(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
# Check a repo with no known triggers.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(BuildTriggerList, params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
2014-02-26 20:19:07 +00:00
|
|
|
self.assertEquals(0, len(json['triggers']))
|
|
|
|
|
|
|
|
# Check a repo with one known trigger.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(BuildTriggerList, params=dict(repository=ADMIN_ACCESS_USER + '/building'))
|
2014-02-26 20:19:07 +00:00
|
|
|
self.assertEquals(1, len(json['triggers']))
|
|
|
|
|
|
|
|
trigger = json['triggers'][0]
|
|
|
|
|
|
|
|
assert 'id' in trigger
|
|
|
|
assert 'is_active' in trigger
|
|
|
|
assert 'config' in trigger
|
|
|
|
assert 'service' in trigger
|
|
|
|
|
|
|
|
# Verify the get trigger method.
|
2014-03-18 23:34:26 +00:00
|
|
|
trigger_json = self.getJsonResponse(BuildTrigger, params=dict(repository=ADMIN_ACCESS_USER + '/building',
|
2014-02-26 20:19:07 +00:00
|
|
|
trigger_uuid=trigger['id']))
|
|
|
|
|
|
|
|
self.assertEquals(trigger, trigger_json)
|
|
|
|
|
|
|
|
# Check the recent builds for the trigger.
|
2014-03-18 23:34:26 +00:00
|
|
|
builds_json = self.getJsonResponse(TriggerBuildList, params=dict(repository=ADMIN_ACCESS_USER + '/building',
|
2014-02-26 20:19:07 +00:00
|
|
|
trigger_uuid=trigger['id']))
|
|
|
|
|
|
|
|
assert 'builds' in builds_json
|
|
|
|
|
|
|
|
def test_delete_build_trigger(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(BuildTriggerList, params=dict(repository=ADMIN_ACCESS_USER + '/building'))
|
2014-02-26 20:19:07 +00:00
|
|
|
self.assertEquals(1, len(json['triggers']))
|
|
|
|
trigger = json['triggers'][0]
|
|
|
|
|
|
|
|
# Delete the trigger.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.deleteResponse(BuildTrigger, params=dict(repository=ADMIN_ACCESS_USER + '/building',
|
2014-02-26 20:19:07 +00:00
|
|
|
trigger_uuid=trigger['id']))
|
|
|
|
|
|
|
|
# Verify it was deleted.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(BuildTriggerList, params=dict(repository=ADMIN_ACCESS_USER + '/building'))
|
2014-02-26 20:19:07 +00:00
|
|
|
self.assertEquals(0, len(json['triggers']))
|
|
|
|
|
|
|
|
|
2014-04-03 03:33:58 +00:00
|
|
|
def test_analyze_fake_trigger(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
database.BuildTriggerService.create(name='fakeservice')
|
|
|
|
|
|
|
|
# Add a new fake trigger.
|
|
|
|
repo = model.get_repository(ADMIN_ACCESS_USER, 'simple')
|
|
|
|
user = model.get_user(ADMIN_ACCESS_USER)
|
|
|
|
trigger = model.create_build_trigger(repo, 'fakeservice', 'sometoken', user)
|
|
|
|
|
|
|
|
# Analyze the trigger's dockerfile: First, no dockerfile.
|
|
|
|
trigger_config = {}
|
|
|
|
analyze_json = self.postJsonResponse(BuildTriggerAnalyze,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config})
|
|
|
|
|
|
|
|
self.assertEquals('error', analyze_json['status'])
|
|
|
|
self.assertEquals('Could not read the Dockerfile for the trigger', analyze_json['message'])
|
|
|
|
|
|
|
|
# Analyze the trigger's dockerfile: Second, missing FROM in dockerfile.
|
|
|
|
trigger_config = {'dockerfile': 'MAINTAINER me'}
|
|
|
|
analyze_json = self.postJsonResponse(BuildTriggerAnalyze,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config})
|
|
|
|
|
|
|
|
self.assertEquals('warning', analyze_json['status'])
|
|
|
|
self.assertEquals('No FROM line found in the Dockerfile', analyze_json['message'])
|
|
|
|
|
|
|
|
# Analyze the trigger's dockerfile: Third, dockerfile with public repo.
|
|
|
|
trigger_config = {'dockerfile': 'FROM somerepo'}
|
|
|
|
analyze_json = self.postJsonResponse(BuildTriggerAnalyze,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config})
|
|
|
|
|
|
|
|
self.assertEquals('publicbase', analyze_json['status'])
|
|
|
|
|
|
|
|
# Analyze the trigger's dockerfile: Fourth, dockerfile with private repo with an invalid path.
|
|
|
|
trigger_config = {'dockerfile': 'FROM localhost:5000/somepath'}
|
|
|
|
analyze_json = self.postJsonResponse(BuildTriggerAnalyze,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config})
|
|
|
|
|
|
|
|
self.assertEquals('warning', analyze_json['status'])
|
|
|
|
self.assertEquals('"localhost:5000/somepath" is not a valid Quay repository path', analyze_json['message'])
|
|
|
|
|
|
|
|
# Analyze the trigger's dockerfile: Fifth, dockerfile with private repo that does not exist.
|
|
|
|
trigger_config = {'dockerfile': 'FROM localhost:5000/nothere/randomrepo'}
|
|
|
|
analyze_json = self.postJsonResponse(BuildTriggerAnalyze,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config})
|
|
|
|
|
|
|
|
self.assertEquals('error', analyze_json['status'])
|
|
|
|
self.assertEquals('Repository "localhost:5000/nothere/randomrepo" was not found', analyze_json['message'])
|
|
|
|
|
|
|
|
# Analyze the trigger's dockerfile: Sixth, dockerfile with private repo that the user cannot see.
|
|
|
|
trigger_config = {'dockerfile': 'FROM localhost:5000/randomuser/randomrepo'}
|
|
|
|
analyze_json = self.postJsonResponse(BuildTriggerAnalyze,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config})
|
|
|
|
|
|
|
|
self.assertEquals('error', analyze_json['status'])
|
|
|
|
self.assertEquals('Repository "localhost:5000/randomuser/randomrepo" was not found', analyze_json['message'])
|
|
|
|
|
|
|
|
# Analyze the trigger's dockerfile: Seventh, dockerfile with private repo that the user see.
|
|
|
|
trigger_config = {'dockerfile': 'FROM localhost:5000/devtable/complex'}
|
|
|
|
analyze_json = self.postJsonResponse(BuildTriggerAnalyze,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config})
|
|
|
|
|
|
|
|
self.assertEquals('analyzed', analyze_json['status'])
|
|
|
|
self.assertEquals('devtable', analyze_json['namespace'])
|
|
|
|
self.assertEquals('complex', analyze_json['name'])
|
|
|
|
self.assertEquals(False, analyze_json['is_public'])
|
|
|
|
self.assertEquals(ADMIN_ACCESS_USER + '+dtrobot', analyze_json['robots'][0]['name'])
|
|
|
|
|
|
|
|
|
2014-02-26 20:19:07 +00:00
|
|
|
def test_fake_trigger(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
database.BuildTriggerService.create(name='fakeservice')
|
|
|
|
|
|
|
|
# Add a new fake trigger.
|
|
|
|
repo = model.get_repository(ADMIN_ACCESS_USER, 'simple')
|
|
|
|
user = model.get_user(ADMIN_ACCESS_USER)
|
|
|
|
trigger = model.create_build_trigger(repo, 'fakeservice', 'sometoken', user)
|
|
|
|
|
|
|
|
# Verify the trigger.
|
2014-03-18 23:34:26 +00:00
|
|
|
json = self.getJsonResponse(BuildTriggerList, params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
2014-02-26 20:19:07 +00:00
|
|
|
self.assertEquals(1, len(json['triggers']))
|
|
|
|
self.assertEquals(trigger.uuid, json['triggers'][0]['id'])
|
|
|
|
self.assertEquals(trigger.service.name, json['triggers'][0]['service'])
|
|
|
|
self.assertEquals(False, json['triggers'][0]['is_active'])
|
|
|
|
|
|
|
|
# List the trigger's sources.
|
2014-03-18 23:34:26 +00:00
|
|
|
source_json = self.getJsonResponse(BuildTriggerSources, params=dict(repository=ADMIN_ACCESS_USER + '/simple',
|
2014-02-26 20:19:07 +00:00
|
|
|
trigger_uuid=trigger.uuid))
|
|
|
|
self.assertEquals([{'first': 'source'}, {'second': 'sometoken'}], source_json['sources'])
|
|
|
|
|
|
|
|
# List the trigger's subdirs.
|
2014-03-18 23:34:26 +00:00
|
|
|
subdir_json = self.postJsonResponse(BuildTriggerSubdirs,
|
2014-02-26 20:19:07 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'somevalue': 'meh'})
|
|
|
|
|
|
|
|
self.assertEquals({'status': 'success', 'subdir': ['sometoken', 'foo', 'bar', 'meh']}, subdir_json)
|
|
|
|
|
|
|
|
# Activate the trigger.
|
|
|
|
trigger_config = {}
|
2014-03-18 23:34:26 +00:00
|
|
|
activate_json = self.postJsonResponse(BuildTriggerActivate,
|
2014-02-26 20:19:07 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
2014-03-27 22:33:13 +00:00
|
|
|
data={'config': trigger_config})
|
2014-02-26 20:19:07 +00:00
|
|
|
|
|
|
|
self.assertEquals(True, activate_json['is_active'])
|
|
|
|
|
|
|
|
# Make sure the trigger has a write token.
|
|
|
|
trigger = model.get_build_trigger(ADMIN_ACCESS_USER, 'simple', trigger.uuid)
|
|
|
|
self.assertNotEquals(None, trigger.write_token)
|
|
|
|
self.assertEquals(True, py_json.loads(trigger.config)['active'])
|
|
|
|
|
|
|
|
# Make sure we cannot activate again.
|
2014-03-18 23:34:26 +00:00
|
|
|
self.postResponse(BuildTriggerActivate,
|
2014-02-26 20:19:07 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
2014-03-27 22:33:13 +00:00
|
|
|
data={'config': trigger_config},
|
2014-02-26 20:19:07 +00:00
|
|
|
expected_code=400)
|
|
|
|
|
|
|
|
# Start a manual build.
|
2014-03-18 23:34:26 +00:00
|
|
|
start_json = self.postJsonResponse(ActivateBuildTrigger,
|
2014-02-26 20:19:07 +00:00
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
expected_code=201)
|
|
|
|
|
|
|
|
assert 'id' in start_json
|
|
|
|
self.assertEquals("build-name", start_json['display_name'])
|
|
|
|
self.assertEquals(['bar'], start_json['job_config']['docker_tags'])
|
|
|
|
|
2014-03-25 00:57:02 +00:00
|
|
|
|
2014-03-27 22:33:13 +00:00
|
|
|
def test_invalid_robot_account(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
database.BuildTriggerService.create(name='fakeservice')
|
|
|
|
|
|
|
|
# Add a new fake trigger.
|
|
|
|
repo = model.get_repository(ADMIN_ACCESS_USER, 'simple')
|
|
|
|
user = model.get_user(ADMIN_ACCESS_USER)
|
|
|
|
trigger = model.create_build_trigger(repo, 'fakeservice', 'sometoken', user)
|
|
|
|
|
|
|
|
# Try to activate it with an invalid robot account.
|
|
|
|
trigger_config = {}
|
|
|
|
activate_json = self.postJsonResponse(BuildTriggerActivate,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config, 'pull_robot': 'someinvalidrobot'},
|
|
|
|
expected_code=404)
|
|
|
|
|
|
|
|
def test_unauthorized_robot_account(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
database.BuildTriggerService.create(name='fakeservice')
|
|
|
|
|
|
|
|
# Add a new fake trigger.
|
|
|
|
repo = model.get_repository(ADMIN_ACCESS_USER, 'simple')
|
|
|
|
user = model.get_user(ADMIN_ACCESS_USER)
|
|
|
|
trigger = model.create_build_trigger(repo, 'fakeservice', 'sometoken', user)
|
|
|
|
|
|
|
|
# Try to activate it with a robot account in the wrong namespace.
|
|
|
|
trigger_config = {}
|
|
|
|
activate_json = self.postJsonResponse(BuildTriggerActivate,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config, 'pull_robot': 'freshuser+anotherrobot'},
|
|
|
|
expected_code=403)
|
|
|
|
|
|
|
|
def test_robot_account(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
database.BuildTriggerService.create(name='fakeservice')
|
|
|
|
|
|
|
|
# Add a new fake trigger.
|
|
|
|
repo = model.get_repository(ADMIN_ACCESS_USER, 'simple')
|
|
|
|
user = model.get_user(ADMIN_ACCESS_USER)
|
|
|
|
trigger = model.create_build_trigger(repo, 'fakeservice', 'sometoken', user)
|
|
|
|
|
|
|
|
# Try to activate it with a robot account.
|
|
|
|
trigger_config = {}
|
|
|
|
activate_json = self.postJsonResponse(BuildTriggerActivate,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
data={'config': trigger_config, 'pull_robot': ADMIN_ACCESS_USER + '+dtrobot'})
|
|
|
|
|
|
|
|
# Verify that the robot was saved.
|
|
|
|
self.assertEquals(True, activate_json['is_active'])
|
2014-04-02 01:49:06 +00:00
|
|
|
self.assertEquals(ADMIN_ACCESS_USER + '+dtrobot', activate_json['pull_robot']['name'])
|
2014-03-27 22:33:13 +00:00
|
|
|
|
|
|
|
# Start a manual build.
|
|
|
|
start_json = self.postJsonResponse(ActivateBuildTrigger,
|
|
|
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple', trigger_uuid=trigger.uuid),
|
|
|
|
expected_code=201)
|
|
|
|
|
|
|
|
assert 'id' in start_json
|
|
|
|
self.assertEquals("build-name", start_json['display_name'])
|
|
|
|
self.assertEquals(['bar'], start_json['job_config']['docker_tags'])
|
|
|
|
|
2014-03-25 00:57:02 +00:00
|
|
|
|
|
|
|
class TestUserAuthorizations(ApiTestCase):
|
|
|
|
def test_list_get_delete_user_authorizations(self):
|
|
|
|
self.login(ADMIN_ACCESS_USER)
|
|
|
|
|
|
|
|
json = self.getJsonResponse(UserAuthorizationList)
|
|
|
|
|
|
|
|
self.assertEquals(1, len(json['authorizations']))
|
|
|
|
|
|
|
|
authorization = json['authorizations'][0]
|
|
|
|
|
|
|
|
assert 'uuid' in authorization
|
|
|
|
assert 'scopes' in authorization
|
|
|
|
assert 'application' in authorization
|
|
|
|
|
|
|
|
# Retrieve the authorization.
|
|
|
|
get_json = self.getJsonResponse(UserAuthorization, params=dict(access_token_uuid = authorization['uuid']))
|
|
|
|
self.assertEquals(authorization, get_json)
|
|
|
|
|
|
|
|
# Delete the authorization.
|
|
|
|
self.deleteResponse(UserAuthorization, params=dict(access_token_uuid = authorization['uuid']))
|
|
|
|
|
|
|
|
# Verify it has been deleted.
|
|
|
|
self.getJsonResponse(UserAuthorization, params=dict(access_token_uuid = authorization['uuid']),
|
|
|
|
expected_code=404)
|
|
|
|
|
2014-01-31 21:19:29 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|