stash
This commit is contained in:
parent
6aaa522a6b
commit
ba427c7a84
25 changed files with 274 additions and 236 deletions
|
@ -1,16 +1,16 @@
|
|||
import inspect
|
||||
from unittest import mock
|
||||
from knox.models import AuthToken
|
||||
|
||||
from django.test import TestCase, Client
|
||||
|
||||
from authentication.models import ExtendedUser
|
||||
from core.settings import MAIL_DOMAIN
|
||||
from inventory.models import Event
|
||||
from mail.models import Email
|
||||
from mail.protocol import LMTPHandler
|
||||
from tickets.models import IssueThread
|
||||
|
||||
client = Client()
|
||||
|
||||
|
||||
def make_mocked_coro(return_value=mock.sentinel, raise_exception=mock.sentinel):
|
||||
async def mock_coro(*args, **kwargs):
|
||||
|
@ -25,6 +25,13 @@ def make_mocked_coro(return_value=mock.sentinel, raise_exception=mock.sentinel):
|
|||
|
||||
class EmailsApiTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
||||
self.user.save()
|
||||
self.token = AuthToken.objects.create(user=self.user)
|
||||
self.client = Client(headers={'Authorization': 'Token ' + self.token[1]})
|
||||
|
||||
def test_mails(self):
|
||||
Event.objects.get_or_create(
|
||||
name="Test event",
|
||||
|
@ -36,7 +43,7 @@ class EmailsApiTest(TestCase):
|
|||
sender='test',
|
||||
recipient='test',
|
||||
)
|
||||
response = client.get('/api/2/mails/')
|
||||
response = self.client.get('/api/2/mails/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(len(response.json()), 1)
|
||||
self.assertEqual(response.json()[0]['subject'], 'test')
|
||||
|
@ -45,13 +52,20 @@ class EmailsApiTest(TestCase):
|
|||
self.assertEqual(response.json()[0]['recipient'], 'test')
|
||||
|
||||
def test_mails_empty(self):
|
||||
response = client.get('/api/2/mails/')
|
||||
response = self.client.get('/api/2/mails/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json(), [])
|
||||
|
||||
|
||||
class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
||||
self.user.save()
|
||||
self.token = AuthToken.objects.create(user=self.user)
|
||||
self.client = Client(headers={'Authorization': 'Token ' + self.token[1]})
|
||||
|
||||
def test_handle_client(self):
|
||||
from aiosmtpd.smtp import Envelope
|
||||
from asgiref.sync import async_to_sync
|
||||
|
@ -156,8 +170,7 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
)
|
||||
import aiosmtplib
|
||||
aiosmtplib.send = make_mocked_coro()
|
||||
client = Client()
|
||||
response = client.post(f'/api/2/tickets/{issue_thread.id}/reply/', {
|
||||
response = self.client.post(f'/api/2/tickets/{issue_thread.id}/reply/', {
|
||||
'message': 'test'
|
||||
})
|
||||
self.assertEqual(response.status_code, 201)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue