import pytest

from devices.filters import DeviceFilter
from devices.models.device import Device

device_filter_query_parameters = [
    [{'name': 'FIREWALL'}, 1],
    [{'name': 'test'}, 2],
    [{'name': 'device'}, 0],
    [{'ip': '1.1.1.1'}, 1],
    [{'type': 'firewall'}, 3],
]


@pytest.mark.unit
@pytest.mark.django_db
class TestDevices:

    @pytest.fixture(autouse=True)
    def setup_tests(self, django_user_model):
        self.admin_user = django_user_model.objects.get(username='admin')
        Device.objects.create(ip='1.1.1.1', port='1500', type='firewall', name='test')
        Device.objects.create(ip='1.1.1.0', port='11111', type='firewall', name='test')
        Device.objects.create(ip='2.2.2.2', port='2500', type='firewall', name='FIREWALL')
        Device.objects.create(ip='3.3.3.3', port='9999', type='endpoint', name='ENDPOINT')

    @pytest.mark.parametrize('query', device_filter_query_parameters)
    def test_filter_device_with_parameters(self, query):
        queryset = DeviceFilter(query[0], Device.objects.all()).qs
        assert queryset.count() == query[1]
