Exemple #1
0
    def test__delete_credential_nonexistent(self):
        multistore = multistore_file._MultiStore(FILENAME)

        with mock.patch.object(multistore, '_write') as write_mock:
            multistore._data = {}
            multistore._delete_credential('nonexistent_key')
            self.assertTrue(write_mock.called)
    def test__delete_credential_nonexistent(self):
        multistore = multistore_file._MultiStore(FILENAME)

        with mock.patch.object(multistore, '_write') as write_mock:
            multistore._data = {}
            multistore._delete_credential('nonexistent_key')
            self.assertTrue(write_mock.called)
    def test_read_only_file_fail_lock_no_warning(self):
        open(FILENAME, 'a+b').close()
        os.chmod(FILENAME, 0o400)

        multistore = multistore_file._MultiStore(FILENAME)

        with mock.patch.object(multistore_file.logger, 'warn') as mock_warn:
            multistore._warn_on_readonly = False
            multistore._lock()
            self.assertFalse(mock_warn.called)
Exemple #4
0
    def test_read_only_file_fail_lock_no_warning(self):
        open(FILENAME, 'a+b').close()
        os.chmod(FILENAME, 0o400)

        multistore = multistore_file._MultiStore(FILENAME)

        with mock.patch.object(multistore_file.logger, 'warn') as mock_warn:
            multistore._warn_on_readonly = False
            multistore._lock()
            self.assertFalse(mock_warn.called)
    def test_lock_file_raise_unexpected_error(self):
        filehandle, filename = tempfile.mkstemp()
        os.close(filehandle)

        try:
            multistore = multistore_file._MultiStore(filename)
            multistore._file = _MockLockedFile(filename, errno.EBUSY)
            self.assertRaises(IOError, multistore._lock)
            self.assertTrue(multistore._file.open_and_lock_called)
        finally:
            os.unlink(filename)
Exemple #6
0
    def test_lock_file_raise_unexpected_error(self):
        filehandle, filename = tempfile.mkstemp()
        os.close(filehandle)

        try:
            multistore = multistore_file._MultiStore(filename)
            multistore._file = _MockLockedFile(filename, errno.EBUSY)
            self.assertRaises(IOError, multistore._lock)
            self.assertTrue(multistore._file.open_and_lock_called)
        finally:
            os.unlink(filename)
Exemple #7
0
    def test_lock_skip_refresh(self):
        with open(FILENAME, 'w') as f:
            f.write('123')
        os.chmod(FILENAME, 0o400)

        multistore = multistore_file._MultiStore(FILENAME)

        refresh_patch = mock.patch.object(multistore, '_refresh_data_cache')

        with refresh_patch as refresh_mock:
            multistore._data = {}
            multistore._lock()
            self.assertFalse(refresh_mock.called)
Exemple #8
0
    def test_lock_file_raises_ioerror(self):
        filehandle, filename = tempfile.mkstemp()
        os.close(filehandle)

        try:
            for error_code in (errno.EDEADLK, errno.ENOSYS, errno.ENOLCK):
                multistore = multistore_file._MultiStore(filename)
                multistore._file = _MockLockedFile(filename, error_code)
                # Should not raise even though the underlying file class did.
                multistore._lock()
                self.assertTrue(multistore._file.open_and_lock_called)
        finally:
            os.unlink(filename)
    def test_lock_skip_refresh(self):
        with open(FILENAME, 'w') as f:
            f.write('123')
        os.chmod(FILENAME, 0o400)

        multistore = multistore_file._MultiStore(FILENAME)

        refresh_patch = mock.patch.object(
            multistore, '_refresh_data_cache')

        with refresh_patch as refresh_mock:
            multistore._data = {}
            multistore._lock()
            self.assertFalse(refresh_mock.called)
    def _refresh_data_cache_helper(self):
        multistore = multistore_file._MultiStore(FILENAME)
        json_patch = mock.patch.object(multistore, '_locked_json_read')

        return multistore, json_patch
Exemple #11
0
    def _refresh_data_cache_helper(self):
        multistore = multistore_file._MultiStore(FILENAME)
        json_patch = mock.patch.object(multistore, '_locked_json_read')

        return multistore, json_patch