-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils.py
More file actions
98 lines (84 loc) · 3.07 KB
/
utils.py
File metadata and controls
98 lines (84 loc) · 3.07 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
Common code used by the Deis CLI unit tests.
"""
from __future__ import unicode_literals
import os
import os.path
import random
import shutil
import tempfile
from uuid import uuid4
import pexpect
DEIS = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'deis.py'))
try:
DEIS_SERVER = os.environ['DEIS_SERVER']
except KeyError:
DEIS_SERVER = None
print 'Error: env var DEIS_SERVER must point to a Deis controller URL.'
DEIS_TEST_FLAVOR = os.environ.get('DEIS_TEST_FLAVOR', 'ec2-us-west-2')
REPOSITORIES = {
'Clojure': 'https://github.com/opdemand/example-clojure-ring.git',
# 'Python': 'https://github.com/opdemand/example-python-django.git',
'Python': 'https://github.com/opdemand/example-python-flask.git',
'Java': 'https://github.com/opdemand/example-java-jetty.git',
'Go': 'https://github.com/opdemand/example-go.git',
'Node.js': 'https://github.com/opdemand/example-nodejs-express.git',
# 'Ruby/Rails': 'https://github.com/opdemand/example-rails-helloworld.git',
'Ruby/Rails': 'https://github.com/opdemand/example-rails-todo.git',
'Ruby/Rack': 'https://github.com/opdemand/example-ruby-sinatra.git',
}
def purge(username, password):
"""Purge an existing Deis user."""
child = pexpect.spawn("{} auth:cancel".format(DEIS))
child.expect('username: ')
child.sendline(username)
child.expect('password: ')
child.sendline(password)
child.expect('\? \(y/n\) ')
child.sendline('y')
child.expect(pexpect.EOF)
def register():
"""Register a new Deis user from the command line."""
username = "autotester-{}".format(uuid4().hex[:4])
password = 'password'
child = pexpect.spawn("{} register {}".format(DEIS, DEIS_SERVER))
child.expect('username: ')
child.sendline(username)
child.expect('password: ')
child.sendline(password)
child.expect('password \(confirm\): ')
child.sendline(password)
child.expect('email: ')
child.sendline('autotest@opdemand.com')
child.expect('Which would you like to use with Deis')
child.sendline('1')
child.expect('Import these credentials\? \(y/n\) :')
child.sendline('y')
child.expect(pexpect.EOF)
return username, password
def random_repo():
"""Return an example Heroku-style repository name and URL."""
name = random.choice(REPOSITORIES.keys())
return name, REPOSITORIES[name]
def setup(repo_url=None):
"""Do user and fixture setup for CLI tests."""
# create an autotest user
username, password = register()
repo_dir = None
if repo_url:
# clone an example repository
repo_dir = tempfile.mkdtemp()
child = pexpect.spawn("git clone {} {}".format(repo_url, repo_dir))
child.expect(', done')
child.expect(pexpect.EOF)
# cd to repo dir
os.chdir(repo_dir)
return (username, password, repo_dir)
def teardown(username, password, repo_dir=None):
"""Undo user and fixture setup for CLI tests."""
# destroy the example repository
if repo_dir:
shutil.rmtree(repo_dir)
# destroy the autotest user
purge(username, password)