forked from deis/deis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed deis#122 -- CLI-driven test suite.
- Loading branch information
Showing
21 changed files
with
658 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ nosetests.xml | |
|
||
# Deis' config file | ||
deis/local_settings.py | ||
.secret_key | ||
|
||
# deis application logs | ||
logs/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
""" | ||
Tests for the command-line client for the Deis system. | ||
""" | ||
|
||
from .test_apps import * # noqa | ||
from .test_auth import * # noqa | ||
from .test_builds import * # noqa | ||
from .test_config import * # noqa | ||
from .test_containers import * # noqa | ||
from .test_flavors import * # noqa | ||
from .test_formations import * # noqa | ||
from .test_git import * # noqa | ||
from .test_keys import * # noqa | ||
from .test_layers import * # noqa | ||
from .test_misc import * # noqa | ||
from .test_nodes import * # noqa | ||
from .test_providers import * # noqa | ||
from .test_releases import * # noqa |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
Unit tests for the Deis CLI apps commands. | ||
Run these tests with "python -m unittest client.tests.test_apps" | ||
or with "./manage.py test client.AppsTest". | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
from unittest import TestCase | ||
from uuid import uuid4 | ||
|
||
import pexpect | ||
|
||
from .utils import DEIS | ||
from .utils import DEIS_TEST_FLAVOR | ||
from .utils import random_repo | ||
from .utils import setup | ||
from .utils import teardown | ||
|
||
|
||
class AppsTest(TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
repo_name, repo_url = random_repo() | ||
cls.username, cls.password, cls.repo_dir = setup(repo_url) | ||
# create a new formation | ||
cls.formation = "{}-test-formation-{}".format( | ||
cls.username, uuid4().hex[:4]) | ||
child = pexpect.spawn("{} formations:create {} --flavor={}".format( | ||
DEIS, cls.formation, DEIS_TEST_FLAVOR)) | ||
child.expect("created {}.*to scale a basic formation".format( | ||
cls.formation)) | ||
child.expect(pexpect.EOF) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
# delete the formation | ||
child = pexpect.spawn("{} formations:destroy {} --confirm={}".format( | ||
DEIS, cls.formation, cls.formation)) | ||
child.expect('done in ', timeout=5*60) | ||
child.expect(pexpect.EOF) | ||
teardown(cls.username, cls.password, cls.repo_dir) | ||
|
||
def test_app_create(self): | ||
self.assertIsNotNone(self.formation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,46 @@ | ||
|
||
""" | ||
Unit tests for authentication in the CLI. | ||
Unit tests for the Deis CLI auth commands. | ||
Run these tests with "python -m unittest deis.tests.test_auth" | ||
or all tests with "python -m unittest discover". | ||
""" # pylint: disable=C0103,R0201,R0904 | ||
Run these tests with "python -m unittest client.tests.test_auth" | ||
or with "./manage.py test client.AuthTest". | ||
""" | ||
|
||
import os | ||
import unittest | ||
from __future__ import unicode_literals | ||
from unittest import TestCase | ||
|
||
import pexpect | ||
|
||
from .utils import DEIS | ||
from .utils import DEIS_SERVER | ||
from .utils import setup | ||
from .utils import teardown | ||
|
||
# Locate the 'of' executable script relative to this file. | ||
CLI = os.path.abspath( | ||
os.path.join(os.path.dirname(__file__), '..', 'deis')) | ||
|
||
|
||
class TestLogin(unittest.TestCase): | ||
|
||
"""Test authentication in the CLI.""" | ||
class AuthTest(TestCase): | ||
|
||
def setUp(self): | ||
# TODO: set up the CLI/api/fixtures/tests.json...somehow | ||
self.child = pexpect.spawn('{} login'.format(CLI)) | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.username, cls.password, _ = setup() | ||
|
||
def tearDown(self): | ||
self.child = None | ||
@classmethod | ||
def tearDownClass(cls): | ||
teardown(cls.username, cls.password, None) | ||
|
||
def test_good_login(self): | ||
"""Test that a valid login responds with a success message.""" | ||
child = self.child | ||
child.expect('username:') | ||
child.sendline('autotest') | ||
child.expect('password:') | ||
child.sendline('password') | ||
child.expect('Logged in as autotest.') | ||
# call a protected API endpoint to ensure we were authenticated | ||
child = self.child = pexpect.spawn('{} apps'.format(CLI)) | ||
child.expect('^\S+ +\(.+\)') | ||
|
||
def test_bad_login(self): | ||
"""Test that an invalid login responds with a failure message.""" | ||
child = self.child | ||
child.expect('username:') | ||
child.sendline('autotest') | ||
child.expect('password:') | ||
child.sendline('Pa55w0rd') | ||
child.expect('Login failed.') | ||
# call a protected API endpoint to ensure we get an unauth error | ||
child = self.child = pexpect.spawn('{} apps'.format(CLI)) | ||
child.expect("\('Error") | ||
def test_login(self): | ||
# log in the interactive way | ||
child = pexpect.spawn("{} login {}".format(DEIS, DEIS_SERVER)) | ||
child.expect('username: ') | ||
child.sendline(self.username) | ||
child.expect('password: ') | ||
child.sendline(self.password) | ||
child.expect("Logged in as {}".format(self.username)) | ||
child.expect(pexpect.EOF) | ||
|
||
def test_logout(self): | ||
child = self.child = pexpect.spawn('{} logout'.format(CLI)) | ||
child.expect('Logged out.') | ||
# call a protected API endpoint to ensure we get an unauth error | ||
child = self.child = pexpect.spawn('{} apps'.format(CLI)) | ||
child.expect("\('Error") | ||
|
||
|
||
class TestHelp(unittest.TestCase): | ||
|
||
"""Test that the client can document its own behavior.""" | ||
|
||
def test_version(self): | ||
"""Test that the client reports its help message.""" | ||
child = pexpect.spawn('{} --help'.format(CLI)) | ||
child.expect(r'Usage: .*number of proxies\s+$') | ||
child = pexpect.spawn('{} -h'.format(CLI)) | ||
child.expect(r'Usage: .*number of proxies\s+$') | ||
child = pexpect.spawn('{} help'.format(CLI)) | ||
child.expect(r'Usage: .*number of proxies\s+$') | ||
|
||
|
||
class TestVersion(unittest.TestCase): | ||
|
||
"""Test that the client can report its version string.""" | ||
|
||
def test_version(self): | ||
"""Test that the client reports its version string.""" | ||
child = pexpect.spawn('{} --version'.format(CLI)) | ||
child.expect('Deis CLI 0.0.1') | ||
child = pexpect.spawn('{} -v'.format(CLI)) | ||
child.expect('Deis CLI 0.0.1') | ||
child = pexpect.spawn("{} logout".format(DEIS)) | ||
child.expect('Logged out') | ||
# log in the one-liner way | ||
child = pexpect.spawn("{} login {} --username={} --password={}".format( | ||
DEIS, DEIS_SERVER, self.username, self.password)) | ||
child.expect("Logged in as {}".format(self.username)) | ||
child.expect(pexpect.EOF) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
Unit tests for the Deis CLI build commands. | ||
Run these tests with "python -m unittest client.tests.test_builds" | ||
or with "./manage.py test client.BuildsTest". | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
from unittest import TestCase | ||
|
||
|
||
class BuildsTest(TestCase): | ||
|
||
pass | ||
|
||
|
||
# class TestBuild(unittest.TestCase): | ||
|
||
# """Test builds.""" | ||
|
||
# def setUp(self): | ||
# # TODO: set up the c3/api/fixtures/tests.json...somehow | ||
# child = pexpect.spawn('{} login {}'.format(CLI, CONTROLLER)) | ||
# child.expect('username:') | ||
# child.sendline('autotest') | ||
# child.expect('password:') | ||
# child.sendline('password') | ||
# child.expect('Logged in as autotest') | ||
|
||
# def tearDown(self): | ||
# self.child = None | ||
|
||
# def test_build(self): | ||
# """Test that a user can publish a new build.""" | ||
# _, temp = tempfile.mkstemp() | ||
# body = { | ||
# 'sha': uuid.uuid4().hex, | ||
# 'slug_size': 4096000, | ||
# 'procfile': json.dumps({'web': 'node server.js'}), | ||
# 'url': | ||
# 'http://deis.local/slugs/1c52739bbf3a44d3bfb9a58f7bbdd5fb.tar.gz', | ||
# 'checksum': uuid.uuid4().hex, | ||
# } | ||
# with open(temp, 'w') as f: | ||
# f.write(json.dumps(body)) | ||
# child = pexpect.spawn( | ||
# 'cat {} | {} builds:create - --app=test-app'.format(temp, CLI)) | ||
# child.expect('Usage: ') |
Oops, something went wrong.