cloud-build/tests/test_no_delete.py

52 lines
1.5 KiB
Python
Raw Normal View History

2020-05-06 16:03:06 +03:00
from pathlib import Path
from unittest import TestCase
from unittest import mock
import shutil
import tempfile
from cloud_build import CB
import tests.call as call
class TestNoDelete(TestCase):
def setUp(self):
self.data_dir = Path(tempfile.mkdtemp(prefix='cloud_build'))
self.images_dir = Path('/tmp/cloud-build-test_no_delete/')
self.images_dir.mkdir()
def tearDown(self):
shutil.rmtree(self.data_dir)
shutil.rmtree(self.images_dir)
@mock.patch('subprocess.call', call.Call())
def test_no_delete_false(self):
cb = CB(
config='tests/test_no_delete_false.yaml',
data_dir=self.data_dir,
)
other_file = self.images_dir / 'other_file.txt'
other_file.write_text('Some text')
2021-04-10 01:03:47 +03:00
cb.create_images(no_tests=True)
cb.sync(create_remote_dirs=True)
2020-05-06 16:03:06 +03:00
del cb
msg = 'Other files shoud be deleted if not no_delete'
if other_file.exists():
self.fail(msg)
@mock.patch('subprocess.call', call.Call())
def test_no_delete_true(self):
cb = CB(
config='tests/test_no_delete_true.yaml',
data_dir=self.data_dir,
)
other_file = self.images_dir / 'other_file.txt'
other_file.write_text('Some text')
2021-04-10 01:03:47 +03:00
cb.create_images(no_tests=True)
cb.sync(create_remote_dirs=True)
2020-05-06 16:03:06 +03:00
del cb
msg = 'Other files shoud not be deleted if no_delete'
if not other_file.exists():
self.fail(msg)