Skip to content

Commit ef59b7c

Browse files
committed
Fixed #122 -- CLI-driven test suite.
1 parent d68da05 commit ef59b7c

21 files changed

Lines changed: 658 additions & 225 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ nosetests.xml
3939

4040
# Deis' config file
4141
deis/local_settings.py
42+
.secret_key
4243

4344
# deis application logs
4445
logs/

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ coverage:
1212
coverage run manage.py test api client cm provider web
1313
coverage html
1414

15+
test_client:
16+
python -m unittest client.tests
17+
1518
flake8:
1619
flake8

client/tests/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
"""
22
Tests for the command-line client for the Deis system.
33
"""
4+
5+
from .test_apps import * # noqa
6+
from .test_auth import * # noqa
7+
from .test_builds import * # noqa
8+
from .test_config import * # noqa
9+
from .test_containers import * # noqa
10+
from .test_flavors import * # noqa
11+
from .test_formations import * # noqa
12+
from .test_git import * # noqa
13+
from .test_keys import * # noqa
14+
from .test_layers import * # noqa
15+
from .test_misc import * # noqa
16+
from .test_nodes import * # noqa
17+
from .test_providers import * # noqa
18+
from .test_releases import * # noqa

client/tests/test_app.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

client/tests/test_apps.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
Unit tests for the Deis CLI apps commands.
3+
4+
Run these tests with "python -m unittest client.tests.test_apps"
5+
or with "./manage.py test client.AppsTest".
6+
"""
7+
8+
from __future__ import unicode_literals
9+
from unittest import TestCase
10+
from uuid import uuid4
11+
12+
import pexpect
13+
14+
from .utils import DEIS
15+
from .utils import DEIS_TEST_FLAVOR
16+
from .utils import random_repo
17+
from .utils import setup
18+
from .utils import teardown
19+
20+
21+
class AppsTest(TestCase):
22+
23+
@classmethod
24+
def setUpClass(cls):
25+
repo_name, repo_url = random_repo()
26+
cls.username, cls.password, cls.repo_dir = setup(repo_url)
27+
# create a new formation
28+
cls.formation = "{}-test-formation-{}".format(
29+
cls.username, uuid4().hex[:4])
30+
child = pexpect.spawn("{} formations:create {} --flavor={}".format(
31+
DEIS, cls.formation, DEIS_TEST_FLAVOR))
32+
child.expect("created {}.*to scale a basic formation".format(
33+
cls.formation))
34+
child.expect(pexpect.EOF)
35+
36+
@classmethod
37+
def tearDownClass(cls):
38+
# delete the formation
39+
child = pexpect.spawn("{} formations:destroy {} --confirm={}".format(
40+
DEIS, cls.formation, cls.formation))
41+
child.expect('done in ', timeout=5*60)
42+
child.expect(pexpect.EOF)
43+
teardown(cls.username, cls.password, cls.repo_dir)
44+
45+
def test_app_create(self):
46+
self.assertIsNotNone(self.formation)

client/tests/test_auth.py

Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,46 @@
1-
21
"""
3-
Unit tests for authentication in the CLI.
2+
Unit tests for the Deis CLI auth commands.
43
5-
Run these tests with "python -m unittest deis.tests.test_auth"
6-
or all tests with "python -m unittest discover".
7-
""" # pylint: disable=C0103,R0201,R0904
4+
Run these tests with "python -m unittest client.tests.test_auth"
5+
or with "./manage.py test client.AuthTest".
6+
"""
87

9-
import os
10-
import unittest
8+
from __future__ import unicode_literals
9+
from unittest import TestCase
1110

1211
import pexpect
1312

13+
from .utils import DEIS
14+
from .utils import DEIS_SERVER
15+
from .utils import setup
16+
from .utils import teardown
1417

15-
# Locate the 'of' executable script relative to this file.
16-
CLI = os.path.abspath(
17-
os.path.join(os.path.dirname(__file__), '..', 'deis'))
18-
19-
20-
class TestLogin(unittest.TestCase):
2118

22-
"""Test authentication in the CLI."""
19+
class AuthTest(TestCase):
2320

24-
def setUp(self):
25-
# TODO: set up the CLI/api/fixtures/tests.json...somehow
26-
self.child = pexpect.spawn('{} login'.format(CLI))
21+
@classmethod
22+
def setUpClass(cls):
23+
cls.username, cls.password, _ = setup()
2724

28-
def tearDown(self):
29-
self.child = None
25+
@classmethod
26+
def tearDownClass(cls):
27+
teardown(cls.username, cls.password, None)
3028

31-
def test_good_login(self):
32-
"""Test that a valid login responds with a success message."""
33-
child = self.child
34-
child.expect('username:')
35-
child.sendline('autotest')
36-
child.expect('password:')
37-
child.sendline('password')
38-
child.expect('Logged in as autotest.')
39-
# call a protected API endpoint to ensure we were authenticated
40-
child = self.child = pexpect.spawn('{} apps'.format(CLI))
41-
child.expect('^\S+ +\(.+\)')
42-
43-
def test_bad_login(self):
44-
"""Test that an invalid login responds with a failure message."""
45-
child = self.child
46-
child.expect('username:')
47-
child.sendline('autotest')
48-
child.expect('password:')
49-
child.sendline('Pa55w0rd')
50-
child.expect('Login failed.')
51-
# call a protected API endpoint to ensure we get an unauth error
52-
child = self.child = pexpect.spawn('{} apps'.format(CLI))
53-
child.expect("\('Error")
29+
def test_login(self):
30+
# log in the interactive way
31+
child = pexpect.spawn("{} login {}".format(DEIS, DEIS_SERVER))
32+
child.expect('username: ')
33+
child.sendline(self.username)
34+
child.expect('password: ')
35+
child.sendline(self.password)
36+
child.expect("Logged in as {}".format(self.username))
37+
child.expect(pexpect.EOF)
5438

5539
def test_logout(self):
56-
child = self.child = pexpect.spawn('{} logout'.format(CLI))
57-
child.expect('Logged out.')
58-
# call a protected API endpoint to ensure we get an unauth error
59-
child = self.child = pexpect.spawn('{} apps'.format(CLI))
60-
child.expect("\('Error")
61-
62-
63-
class TestHelp(unittest.TestCase):
64-
65-
"""Test that the client can document its own behavior."""
66-
67-
def test_version(self):
68-
"""Test that the client reports its help message."""
69-
child = pexpect.spawn('{} --help'.format(CLI))
70-
child.expect(r'Usage: .*number of proxies\s+$')
71-
child = pexpect.spawn('{} -h'.format(CLI))
72-
child.expect(r'Usage: .*number of proxies\s+$')
73-
child = pexpect.spawn('{} help'.format(CLI))
74-
child.expect(r'Usage: .*number of proxies\s+$')
75-
76-
77-
class TestVersion(unittest.TestCase):
78-
79-
"""Test that the client can report its version string."""
80-
81-
def test_version(self):
82-
"""Test that the client reports its version string."""
83-
child = pexpect.spawn('{} --version'.format(CLI))
84-
child.expect('Deis CLI 0.0.1')
85-
child = pexpect.spawn('{} -v'.format(CLI))
86-
child.expect('Deis CLI 0.0.1')
40+
child = pexpect.spawn("{} logout".format(DEIS))
41+
child.expect('Logged out')
42+
# log in the one-liner way
43+
child = pexpect.spawn("{} login {} --username={} --password={}".format(
44+
DEIS, DEIS_SERVER, self.username, self.password))
45+
child.expect("Logged in as {}".format(self.username))
46+
child.expect(pexpect.EOF)

client/tests/test_build.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

client/tests/test_builds.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Unit tests for the Deis CLI build commands.
3+
4+
Run these tests with "python -m unittest client.tests.test_builds"
5+
or with "./manage.py test client.BuildsTest".
6+
"""
7+
8+
from __future__ import unicode_literals
9+
from unittest import TestCase
10+
11+
12+
class BuildsTest(TestCase):
13+
14+
pass
15+
16+
17+
# class TestBuild(unittest.TestCase):
18+
19+
# """Test builds."""
20+
21+
# def setUp(self):
22+
# # TODO: set up the c3/api/fixtures/tests.json...somehow
23+
# child = pexpect.spawn('{} login {}'.format(CLI, CONTROLLER))
24+
# child.expect('username:')
25+
# child.sendline('autotest')
26+
# child.expect('password:')
27+
# child.sendline('password')
28+
# child.expect('Logged in as autotest')
29+
30+
# def tearDown(self):
31+
# self.child = None
32+
33+
# def test_build(self):
34+
# """Test that a user can publish a new build."""
35+
# _, temp = tempfile.mkstemp()
36+
# body = {
37+
# 'sha': uuid.uuid4().hex,
38+
# 'slug_size': 4096000,
39+
# 'procfile': json.dumps({'web': 'node server.js'}),
40+
# 'url':
41+
# 'http://deis.local/slugs/1c52739bbf3a44d3bfb9a58f7bbdd5fb.tar.gz',
42+
# 'checksum': uuid.uuid4().hex,
43+
# }
44+
# with open(temp, 'w') as f:
45+
# f.write(json.dumps(body))
46+
# child = pexpect.spawn(
47+
# 'cat {} | {} builds:create - --app=test-app'.format(temp, CLI))
48+
# child.expect('Usage: ')

0 commit comments

Comments
 (0)