Exemplo n.º 1
0
    def test_io(self):

        self.__reset_state()

        file_path = settings.MAINTENANCE_MODE_STATE_FILE_PATH

        val = io.read_file(file_path)
        self.assertEqual(val, '')

        # ensure overwrite instead of append
        io.write_file(file_path, 'test')
        io.write_file(file_path, 'test')
        io.write_file(file_path, 'test')
        val = io.read_file(file_path)
        self.assertEqual(val, 'test')
Exemplo n.º 2
0
    def test_io(self):

        self.__reset_state()

        file_path = settings.MAINTENANCE_MODE_STATE_FILE_PATH

        val = io.read_file(file_path)
        self.assertEqual(val, '')

        # ensure overwrite instead of append
        io.write_file(file_path, 'test')
        io.write_file(file_path, 'test')
        io.write_file(file_path, 'test')
        val = io.read_file(file_path)
        self.assertEqual(val, 'test')
Exemplo n.º 3
0
 def get_value(self):
     value = read_file(settings.MAINTENANCE_MODE_STATE_FILE_PATH, '0')
     value = value.strip()
     if value not in ['0', '1']:
         raise ValueError('state file content value is not 0|1')
     value = bool(int(value))
     return value
Exemplo n.º 4
0
def get_maintenance_mode():

    value = io.read_file(settings.MAINTENANCE_MODE_STATE_FILE_PATH, '0')

    if not value in ['0', '1']:
        raise ValueError('state file content value is not 0|1')

    value = bool(int(value))
    return value
Exemplo n.º 5
0
    def test_io_invalid_file_path(self):

        self.__reset_state()

        file_path = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ:/maintenance_mode_state.txt'

        val = io.write_file(file_path, 'test')
        self.assertFalse(val)

        val = io.read_file(file_path)
        self.assertEqual(val, '')
Exemplo n.º 6
0
def get_maintenance_mode():
    # If maintenance mode is defined in settings, it has priority.
    if settings.MAINTENANCE_MODE is not None:
        return settings.MAINTENANCE_MODE

    value = io.read_file(settings.MAINTENANCE_MODE_STATE_FILE_PATH, '0')

    if value not in ['0', '1']:
        raise ValueError('state file content value is not 0|1')

    value = bool(int(value))
    return value
 def get_value(self):
     value = read_file(settings.MAINTENANCE_MODE_STATE_FILE_PATH, '0')
     if value not in ['0', '1']:
         raise ValueError('state file content value is not 0|1')
     value = bool(int(value))
     return value