def test__get_backend(self):
        backend_one = multiprocess_file_storage._get_backend('file_a')
        backend_two = multiprocess_file_storage._get_backend('file_a')
        backend_three = multiprocess_file_storage._get_backend('file_b')

        self.assertIs(backend_one, backend_two)
        self.assertIsNot(backend_one, backend_three)
    def test__get_backend(self):
        backend_one = multiprocess_file_storage._get_backend('file_a')
        backend_two = multiprocess_file_storage._get_backend('file_a')
        backend_three = multiprocess_file_storage._get_backend('file_b')

        self.assertIs(backend_one, backend_two)
        self.assertIsNot(backend_one, backend_three)
 def test_acquire_lock_nonexistent_file(self):
     backend = multiprocess_file_storage._get_backend(self.filename)
     os.unlink(self.filename)
     backend._process_lock = mock.Mock()
     backend._process_lock.acquire.return_value = False
     backend.acquire_lock()
     self.assertIsNone(backend._file)
 def test_acquire_lock_nonexistent_file(self):
     backend = multiprocess_file_storage._get_backend(self.filename)
     os.unlink(self.filename)
     backend._process_lock = mock.Mock()
     backend._process_lock.acquire.return_value = False
     backend.acquire_lock()
     self.assertIsNone(backend._file)
    def test__refresh_predicate(self):
        backend = multiprocess_file_storage._get_backend(self.filename)

        credentials = _create_test_credentials()
        self.assertFalse(backend._refresh_predicate(credentials))

        credentials.invalid = True
        self.assertTrue(backend._refresh_predicate(credentials))

        credentials = _create_test_credentials(
            expiration=(
                datetime.datetime.utcnow() - datetime.timedelta(seconds=3600)))
        self.assertTrue(backend._refresh_predicate(credentials))
    def test__refresh_predicate(self):
        backend = multiprocess_file_storage._get_backend(self.filename)

        credentials = _create_test_credentials()
        self.assertFalse(backend._refresh_predicate(credentials))

        credentials.invalid = True
        self.assertTrue(backend._refresh_predicate(credentials))

        credentials = _create_test_credentials(
            expiration=(
                datetime.datetime.utcnow() - datetime.timedelta(seconds=3600)))
        self.assertTrue(backend._refresh_predicate(credentials))
 def test_release_lock_with_no_file(self):
     backend = multiprocess_file_storage._get_backend(self.filename)
     backend._file = None
     backend._read_only = True
     backend._thread_lock.acquire()
     backend.release_lock()
 def test__load_credentials_no_open_file(self):
     backend = multiprocess_file_storage._get_backend(self.filename)
     backend._credentials = mock.Mock()
     backend._credentials.update.side_effect = AssertionError()
     backend._load_credentials()
 def test_release_lock_with_no_file(self):
     backend = multiprocess_file_storage._get_backend(self.filename)
     backend._file = None
     backend._read_only = True
     backend._thread_lock.acquire()
     backend.release_lock()
 def test__load_credentials_no_open_file(self):
     backend = multiprocess_file_storage._get_backend(self.filename)
     backend._credentials = mock.Mock()
     backend._credentials.update.side_effect = AssertionError()
     backend._load_credentials()