from ddt import data, ddt
from django.core import mail
from django.urls import reverse
from rest_framework import status, test

from waldur_core.core.tests.helpers import override_waldur_core_settings
from waldur_core.logging import loggers, models, tasks
from waldur_core.logging.tests.factories import WebHookFactory
from waldur_core.structure.tests import factories as structure_factories
from waldur_core.structure.tests import fixtures as structure_fixtures

from . import factories


class BaseHookApiTest(test.APITransactionTestCase):
    def setUp(self):
        self.staff = structure_factories.UserFactory(is_staff=True)
        self.author = structure_factories.UserFactory()
        self.other_user = structure_factories.UserFactory()

        self.valid_event_types = loggers.get_valid_events()[:3]
        self.valid_event_groups = loggers.get_event_groups_keys()[:3]


class HookCreationViewTest(BaseHookApiTest):
    def test_user_can_create_webhook(self):
        self.client.force_authenticate(user=self.author)
        response = self.client.post(
            WebHookFactory.get_list_url(),
            data={
                'event_types': self.valid_event_types,
                'destination_url': 'http://example.com/',
            },
        )
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)

    def test_user_can_create_email_hook(self):