"""Views tests."""

from django.urls import reverse

from modoboa.admin import factories as admin_factories
from modoboa.core import models as core_models
from modoboa.lib.tests import ModoTestCase

from . import mixins


class DMARCViewsTestCase(mixins.CallCommandMixin, ModoTestCase):
    """Views test cases."""

    @classmethod
    def setUpTestData(cls):
        """Create test data."""
        super(DMARCViewsTestCase, cls).setUpTestData()
        cls.domain = admin_factories.DomainFactory(name="ngyn.org")

    def test_domainlist_view(self):
        """Test domain list view."""
        self.import_reports()
        user = core_models.User.objects.get(username="admin")
        self.client.force_login(user)
        url = reverse("admin:_domain_list")
        response = self.ajax_get(url)
        url = reverse("modoboa_dmarc:domain_report", args=[self.domain.pk])
        self.assertIn(url, response["rows"])

    def test_domainreport_view(self):
        """Test domain report view."""
        self.import_reports()
        user = core_models.User.objects.get(username="admin")
        self.client.force_login(user)
        url = reverse("modoboa_dmarc:domain_report", args=[self.domain.pk])
        response = self.client.get("{}?period=2015-26".format(url))
        self.assertContains(response, "'Failed', 100.0")

@@ -1325,8 +1325,835 @@
 100.0%22)%0A
+%0A    def test_domainreport_view_week0(self):%0A        %22%22%22Test domain report view.%22%22%22%0A        self.import_reports()%0A        user = core_models.User.objects.get(username=%22admin%22)%0A        self.client.force_login(user)%0A        url = reverse(%22modoboa_dmarc:domain_report%22, args=%5Bself.domain.pk%5D)%0A        response = self.client.get(%22%7B%7D?period=2019-0%22.format(url))%0A        self.assertContains(response, %22Dec. 31, 2018%22)%0A%0A    def test_domainreport_view_week52(self):%0A        %22%22%22Test domain report view.%22%22%22%0A        self.import_reports()%0A        user = core_models.User.objects.get(username=%22admin%22)%0A        self.client.force_login(user)%0A        url = reverse(%22modoboa_dmarc:domain_report%22, args=%5Bself.domain.pk%5D)%0A        response = self.client.get(%22%7B%7D?period=2018-52%22.format(url))%0A        self.assertContains(response, %22Dec. 30, 2018%22)%0A%0A

add unit tests for first and last weeknum