|
8 | 8 | from __future__ import unicode_literals |
9 | 9 | from unittest import TestCase |
10 | 10 | from uuid import uuid4 |
| 11 | +import json |
| 12 | +import re |
11 | 13 |
|
12 | 14 | import pexpect |
13 | 15 |
|
@@ -42,5 +44,115 @@ def tearDownClass(cls): |
42 | 44 | child.expect(pexpect.EOF) |
43 | 45 | teardown(cls.username, cls.password, cls.repo_dir) |
44 | 46 |
|
45 | | - def test_app_create(self): |
| 47 | + def test_create(self): |
| 48 | + # create the app |
46 | 49 | self.assertIsNotNone(self.formation) |
| 50 | + child = pexpect.spawn("{} create --formation={}".format( |
| 51 | + DEIS, self.formation)) |
| 52 | + child.expect('done, created (?P<name>[-_\w]+)') |
| 53 | + app = child.match.group('name') |
| 54 | + child.expect('Git remote deis added') |
| 55 | + child.expect(pexpect.EOF) |
| 56 | + # check that it's in the list of apps |
| 57 | + child = pexpect.spawn("{} apps".format(DEIS)) |
| 58 | + child.expect('=== Apps') |
| 59 | + child.expect(pexpect.EOF) |
| 60 | + apps = re.findall(r'([-_\w]+) {\w?}', child.before) |
| 61 | + self.assertIn(app, apps) |
| 62 | + # destroy the app |
| 63 | + child = pexpect.spawn("{} apps:destroy --confirm={}".format(DEIS, app)) |
| 64 | + child.expect('Git remote deis removed') |
| 65 | + child.expect(pexpect.EOF) |
| 66 | + |
| 67 | + def test_destroy(self): |
| 68 | + # create the app |
| 69 | + self.assertIsNotNone(self.formation) |
| 70 | + child = pexpect.spawn("{} apps:create --formation={}".format( |
| 71 | + DEIS, self.formation)) |
| 72 | + child.expect('done, created ([-_\w]+)') |
| 73 | + app = child.match.group(1) |
| 74 | + child.expect(pexpect.EOF) |
| 75 | + # check that it's in the list of apps |
| 76 | + child = pexpect.spawn("{} apps".format(DEIS)) |
| 77 | + child.expect('=== Apps') |
| 78 | + child.expect(pexpect.EOF) |
| 79 | + apps = re.findall(r'([-_\w]+) {\w?}', child.before) |
| 80 | + self.assertIn(app, apps) |
| 81 | + # destroy the app |
| 82 | + child = pexpect.spawn("{} destroy --confirm={}".format(DEIS, app)) |
| 83 | + child.expect("Destroying {}".format(app)) |
| 84 | + child.expect('done in \d+s') |
| 85 | + child.expect('Git remote deis removed') |
| 86 | + child.expect(pexpect.EOF) |
| 87 | + |
| 88 | + def test_list(self): |
| 89 | + # list apps and get their names |
| 90 | + child = pexpect.spawn("{} apps".format(DEIS)) |
| 91 | + child.expect('=== Apps') |
| 92 | + child.expect(pexpect.EOF) |
| 93 | + apps_before = re.findall(r'([-_\w]+) {\w?}', child.before) |
| 94 | + # create a new app |
| 95 | + self.assertIsNotNone(self.formation) |
| 96 | + child = pexpect.spawn("{} apps:create --formation={}".format( |
| 97 | + DEIS, self.formation)) |
| 98 | + child.expect('done, created ([-_\w]+)') |
| 99 | + app = child.match.group(1) |
| 100 | + child.expect(pexpect.EOF) |
| 101 | + # list apps and get their names |
| 102 | + child = pexpect.spawn("{} apps".format(DEIS)) |
| 103 | + child.expect('=== Apps') |
| 104 | + child.expect(pexpect.EOF) |
| 105 | + apps = re.findall(r'([-_\w]+) {\w?}', child.before) |
| 106 | + # test that the set of names contains the previous set |
| 107 | + self.assertLess(set(apps_before), set(apps)) |
| 108 | + # delete the app |
| 109 | + child = pexpect.spawn("{} apps:destroy --app={} --confirm={}".format( |
| 110 | + DEIS, app, app)) |
| 111 | + child.expect('done in ', timeout=5*60) |
| 112 | + child.expect(pexpect.EOF) |
| 113 | + # list apps and get their names |
| 114 | + child = pexpect.spawn("{} apps:list".format(DEIS)) |
| 115 | + child.expect('=== Apps') |
| 116 | + child.expect(pexpect.EOF) |
| 117 | + apps = re.findall(r'([-_\w]+) {\w?}', child.before) |
| 118 | + # test that the set of names is equal to the original set |
| 119 | + self.assertEqual(set(apps_before), set(apps)) |
| 120 | + |
| 121 | + def test_info(self): |
| 122 | + # create a new app |
| 123 | + self.assertIsNotNone(self.formation) |
| 124 | + child = pexpect.spawn("{} create --formation={}".format( |
| 125 | + DEIS, self.formation)) |
| 126 | + child.expect('done, created (?P<name>[-_\w]+)') |
| 127 | + app = child.match.group('name') |
| 128 | + child.expect('Git remote deis added') |
| 129 | + child.expect(pexpect.EOF) |
| 130 | + # get app info |
| 131 | + child = pexpect.spawn("{} info".format(DEIS)) |
| 132 | + child.expect("=== {} Application".format(app)) |
| 133 | + child.expect("=== {} Containers".format(app)) |
| 134 | + response = json.loads(child.before) |
| 135 | + child.expect(pexpect.EOF) |
| 136 | + self.assertEqual(response['id'], app) |
| 137 | + self.assertEqual(response['formation'], self.formation) |
| 138 | + self.assertEqual(response['owner'], self.username) |
| 139 | + self.assertIn('uuid', response) |
| 140 | + self.assertIn('created', response) |
| 141 | + self.assertIn('containers', response) |
| 142 | + # delete the app |
| 143 | + child = pexpect.spawn("{} apps:destroy --app={} --confirm={}".format( |
| 144 | + DEIS, app, app)) |
| 145 | + child.expect('done in ', timeout=5*60) |
| 146 | + child.expect(pexpect.EOF) |
| 147 | + |
| 148 | + # def test_calculate(self): |
| 149 | + # pass |
| 150 | + |
| 151 | + # def test_open(self): |
| 152 | + # pass |
| 153 | + |
| 154 | + # def test_logs(self): |
| 155 | + # pass |
| 156 | + |
| 157 | + # def test_run(self): |
| 158 | + # pass |
0 commit comments