import pytest

from assets.models.assets import Asset
from incident.filters import IncidentFilters
from incident.models import Incident


@pytest.mark.django_db
class TestIncidentFilters:
    """Test Incident filters"""

    @pytest.fixture(autouse=True)
    def setup_test(self):
        incident = Incident.objects.create(title=f'title_1', importance=10, event_count=10, events='',
                                           status=Incident.Status.NOT_ASSIGNED)
        Incident.objects.create(title=f'title_2', importance=10, event_count=10, events='',
                                status=Incident.Status.NOT_ASSIGNED)

        self.asset = Asset.objects.create(name='Asset 1', ip='127.0.0.1', status=Asset.AllowStatus.NEW,)
        self.asset.incidents.add(incident)

    @pytest.mark.unit
    def test_incident_filters_asset(self):
        incident_filter = IncidentFilters()
        queryset = Incident.objects.all()
        assert queryset.count() == 2
        filtered_data = incident_filter.assets_filter(queryset, name='assets', value=f'{self.asset.id},2,3')
        assert filtered_data.count() == 1
        filtered_data = incident_filter.assets_filter(queryset, name='assets', value=f'0')
        assert filtered_data.count() == 0
