Revision c25cc9ec logic/tests.py
b/logic/tests.py | ||
---|---|---|
30 | 30 |
|
31 | 31 |
# Provides automated tests for logic module |
32 | 32 |
|
33 |
import time |
|
34 |
import hashlib |
|
35 |
from random import randint |
|
36 |
|
|
37 |
from django.test import TestCase |
|
38 |
from django.conf import settings |
|
39 |
|
|
33 | 40 |
from synnefo.db.models import * |
34 | 41 |
from synnefo.logic import backend |
35 | 42 |
from synnefo.logic import credits |
36 | 43 |
from synnefo.logic import users |
37 | 44 |
from synnefo.logic.utils import get_rsapi_state |
38 | 45 |
|
39 |
from django.test import TestCase |
|
40 |
from django.conf import settings |
|
41 |
|
|
42 |
import time |
|
43 |
import hashlib |
|
44 | 46 |
|
45 | 47 |
class CostsTestCase(TestCase): |
46 |
fixtures = [ 'db_test_data' ]
|
|
48 |
fixtures = ['db_test_data']
|
|
47 | 49 |
|
48 | 50 |
def test_get_costs(self): |
49 | 51 |
"""Test the Flavor cost-related methods method""" |
... | ... | |
88 | 90 |
|
89 | 91 |
|
90 | 92 |
class ChargeTestCase(TestCase): |
91 |
fixtures = [ 'db_test_data' ]
|
|
93 |
fixtures = ['db_test_data']
|
|
92 | 94 |
|
93 | 95 |
def test_charge_method(self): |
94 | 96 |
"""Test VirtualMachine.charge() method""" |
... | ... | |
110 | 112 |
|
111 | 113 |
|
112 | 114 |
class DebitAccountTestCase(TestCase): |
113 |
fixtures = [ 'db_test_data' ]
|
|
115 |
fixtures = ['db_test_data']
|
|
114 | 116 |
|
115 | 117 |
def test_debit_account(self): |
116 | 118 |
"""Test a SynnefoUser object""" |
... | ... | |
132 | 134 |
|
133 | 135 |
|
134 | 136 |
class AuthTestCase(TestCase): |
135 |
fixtures = [ 'db_test_data' ]
|
|
137 |
fixtures = ['db_test_data']
|
|
136 | 138 |
|
137 | 139 |
def _register_user(self): |
138 | 140 |
users.register_student ("Jimmy Page", "jpage", "jpage@zoso.com") |
... | ... | |
281 | 283 |
|
282 | 284 |
class ProcessNetStatusTestCase(TestCase): |
283 | 285 |
fixtures = ['db_test_data'] |
286 |
|
|
284 | 287 |
def test_set_ipv4(self): |
285 | 288 |
"""Test reception of a net status notification""" |
286 | 289 |
msg = {'instance': 'instance-name', |
... | ... | |
307 | 310 |
|
308 | 311 |
|
309 | 312 |
class UsersTestCase(TestCase): |
310 |
|
|
311 | 313 |
def test_create_uname(self): |
312 | 314 |
username = users.create_uname("Donald Knuth") |
313 | 315 |
self.assertEquals(username, "knuthd") |
... | ... | |
318 | 320 |
username = users.create_uname(u'Γεώργιος Παπαγεωργίου') |
319 | 321 |
self.assertEquals(username, u'παπαγεωγ') |
320 | 322 |
|
323 |
|
|
321 | 324 |
class ProcessProgressUpdateTestCase(TestCase): |
322 |
fixtures = [ 'db_test_data' ]
|
|
325 |
fixtures = ['db_test_data']
|
|
323 | 326 |
|
324 | 327 |
def test_progress_update(self): |
328 |
"""Test reception of a create progress notification""" |
|
325 | 329 |
|
326 |
# A VM in status BUILDING
|
|
330 |
# This machine is in BUILD
|
|
327 | 331 |
vm = VirtualMachine.objects.get(pk=30002) |
332 |
rprogress = randint(10, 100) |
|
328 | 333 |
|
329 |
backend.process_progress_update(vm, 12)
|
|
330 |
self.assertEquals(vm.buildpercentage, 12)
|
|
334 |
backend.process_create_progress(vm, rprogress, 0)
|
|
335 |
self.assertEquals(vm.buildpercentage, rprogress)
|
|
331 | 336 |
|
332 |
self.assertRaises(Exception, backend.process_progress_update, vm, 10) |
|
333 |
self.assertRaises(Exception, backend.process_progress_update, vm, -1) |
|
334 |
self.assertRaises(Exception, backend.process_progress_update, vm, 102) |
|
335 |
self.assertRaises(TypeError, backend.process_progress_update, vm, '1') |
|
337 |
self.assertRaises(ValueError, backend.process_create_progress, |
|
338 |
vm, 9, 0) |
|
339 |
self.assertRaises(ValueError, backend.process_create_progress, |
|
340 |
vm, -1, 0) |
|
341 |
self.assertRaises(ValueError, backend.process_create_progress, |
|
342 |
vm, 102, 0) |
|
343 |
self.assertRaises(ValueError, backend.process_create_progress, |
|
344 |
vm, 'a', 0) |
|
345 |
|
|
346 |
# This machine is ACTIVE |
|
347 |
#vm = VirtualMachine.objects.get(pk=30000) |
|
348 |
#self.assertRaises(VirtualMachine.IllegalState, |
|
349 |
# backend.process_create_progress, vm, 1) |
|
336 | 350 |
|
337 |
# A VM in status RUNNING |
|
338 |
vm = VirtualMachine.objects.get(pk=30000) |
|
339 |
self.assertRaises(VirtualMachine.IllegalState, |
|
340 |
backend.process_progress_update, vm, 1) |
Also available in: Unified diff