-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathtest_cf_ignore.py
More file actions
51 lines (41 loc) · 2.38 KB
/
test_cf_ignore.py
File metadata and controls
51 lines (41 loc) · 2.38 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
import os
from unittest import TestCase
from unittest.mock import mock_open, patch
from cloudfoundry_client.operations.push.cf_ignore import CfIgnore
class TestCfIgnore(TestCase):
def test_open_cfignore_file(self):
with patch("builtins.open", mock_open(read_data="*.log")) as mock_file, patch(
"os.path.isfile", create=True
) as mock_isfile:
mock_isfile.__return_value__ = True
application_path = "/some/path"
CfIgnore(application_path)
mock_file.assert_called_with(os.path.join(application_path, ".cfignore"), "r")
def test_ignore_wildcard_resources(self):
with patch("builtins.open", mock_open(read_data="*.log")), patch("os.path.isfile", create=True) as mock_isfile:
mock_isfile.__return_value__ = True
cf_ignore = CfIgnore("/some/path")
self.assertTrue(cf_ignore.is_entry_ignored("toto.log"))
self.assertTrue(cf_ignore.is_entry_ignored("/some/other/path/toto.log"))
def test_ignore_directory(self):
with patch("builtins.open", mock_open(read_data="ignored/directory/")), patch(
"os.path.isfile", create=True
) as mock_isfile:
mock_isfile.__return_value__ = True
cf_ignore = CfIgnore("/some/path")
self.assertTrue(cf_ignore.is_entry_ignored("ignored/directory/resource.file"))
self.assertTrue(cf_ignore.is_entry_ignored("/ignored/directory/resource.file"))
self.assertTrue(cf_ignore.is_entry_ignored("/some/sub/directory/containing/ignored/directory/resource.file"))
# File in fact
self.assertFalse(cf_ignore.is_entry_ignored("/ignored/directory"))
def test_ignore_file_with_directory(self):
with patch("builtins.open", mock_open(read_data="ignored/directory/resource.file")), patch(
"os.path.isfile", create=True
) as mock_isfile:
mock_isfile.__return_value__ = True
cf_ignore = CfIgnore("/some/path")
self.assertTrue(cf_ignore.is_entry_ignored("ignored/directory/resource.file"))
self.assertTrue(cf_ignore.is_entry_ignored("/ignored/directory/resource.file"))
self.assertTrue(cf_ignore.is_entry_ignored("/some/sub/directory/containing/ignored/directory/resource.file"))
# File in fact
self.assertFalse(cf_ignore.is_entry_ignored("ignored/resource.file"))