Commit a7da5556 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou

Merge branch 'develop' into feature-astakos-userflow

parents 7319c9be 2ce54fe3
import sys, os
sys.path.insert(0, os.path.abspath('../snf-cyclades-app'))
import synnefo
reload(synnefo)
import synnefo.versions
reload(synnefo.versions)
from synnefo.versions.app import __version__
project = u'synnefo'
......
......@@ -36,7 +36,7 @@ import copy
import datetime
import functools
from snf_django.utils.testing import with_settings, override_settings
from snf_django.utils.testing import with_settings, override_settings, assertIn
from django.test import Client
from django.test import TransactionTestCase as TestCase
......@@ -1649,35 +1649,35 @@ class QuotaAPITest(TestCase):
[resource11, resource12, resource21]]
# get resources
r = client.get(u('resources'), follow=True)
r = client.get(u('resources'))
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
for name in resource_names:
self.assertIn(name, body)
assertIn(name, body)
# get quota
r = client.get(u('quotas'), follow=True)
r = client.get(u('quotas'))
self.assertEqual(r.status_code, 401)
headers = {'HTTP_X_AUTH_TOKEN': user.auth_token}
r = client.get(u('quotas'), follow=True, **headers)
r = client.get(u('quotas/'), **headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
system_quota = body['system']
self.assertIn('system', body)
assertIn('system', body)
for name in resource_names:
self.assertIn(name, system_quota)
assertIn(name, system_quota)
r = client.get(u('service_quotas'), follow=True)
r = client.get(u('service_quotas'))
self.assertEqual(r.status_code, 401)
s1_headers = {'HTTP_X_AUTH_TOKEN': service1.auth_token}
r = client.get(u('service_quotas'), follow=True, **s1_headers)
r = client.get(u('service_quotas'), **s1_headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
self.assertIn(user.uuid, body)
assertIn(user.uuid, body)
r = client.get(u('commissions'), follow=True, **s1_headers)
r = client.get(u('commissions'), **s1_headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
self.assertEqual(body, [])
......@@ -1746,22 +1746,20 @@ class QuotaAPITest(TestCase):
body = json.loads(r.content)
self.assertEqual(body['serial'], 3)
r = client.get(u('commissions'), follow=True, **s1_headers)
r = client.get(u('commissions'), **s1_headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
self.assertEqual(body, [1, 2, 3])
r = client.get(u('commissions/' + str(serial)), follow=True,
**s1_headers)
r = client.get(u('commissions/' + str(serial)), **s1_headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
self.assertEqual(body['serial'], serial)
self.assertIn('issue_time', body)
assertIn('issue_time', body)
self.assertEqual(body['provisions'], commission_request['provisions'])
self.assertEqual(body['name'], commission_request['name'])
r = client.get(u('service_quotas?user=' + user.uuid),
follow=True, **s1_headers)
r = client.get(u('service_quotas?user=' + user.uuid), **s1_headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
user_quota = body[user.uuid]
......@@ -1786,8 +1784,7 @@ class QuotaAPITest(TestCase):
failed = body['failed']
self.assertEqual(len(failed), 2)
r = client.get(u('commissions/' + str(serial)), follow=True,
**s1_headers)
r = client.get(u('commissions/' + str(serial)), **s1_headers)
self.assertEqual(r.status_code, 404)
# auto accept
......@@ -1816,8 +1813,7 @@ class QuotaAPITest(TestCase):
serial = body['serial']
self.assertEqual(serial, 4)
r = client.get(u('commissions/' + str(serial)), follow=True,
**s1_headers)
r = client.get(u('commissions/' + str(serial)), **s1_headers)
self.assertEqual(r.status_code, 404)
# malformed
......
......@@ -33,6 +33,7 @@
from django.test import TestCase
from snf_django.utils.testing import assertGreater, assertIn, assertRaises
import astakos.quotaholder_app.callpoint as qh
from astakos.quotaholder_app.exception import (
InvalidDataError,
......@@ -77,7 +78,7 @@ class QuotaholderTest(TestCase):
s1 = self.issue_commission([((holder, source, resource1), limit1/2),
((holder, source, resource2), limit2)],
name="initial")
self.assertGreater(s1, 0)
assertGreater(s1, 0)
r = qh.get_commission(self.client, s1)
provisions = [
......@@ -95,14 +96,14 @@ class QuotaholderTest(TestCase):
self.assertEqual(r['serial'], s1)
ps = r['provisions']
for p in ps:
self.assertIn(p, provisions)
assertIn(p, provisions)
with self.assertRaises(NoCommissionError):
with assertRaises(NoCommissionError):
qh.get_commission(self.client, s1+1)
# commission exceptions
with self.assertRaises(NoCapacityError) as cm:
with assertRaises(NoCapacityError) as cm:
self.issue_commission([((holder, source, resource1), 1),
((holder, source, resource2), 1)])
......@@ -115,7 +116,7 @@ class QuotaholderTest(TestCase):
self.assertEqual(e.data['usage'], limit2)
self.assertEqual(e.data['limit'], limit2)
with self.assertRaises(NoQuantityError) as cm:
with assertRaises(NoQuantityError) as cm:
self.issue_commission([((holder, source, resource1), -1)])
e = cm.exception
......@@ -127,7 +128,7 @@ class QuotaholderTest(TestCase):
self.assertEqual(e.data['usage'], 0)
self.assertEqual(e.data['limit'], 0)
with self.assertRaises(NoHoldingError) as cm:
with assertRaises(NoHoldingError) as cm:
self.issue_commission([((holder, source, resource1), 1),
(('nonex', source, resource1), 1)])
......@@ -138,7 +139,7 @@ class QuotaholderTest(TestCase):
self.assertEqual(provision['resource'], resource1)
self.assertEqual(provision['quantity'], 1)
with self.assertRaises(DuplicateError) as cm:
with assertRaises(DuplicateError) as cm:
self.issue_commission([((holder, source, resource1), 1),
((holder, source, resource1), 2)])
......@@ -149,7 +150,7 @@ class QuotaholderTest(TestCase):
self.assertEqual(provision['resource'], resource1)
self.assertEqual(provision['quantity'], 2)
with self.assertRaises(InvalidDataError):
with assertRaises(InvalidDataError):
self.issue_commission([((holder, source, resource1), 1),
((holder, source, resource1), "nan")])
......@@ -217,7 +218,7 @@ class QuotaholderTest(TestCase):
}
self.assertEqual(r, quotas)
with self.assertRaises(NoCapacityError):
with assertRaises(NoCapacityError):
self.issue_commission(
[((holder, source, resource1), limit1/2+1)])
......
......@@ -22,3 +22,6 @@ LOGIN_URL = 'http://host:port/'
SOUTH_TESTS_MIGRATE = bool(int(os.environ.get('SOUTH_TESTS_MIGRATE', True)))
ASTAKOS_IM_MODULES = ['local', 'shibboleth']
CYCLADES_PROXY_USER_SERVICES = False
PITHOS_PROXY_USER_SERVICES = False
......@@ -186,3 +186,44 @@ class BaseAPITest(TestCase):
def assertItemNotFound(self, response):
self.assertFault(response, 404, 'itemNotFound')
# Imitate unittest assertions new in Python 2.7
class _AssertRaisesContext(object):
"""
A context manager used to implement TestCase.assertRaises* methods.
Adapted from unittest2.
"""
def __init__(self, expected):
self.expected = expected
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
if exc_type is None:
try:
exc_name = self.expected.__name__
except AttributeError:
exc_name = str(self.expected)
raise AssertionError(
"%s not raised" % (exc_name,))
if not issubclass(exc_type, self.expected):
# let unexpected exceptions pass through
return False
self.exception = exc_value # store for later retrieval
return True
def assertRaises(excClass):
return _AssertRaisesContext(excClass)
def assertGreater(x, y):
assert x > y
def assertIn(x, y):
assert x in y
......@@ -39,7 +39,7 @@ import time as _time
import pithos.api.settings as settings
from pithos.api.swiss_army import SwissArmy
from pithos.api.manage_accounts import ManageAccounts
def get_random_data(length=500):
char_set = string.ascii_uppercase + string.digits
......@@ -47,7 +47,7 @@ def get_random_data(length=500):
class TestPublic(unittest.TestCase):
def setUp(self):
self.utils = SwissArmy()
self.utils = ManageAccounts()
self.backend = self.utils.backend
self.utils.create_account('account')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment