-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathtest_push.py
More file actions
68 lines (57 loc) · 2.58 KB
/
test_push.py
File metadata and controls
68 lines (57 loc) · 2.58 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
import sys
from unittest import TestCase
from unittest.mock import patch, MagicMock
import cloudfoundry_client.main.main as main
from abstract_test_case import AbstractTestCase
from cloudfoundry_client.operations.push.push import PushOperation
class TestPushOperation(TestCase, AbstractTestCase):
@classmethod
def setUpClass(cls):
cls.mock_client_class()
def setUp(self):
self.build_client()
def test_split_route_with_port_and_path(self):
domain, port, path = PushOperation._split_route(dict(route="foo-((suffix)).apps.internal:666/some/path"))
self.assertEqual("foo-((suffix)).apps.internal", domain)
self.assertEqual(666, port)
self.assertEqual("/some/path", path)
def test_split_route_without_port_and_path(self):
domain, port, path = PushOperation._split_route(dict(route="foo-((suffix)).apps.internal"))
self.assertEqual("foo-((suffix)).apps.internal", domain)
self.assertIsNone(port)
self.assertEqual("", path)
def test_split_route_without_port_path(self):
domain, port, path = PushOperation._split_route(dict(route="foo-((suffix)).apps.internal/path"))
self.assertEqual("foo-((suffix)).apps.internal", domain)
self.assertIsNone(port)
self.assertEqual("/path", path)
def test_split_route_without_path(self):
domain, port, path = PushOperation._split_route(dict(route="foo-((suffix)).apps.internal:666"))
self.assertEqual("foo-((suffix)).apps.internal", domain)
self.assertEqual(666, port)
self.assertEqual("", path)
def test_to_host_should_remove_unwanted_characters(self):
host = PushOperation._to_host("idzone-3.0.7-rec-tb1_bobby")
self.assertEqual("idzone-307-rec-tb1-bobby", host)
@patch.object(
sys,
"argv",
[
"main",
"push_app",
AbstractTestCase.get_fixtures_path("fake", "operations", "manifest_main.yml"),
"-space_guid",
"space_id"
],
)
def test_main_push(self):
class FakeOperation(object):
def __init__(self):
self.push = MagicMock()
client = object()
push_operation = FakeOperation()
with patch("cloudfoundry_client.main.main.build_client_from_configuration", new=lambda: client), patch(
"cloudfoundry_client.main.operation_commands.PushOperation", new=lambda c: push_operation
):
main.main()
push_operation.push.assert_called_with("space_id", self.get_fixtures_path("fake", "operations", "manifest_main.yml"))