Ejemplo n.º 1
0
def test_is_container_in_somelist_whitelist(monkeypatch):
    def new_init(self):
        self.is_whitelist = True
        self.is_blacklist = False
        self._somelist = [
            {'host': 1, 'pod': 2, 'container': 3, 'ip': 4},
            {'host': 1},
            {'container': 3},
            {'pod': 2},
            {'ip': 4},
            {'ip': 4, 'pod': 2},
        ]
    monkeypatch.setattr(SomeList, '__init__', new_init)
    containers = [
        (1, 2, 3, 4),
        (1, 0, 0, 0),
        (0, 2, 0, 0),
        (0, 0, 3, 0),
        (0, 0, 0, 4),
        (0, 2, 0, 4),
    ]
    for c in containers:
        cnt = Container(*c)
        sl = SomeList()
        assert sl.is_container_in_somelist(cnt)
Ejemplo n.º 2
0
def test_somelist_is_container_allowed_negative(monkeypatch):
    def new_init(self):
        self.is_whitelist = True
        self.is_blacklist = False
    def new_is_container_in_somelist(self, cnt):
        return False

    monkeypatch.setattr(SomeList, '__init__', new_init)
    monkeypatch.setattr(
        SomeList, 'is_container_in_somelist', new_is_container_in_somelist)
    
    cnt = Container(1, 2, 3, 4)    
    sl = SomeList()
    assert not sl.is_container_allowed(cnt)
Ejemplo n.º 3
0
def test_somelist_is_list_enabled_negative():
    class FakeArgs:
        blacklist = ""
        whitelist = ""
    CONFIG.set_args(FakeArgs())

    sl = SomeList()
    scenarious = (
        (False, False, True),
        (True, False, False),
        (False, True, False),
    )
    for sc in scenarious:
        sl.is_blacklist = sc[0]
        sl.is_whitelist = sc[1]
        assert sl.is_list_enabled() != sc[2]
Ejemplo n.º 4
0
def test_somelist_impossible():
    class FakeArgs:
        blacklist = "/path"
        whitelist = "/path2"
    CONFIG.set_args(FakeArgs())

    with pytest.raises(SomeListMissuse):
        SomeList()