Commit ebc32b08 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

astakos: Update tests

parent 7839f153
...@@ -66,14 +66,14 @@ class QuotaAPITest(TestCase): ...@@ -66,14 +66,14 @@ class QuotaAPITest(TestCase):
"service_origin": "service1", "service_origin": "service1",
"ui_visible": True} "ui_visible": True}
r, _ = register.add_resource(resource11) r, _ = register.add_resource(resource11)
register.update_resources([(r, 100)]) register.update_base_default(r, 100)
resource12 = {"name": "service1.resource12", resource12 = {"name": "service1.resource12",
"desc": "resource11 desc", "desc": "resource11 desc",
"service_type": "type1", "service_type": "type1",
"service_origin": "service1", "service_origin": "service1",
"unit": "bytes"} "unit": "bytes"}
r, _ = register.add_resource(resource12) r, _ = register.add_resource(resource12)
register.update_resources([(r, 1024)]) register.update_base_default(r, 1024)
# create user # create user
user = get_local_user('test@grnet.gr') user = get_local_user('test@grnet.gr')
...@@ -93,7 +93,7 @@ class QuotaAPITest(TestCase): ...@@ -93,7 +93,7 @@ class QuotaAPITest(TestCase):
"service_origin": "service2", "service_origin": "service2",
"ui_visible": False} "ui_visible": False}
r, _ = register.add_resource(resource21) r, _ = register.add_resource(resource21)
register.update_resources([(r, 3)]) register.update_base_default(r, 3)
resource_names = [r['name'] for r in resource_names = [r['name'] for r in
[resource11, resource12, resource21]] [resource11, resource12, resource21]]
...@@ -113,10 +113,10 @@ class QuotaAPITest(TestCase): ...@@ -113,10 +113,10 @@ class QuotaAPITest(TestCase):
r = client.get(u('quotas/'), **headers) r = client.get(u('quotas/'), **headers)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
body = json.loads(r.content) body = json.loads(r.content)
system_quota = body['system'] assertIn(user.uuid, body)
assertIn('system', body) base_quota = body[user.uuid]
for name in resource_names: for name in resource_names:
assertIn(name, system_quota) assertIn(name, base_quota)
nmheaders = {'HTTP_X_AUTH_TOKEN': non_moderated_user.auth_token} nmheaders = {'HTTP_X_AUTH_TOKEN': non_moderated_user.auth_token}
r = client.get(u('quotas/'), **nmheaders) r = client.get(u('quotas/'), **nmheaders)
...@@ -149,14 +149,14 @@ class QuotaAPITest(TestCase): ...@@ -149,14 +149,14 @@ class QuotaAPITest(TestCase):
"name": "my commission", "name": "my commission",
"provisions": [ "provisions": [
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource11['name'], "resource": resource11['name'],
"quantity": 1 "quantity": 1
}, },
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource12['name'], "resource": resource12['name'],
"quantity": 30000 "quantity": 30000
}]} }]}
...@@ -172,14 +172,14 @@ class QuotaAPITest(TestCase): ...@@ -172,14 +172,14 @@ class QuotaAPITest(TestCase):
"name": "my commission", "name": "my commission",
"provisions": [ "provisions": [
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource11['name'], "resource": resource11['name'],
"quantity": 1 "quantity": 1
}, },
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource12['name'], "resource": resource12['name'],
"quantity": 100 "quantity": 100
}]} }]}
...@@ -226,11 +226,16 @@ class QuotaAPITest(TestCase): ...@@ -226,11 +226,16 @@ class QuotaAPITest(TestCase):
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
body = json.loads(r.content) body = json.loads(r.content)
user_quota = body[user.uuid] user_quota = body[user.uuid]
system_quota = user_quota['system'] base_quota = user_quota[user.uuid]
r11 = system_quota[resource11['name']] r11 = base_quota[resource11['name']]
self.assertEqual(r11['usage'], 3) self.assertEqual(r11['usage'], 3)
self.assertEqual(r11['pending'], 3) self.assertEqual(r11['pending'], 3)
r = client.get(u('service_project_quotas'), **s1_headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
assertIn(user.uuid, body)
# resolve pending commissions # resolve pending commissions
resolve_data = { resolve_data = {
"accept": [serial1, serial3], "accept": [serial1, serial3],
...@@ -256,14 +261,14 @@ class QuotaAPITest(TestCase): ...@@ -256,14 +261,14 @@ class QuotaAPITest(TestCase):
"name": "my commission", "name": "my commission",
"provisions": [ "provisions": [
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource11['name'], "resource": resource11['name'],
"quantity": 1 "quantity": 1
}, },
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource12['name'], "resource": resource12['name'],
"quantity": 100 "quantity": 100
}]} }]}
...@@ -285,8 +290,8 @@ class QuotaAPITest(TestCase): ...@@ -285,8 +290,8 @@ class QuotaAPITest(TestCase):
"name": "my commission", "name": "my commission",
"provisions": [ "provisions": [
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource11['name'], "resource": resource11['name'],
} }
]} ]}
...@@ -316,14 +321,14 @@ class QuotaAPITest(TestCase): ...@@ -316,14 +321,14 @@ class QuotaAPITest(TestCase):
"name": "my commission", "name": "my commission",
"provisions": [ "provisions": [
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": "non existent", "resource": "non existent",
"quantity": 1 "quantity": 1
}, },
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource12['name'], "resource": resource12['name'],
"quantity": 100 "quantity": 100
}]} }]}
...@@ -337,8 +342,8 @@ class QuotaAPITest(TestCase): ...@@ -337,8 +342,8 @@ class QuotaAPITest(TestCase):
commission_request = { commission_request = {
"provisions": [ "provisions": [
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource11['name'], "resource": resource11['name'],
"quantity": -1 "quantity": -1
} }
...@@ -368,8 +373,8 @@ class QuotaAPITest(TestCase): ...@@ -368,8 +373,8 @@ class QuotaAPITest(TestCase):
"force": True, "force": True,
"provisions": [ "provisions": [
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource11['name'], "resource": resource11['name'],
"quantity": 100 "quantity": 100
}]} }]}
...@@ -383,8 +388,8 @@ class QuotaAPITest(TestCase): ...@@ -383,8 +388,8 @@ class QuotaAPITest(TestCase):
"force": True, "force": True,
"provisions": [ "provisions": [
{ {
"holder": user.uuid, "holder": "user:" + user.uuid,
"source": "system", "source": "project:" + user.uuid,
"resource": resource11['name'], "resource": resource11['name'],
"quantity": -200 "quantity": -200
}]} }]}
...@@ -397,8 +402,8 @@ class QuotaAPITest(TestCase): ...@@ -397,8 +402,8 @@ class QuotaAPITest(TestCase):
r = client.get(u('quotas'), **headers) r = client.get(u('quotas'), **headers)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
body = json.loads(r.content) body = json.loads(r.content)
system_quota = body['system'] base_quota = body[user.uuid]
r11 = system_quota[resource11['name']] r11 = base_quota[resource11['name']]
self.assertEqual(r11['usage'], 102) self.assertEqual(r11['usage'], 102)
self.assertEqual(r11['pending'], 101) self.assertEqual(r11['pending'], 101)
...@@ -753,7 +758,7 @@ class WrongPathAPITest(TestCase): ...@@ -753,7 +758,7 @@ class WrongPathAPITest(TestCase):
class ValidateAccessToken(TestCase): class ValidateAccessToken(TestCase):
def setUp(self): def setUp(self):
self.oa2_backend = DjangoBackend() self.oa2_backend = DjangoBackend()
self.user = AstakosUser.objects.create(username="user@synnefo.org") self.user = get_local_user("user@synnefo.org")
self.token = self.oa2_backend.token_model.create( self.token = self.oa2_backend.token_model.create(
code='12345', code='12345',
expires_at=datetime.now() + timedelta(seconds=5), expires_at=datetime.now() + timedelta(seconds=5),
......
...@@ -64,7 +64,8 @@ def submit(name, user_id, project_id=None): ...@@ -64,7 +64,8 @@ def submit(name, user_id, project_id=None):
if not ok: if not ok:
raise ProjectForbidden('Limit %s reached', limit) raise ProjectForbidden('Limit %s reached', limit)
resource_policies = {'cyclades.network.private': {'member_capacity': 5}} resource_policies = {'cyclades.network.private': {'member_capacity': 5,
'project_capacity': 10}}
data = {'owner': owner, data = {'owner': owner,
'name': name, 'name': name,
'project_id': project_id, 'project_id': project_id,
......
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