Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@istest
def installs_a_package_if_its_not_installed_yet_by_name_and_version(self):
with self.execute_mock() as execute, self.mock_role_method('is_package_installed') as is_package_installed:
is_package_installed.return_value = False
self.role.ensure_package_installed('runit', '123')
execute.assert_called_with('gem install runit(123)', sudo=True, stdout=False)
@istest
def sets_session_id_on_cookies(self):
test_case = self
class StubHandler(SessionMixin):
settings = {
'pycket': {
'engine': 'redis',
}
}
def get_secure_cookie(self, name):
test_case.assertEqual(name, 'PYCKET_ID')
self.cookie_set = True
return None
def set_secure_cookie(self, name, value, expires_days, expires):
@istest
def creates_a_profile_with_read_and_write_permissions(self):
with self.execute_mock() as execute:
self.role.create('/some/bin', read_and_write=['/var/log/somebin.log', '/srv/somebin/'])
execute.assert_called_with('aa-easyprof -w /var/log/somebin.log -w /srv/somebin/ /some/bin', stdout=False, sudo=True)
@istest
def installs_necessary_packages_to_provision(self):
with self.using_stub(AptitudeRole) as aptitude, self.execute_mock():
self.role.provision()
aptitude.ensure_package_installed.assert_any_call('iptables')
@istest
def libc_version_is_derived_from_getconf_gnu_libc_version():
platform = _generate_platform()
assert_equal(platform.libc, "glibc-2.13")
@istest
def gets_none_as_last_update_if_there_was_no_update_yet(self):
with self.mock_role_methods('remote_exists', 'update_date_file', 'read_remote_file'):
self.role.update_date_file = '/foo/bar'
self.role.remote_exists.return_value = False
result = self.role.get_last_update_date()
self.assertIsNone(result)
self.assertFalse(self.role.read_remote_file.called)
@istest
def gets_provyfile_path_from_args(self):
existing_file = 'path/to/provyfile.py'
with patch.object(os.path, 'exists') as exists:
exists.return_value = True
self.assertEqual(provyfile_path_from(args=[existing_file]), existing_file)
@istest
def schedules_cleanup_when_provisioning(self):
role_instance = MagicMock()
def StubRole(prov, context):
return role_instance
self.role.provision_role(StubRole)
role_instance.schedule_cleanup.assert_called_with()
@istest
def gets_empty_user_hosts(self):
with self.execute_mock() as execute:
execute.return_value = ''
hosts = self.role.get_user_hosts('root')
self.assertEqual(hosts, [])
execute.assert_called_with('''mysql -u root -E -e "select Host from mysql.user where LOWER(User)='root'" mysql''',
sudo=True, stdout=False)
@istest
def restart_if_necessary_upon_cleanup(self):
self.role.context['must-restart-nginx'] = True
with self.mock_role_method('restart'):
self.role.cleanup()
self.assertTrue(self.role.restart.called)