Esempio n. 1
0
def test_files_has_been_entangled_enough(monkeypatch):
    with mock.patch("socket.gethostbyname", return_value="127.0.0.1"):
        files = Files()
    monkeypatch.setattr(FakeRedisPipeline, "execute", mock_pipeline_get_block)
    monkeypatch.setattr(files.redis, "pipeline", get_me_a_fake_redis_pipeline)
    assert files.has_been_entangled_enough("path", 0) is True
    assert files.has_been_entangled_enough("path", 1) is True
    assert files.has_been_entangled_enough("path", 2) is False
Esempio n. 2
0
def test_files_has_been_entangled_enough_raises_ValueError_if_block_key_is_None():
    with mock.patch("socket.gethostbyname", return_value="127.0.0.1"):
        files = Files()
    with pytest.raises(ValueError, match="path argument must be a valid non-empty string"):
        files.has_been_entangled_enough(None, 1)
Esempio n. 3
0
def test_files_has_been_entangled_enough_raises_KeyError_if_block_key_does_not_match_any_existing_key(monkeypatch):
    with mock.patch("socket.gethostbyname", return_value="127.0.0.1"):
        files = Files()
    monkeypatch.setattr(files.redis, "pipeline", get_me_a_fake_redis_pipeline)
    with pytest.raises(KeyError, match="key {:s} not found".format("NonExistingKey")):
        files.has_been_entangled_enough("NonExistingKey", 2)
Esempio n. 4
0
def test_files_has_been_entangled_enough_raises_ValueError_if_pointers_is_lower_than_0():
    with mock.patch("socket.gethostbyname", return_value="127.0.0.1"):
        files = Files()
    with pytest.raises(ValueError, match="pointers argument must be a valid integer greater or equal to 0"):
        files.has_been_entangled_enough("path", -1)