This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
85 lines (60 loc) · 2.16 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from functools import wraps
from fabric.api import local
from fabric.api import task
from fabric.context_managers import prefix
from os.path import exists
@task
def setup_env(env='local_env'):
create_virtual_environment(env)
install_dependencies(env=env)
print '-----------------------------------------\n\n' \
'Virtual environment created at ./{0}\n' \
'To activate use ". {0}/bin/activate"'.format(env)
def create_virtual_environment(env):
print '--- Creating virtual environment at ./{}'.format(env)
local('virtualenv {}'.format(env))
def activate_env(fn):
@wraps(fn)
def with_env_activated(*args, **kwargs):
# print(args, kwargs)
env = kwargs['env']
if not exists(env):
setup_env(env)
with prefix('. {}/bin/activate'.format(env)):
return fn(env)
return with_env_activated
@activate_env
def install_dependencies(env):
print('--- Installing dependencies from requirements.txt in {}'.format(env))
local('pip install -r requirements.txt')
@task
def test(only='unit integration functional', env='local_env'):
if 'unit' in only:
run_unit_tests(env=env)
if 'integration' in only or 'functional' in only:
# need to pass only down to sh -> docker as command -> fab into docker to decide whether to run ft or int
local('./docker_tests/run_docker_tests.sh {}'.format(only))
@task
def docker_tests(only='integration functional', env='local_env'):
if 'integration' in only:
integration(env=env)
if 'functional' in only:
ft(env=env)
@task
def docker_ft(env='local_env'):
ft(env=env)
@task
def docker_integration(env='local_env'):
integration(env=env)
@activate_env
def ft(env='local_env'):
print 'Running functional tests..'
print local('python -m unittest discover -s ./docker_tests/functional')
@activate_env
def integration(env='local_env'):
print 'Running integration tests..'
print local('python -m unittest discover -s ./docker_tests/integration')
@activate_env
def run_unit_tests(env='local_env'):
print 'Running unit tests..'
print local('python -m unittest discover -s ./tests/unit')