Commit 70bcdc46 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Use TestCase instead of TransactionTestCase

We need to be sure that code runs in a transaction (provided by TestCase).
If we need in some case to test the transactional behavior itself,
we could there use TransactionTestCase.
parent 361ec44d
......@@ -36,7 +36,6 @@ from astakos.im.settings import astakos_services, BASE_HOST
from synnefo.lib.services import get_service_path
from synnefo.lib import join_urls
from django.test import TestCase
from django.core.urlresolvers import reverse
from datetime import date
......@@ -187,32 +186,34 @@ class QuotaAPITest(TestCase):
content_type='application/json', **s1_headers)
self.assertEqual(r.status_code, 201)
body = json.loads(r.content)
serial = body['serial']
self.assertEqual(serial, 1)
serial1 = body['serial']
assertGreater(serial1, 0)
post_data = json.dumps(commission_request)
r = client.post(u('commissions'), post_data,
content_type='application/json', **s1_headers)
self.assertEqual(r.status_code, 201)
body = json.loads(r.content)
self.assertEqual(body['serial'], 2)
serial2 = body['serial']
assertGreater(serial2, serial1)
post_data = json.dumps(commission_request)
r = client.post(u('commissions'), post_data,
content_type='application/json', **s1_headers)
self.assertEqual(r.status_code, 201)
body = json.loads(r.content)
self.assertEqual(body['serial'], 3)
serial3 = body['serial']
assertGreater(serial3, serial2)
r = client.get(u('commissions'), **s1_headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
self.assertEqual(body, [1, 2, 3])
self.assertEqual(len(body), 3)
r = client.get(u('commissions/' + str(serial)), **s1_headers)
r = client.get(u('commissions/' + str(serial1)), **s1_headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
self.assertEqual(body['serial'], serial)
self.assertEqual(body['serial'], serial1)
assertIn('issue_time', body)
provisions = sorted(body['provisions'], key=lambda p: p['resource'])
self.assertEqual(provisions, commission_request['provisions'])
......@@ -229,8 +230,8 @@ class QuotaAPITest(TestCase):
# resolve pending commissions
resolve_data = {
"accept": [1, 3],
"reject": [2, 3, 4],
"accept": [serial1, serial3],
"reject": [serial2, serial3, serial3 + 1],
}
post_data = json.dumps(resolve_data)
......@@ -238,12 +239,12 @@ class QuotaAPITest(TestCase):
content_type='application/json', **s1_headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
self.assertEqual(body['accepted'], [1])
self.assertEqual(body['rejected'], [2])
self.assertEqual(body['accepted'], [serial1])
self.assertEqual(body['rejected'], [serial2])
failed = body['failed']
self.assertEqual(len(failed), 2)
r = client.get(u('commissions/' + str(serial)), **s1_headers)
r = client.get(u('commissions/' + str(serial1)), **s1_headers)
self.assertEqual(r.status_code, 404)
# auto accept
......@@ -269,10 +270,10 @@ class QuotaAPITest(TestCase):
content_type='application/json', **s1_headers)
self.assertEqual(r.status_code, 201)
body = json.loads(r.content)
serial = body['serial']
self.assertEqual(serial, 4)
serial4 = body['serial']
assertGreater(serial4, serial3)
r = client.get(u('commissions/' + str(serial)), **s1_headers)
r = client.get(u('commissions/' + str(serial4)), **s1_headers)
self.assertEqual(r.status_code, 404)
# malformed
......
......@@ -37,10 +37,11 @@ import copy
import datetime
import functools
from snf_django.utils.testing import with_settings, override_settings, assertIn
from snf_django.utils.testing import with_settings, override_settings, \
assertIn, assertGreater, assertRaises
from django.test import Client
from django.test import TransactionTestCase as TestCase
from django.test import TestCase
from django.core import mail
from django.http import SimpleCookie, HttpRequest, QueryDict
from django.utils.importlib import import_module
......
......@@ -32,7 +32,6 @@
# or implied, of GRNET S.A.
from astakos.im.tests.common import *
from snf_django.utils.testing import assertGreater, assertIn, assertRaises
class ProjectAPITest(TestCase):
......
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