Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
"""Create fake filesystem."""
self.setUpPyfakefs()
self.fake_os = fake_filesystem.FakeOsModule(self.fs)
populate_fakefs(self)
osd.__salt__ = {}
osd.__salt__['helper.run'] = mock.Mock()
osd.__salt__['helper.run'].return_value = ('', '/dev/disk/by-id/wwn-0x12345-part1', '')
result = osd.readlink("/dev/disk/by-id/wwn-0x12345-part1")
assert result == "/dev/disk/by-id/wwn-0x12345-part1"
@pytest.mark.skip(reason="Low priority: skipped")
class TetstOSDState():
pass
fs = fake_fs.FakeFilesystem()
f_glob = fake_glob.FakeGlobModule(fs)
f_os = fake_fs.FakeOsModule(fs)
f_open = fake_fs.FakeFileOpen(fs)
class TestOSDWeight():
"""
Initial checks for the wait method. Override the __init__ funciton to
avoid the rados logic. Set osd_id and settings directly.
"""
@patch('builtins.open', new=f_open)
@patch('srv.salt._modules.osd.OSDWeight.osd_df')
def test_save_defaults(self, osd_df):
"""
No files created with default values
"""
osd_df.return_value = {'crush_weight': 0,
'reweight': 1.0}
def setUp(self):
self.cwd = os.getcwd()
if not self.use_real_fs():
self.filesystem = fake_filesystem.FakeFilesystem(
path_separator=self.path_separator())
self.open = fake_filesystem.FakeFileOpen(self.filesystem)
self.os = fake_filesystem.FakeOsModule(self.filesystem)
self.create_basepath()
self.setUpFileSystem()
def test_creates_filesystem_when_requested(self):
with dependency_context(supply_fs=True) as context:
expect(context.fs).to(be_a(fakefs.FakeFilesystem))
mock.Mock(ok=True,
content=json.dumps({'sha': 'main-tree-sha'})),
mock.Mock(ok=True,
content=json.dumps({'sha': 'util-tree-sha'})),
mock.Mock(ok=True,
content=json.dumps({'sha': 'root-tree-sha'})),
mock.Mock(ok=True,
content=json.dumps({'sha': 'fake-commit-sha'}))]
_PATCH_RETURN_VAL = mock.Mock(ok=True, content=json.dumps({}))
fs = fake_fs.FakeFilesystem()
fs.CreateFile('/main/subdir/blank.txt')
fs.CreateFile('/main/hello.txt', contents='hello local\n')
# mark executable.py as an executable
fs.CreateFile('/util/executable.py', contents='#!/usr/bin/env python\n',
st_mode=stat.S_IFREG | fake_fs.PERM_DEF_FILE | fake_fs.PERM_EXE)
os_module = fake_fs.FakeOsModule(fs)
@mock.patch.object(github_utils, 'open', side_effect=fake_fs.FakeFileOpen(fs))
@mock.patch('os.access', side_effect=os_module.access)
@mock.patch('os.path.isfile', side_effect=os_module.path.isfile)
@mock.patch('os.path.isdir', side_effect=os_module.path.isdir)
@mock.patch('os.listdir', side_effect=os_module.listdir)
@mock.patch('requests.patch', return_value=_PATCH_RETURN_VAL)
@mock.patch('requests.post', side_effect=_POST_SIDE_EFFECT)
@mock.patch('requests.get', side_effect=_GET_SIDE_EFFECT)
def test_github_utils_task(mock_get, mock_post, mock_patch, mock_listdir,
mock_isdir, mock_isfile, mock_access, mock_open):
github_utils.push_dir_to_github('/', _USERNAME, _PASSWORD, _OWNER,
_REPO, _BRANCH, _MESSAGE)
mock_get.assert_has_calls(_EXPECTED_GET_ARGS)
mock_post.assert_has_calls(_EXPECTED_POST_ARGS)
def set_resolution(ctx, res):
res_data = get_display_config(res)
ctx.new_res = res_data
'''
# FIXME: Don't do this manually
with open(BOOT_CONFIG_FILEPATH, 'a') as f:
f.write('{}\n'.format(res_data.get('group_line')))
f.write('{}\n'.format(res_data.get('mode_line')))
'''
display.set_hdmi_mode(group=res_data['group'], mode=res_data['mode'])
with mock.patch('os.open'):
with mock.patch('pyfakefs.fake_filesystem.FakeOsModule.open', spec=fake_fs.FakeOsModule.open) as fake_open:
print(fake_open)
boot_config.end_config_transaction()
def get_fake_fs():
fs = fake_fs.FakeFilesystem()
fs.CreateDirectory('/usr/share/kano-settings/media')
return fs