import pytest
from django.urls import reverse
from rest_framework import status

from ncircc.models.notification import Notification
from notifications.models import Notification
from notifications.services.notification_sender import NotificationService


@pytest.mark.django_db
@pytest.mark.unit
class TestNotificationsService:
    """Test Notifications API"""

    @pytest.fixture(autouse=True)
    def setup_test(self, add_user_with_permissions, django_user_model):
        self.admin = django_user_model.objects.get()
        self.user = add_user_with_permissions(username='test_user', password='TesTPasWord1', is_superuser=True)
        self.notification = Notification.objects.create(text='Notification')

    def test_create_notification_with_data(self, api_client):
        assert Notification.objects.count() == 1
        api_client.force_authenticate(self.admin)
        NotificationService().send(data={'text': 'test notification'})
        url = reverse('notifications-list')

        response = api_client.get(url)
        assert response.status_code == status.HTTP_200_OK
        assert response.json()['count'] == 2

        assert response.json()['results'][1]['text'] == 'test notification'
