Statistics
| Branch: | Tag: | Revision:

root / test / kkconfig.py @ f6d15c9b

History | View | Annotate | Download (1.7 kB)

1
### IMPORTS ###
2
# The following import is copied from snf-tools/syneffo_tools/burnin.py
3
# Thank you John Giannelos <johngian@grnet.gr>
4
# Use backported unittest functionality if Python < 2.7
5
try:
6
    import unittest2 as unittest
7
except ImportError:
8
    import sys
9
    if sys.version_info < (2, 7):
10
        raise Exception("The unittest2 package is required for Python < 2.7")
11
    del sys
12
    import unittest
13

    
14
from commissioning.clients.http import HTTP_API_Client
15
from commissioning import QuotaholderAPI
16
import random 
17

    
18
### DEFS ###
19
def new_quota_holder_client():
20
    """
21
    Create a new quota holder api client
22
    """
23
    class QuotaholderHTTP(HTTP_API_Client):
24
        api_spec = QuotaholderAPI()
25

    
26
    global QH_URL
27
    return QuotaholderHTTP(QH_URL)
28

    
29
def run_test_case(test_case):
30
    """
31
    Runs the test_case and returns the result
32
    """
33
    # Again from snf-tools/synnefo_tools/burnin.py
34
    # Thank you John Giannelos <johngian@grnet.gr>
35
    print("Running {0}".format(test_case))
36
    import sys
37
    suite = unittest.TestLoader().loadTestsFromTestCase(test_case)
38
    runner = unittest.TextTestRunner(stream = sys.stderr, verbosity = 2, failfast = True, buffer = False)
39
    return runner.run(suite)
40

    
41
def run_test_cases(test_cases):
42
    for test_case in test_cases:
43
        run_test_case(test_case)
44

    
45
def rand_string():
46
   alphabet = 'abcdefghijklmnopqrstuvwxyz'
47
   min = 5
48
   max = 15
49
   string=''
50
   for x in random.sample(alphabet,random.randint(min,max)):
51
    string += x
52
   return string
53

    
54
### CLASSES ###
55
class QHTestCase(unittest.TestCase):
56
    def setUp(self):
57
        self.qh = new_quota_holder_client()
58

    
59
    def tearDown(self):
60
        del self.qh
61

    
62

    
63
### VARS ###
64
QH_URL = "http://localhost:8008/api/quotaholder/v"