root / snf-astakos-app / astakos / quotaholder / test / config.py @ c6ef66ba
History | View | Annotate | Download (3.5 kB)
1 |
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
### IMPORTS ###
|
35 |
import sys |
36 |
import os |
37 |
import subprocess |
38 |
import time |
39 |
from errno import ECONNREFUSED |
40 |
from os.path import dirname |
41 |
|
42 |
path = os.path.dirname(os.path.realpath(__file__)) |
43 |
os.environ['SYNNEFO_SETTINGS_DIR'] = path + '/settings' |
44 |
os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings' |
45 |
|
46 |
# The following import is copied from snf-tools/syneffo_tools/burnin.py
|
47 |
# Thank you John Giannelos <johngian@grnet.gr>
|
48 |
# Use backported unittest functionality if Python < 2.7
|
49 |
try:
|
50 |
import unittest2 as unittest |
51 |
except ImportError: |
52 |
if sys.version_info < (2, 7): |
53 |
raise Exception("The unittest2 package is required for Python < 2.7") |
54 |
import unittest |
55 |
|
56 |
from astakos.quotaholder.callpoint import QuotaholderDjangoDBCallpoint |
57 |
|
58 |
import random |
59 |
|
60 |
def printf(fmt, *args): |
61 |
print(fmt.format(*args)) |
62 |
|
63 |
|
64 |
### DEFS ###
|
65 |
def new_quota_holder_client(): |
66 |
"""
|
67 |
Create a new quota holder api client
|
68 |
"""
|
69 |
return QuotaholderDjangoDBCallpoint()
|
70 |
|
71 |
def run_test_case(test_case): |
72 |
"""
|
73 |
Runs the test_case and returns the result
|
74 |
"""
|
75 |
# Again from snf-tools/synnefo_tools/burnin.py
|
76 |
# Thank you John Giannelos <johngian@grnet.gr>
|
77 |
printf("Running {0}", test_case)
|
78 |
import sys |
79 |
suite = unittest.TestLoader().loadTestsFromTestCase(test_case) |
80 |
runner = unittest.TextTestRunner(stream=sys.stderr, verbosity=2,
|
81 |
failfast=True, buffer=False) |
82 |
return runner.run(suite)
|
83 |
|
84 |
def run_test_cases(test_cases): |
85 |
for test_case in test_cases: |
86 |
run_test_case(test_case) |
87 |
|
88 |
def rand_string(): |
89 |
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
90 |
min = 5
|
91 |
max = 15
|
92 |
string=''
|
93 |
for x in random.sample(alphabet,random.randint(min,max)): |
94 |
string += x |
95 |
return string
|
96 |
|
97 |
HERE = dirname(__file__) |
98 |
|
99 |
### CLASSES ###
|
100 |
class QHTestCase(unittest.TestCase): |
101 |
@classmethod
|
102 |
def setUpClass(self): |
103 |
subprocess.call([HERE+'/qh_init'])
|
104 |
self.qh = new_quota_holder_client()
|
105 |
|
106 |
def setUp(self): |
107 |
print
|
108 |
|
109 |
@classmethod
|
110 |
def tearDownClass(self): |
111 |
pass
|