This commit is contained in:
j3d1 2024-06-15 19:27:20 +02:00
parent 39ce06d180
commit 9c3fedc5c3
3 changed files with 43 additions and 1 deletions

View file

@ -29,7 +29,7 @@ class StateSerializer(serializers.Serializer):
return obj['value']
class ShippingCodeSerializer(serializers.Serializer):
class ShippingCodeSerializer(serializers.ModelSerializer):
class Meta:
model = ShippingCode
fields = ('id', 'code', 'timestamp', 'issue_thread', 'used_at')

View file

@ -0,0 +1,32 @@
from datetime import datetime, timedelta
from django.test import TestCase, Client
from authentication.models import ExtendedUser
from mail.models import Email, EmailAttachment
from tickets.models import IssueThread, StateChange, Comment
from django.contrib.auth.models import Permission
from knox.models import AuthToken
class ShippingCodeApiTest(TestCase):
def setUp(self):
super().setUp()
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
self.user.user_permissions.add(*Permission.objects.all())
self.user.save()
self.token = AuthToken.objects.create(user=self.user)
self.client = Client(headers={'Authorization': 'Token ' + self.token[1]})
def test_issues_empty(self):
response = self.client.get('/api/2/shipping_codes/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
def test_issues_create(self):
response = self.client.post('/api/2/shipping_codes/', {'code': '1234'})
self.assertEqual(response.status_code, 201)
self.assertEqual(response.json()['code'], '1234')
self.assertEqual(response.json()['used_at'], None)
self.assertEqual(response.json()['issue_thread'], None)

View file

@ -247,6 +247,16 @@ class IssueApiTest(TestCase):
self.assertEqual(timeline[1]['subject'], 'test issue')
self.assertEqual(timeline[1]['body'], 'test')
#def test_post_comment(self):
# issue = IssueThread.objects.create(
# name="test issue",
# )
# response = self.client.post('/api/2/comments/', {'comment': 'test', 'issue_thread': issue.id})
# self.assertEqual(response.status_code, 201)
# self.assertEqual(response.json()['comment'], 'test')
# self.assertEqual(response.json()['issue_thread'], issue.id)
# self.assertEqual(response.json()['timestamp'], response.json()['timestamp'])
def test_post_comment_altenative(self):
issue = IssueThread.objects.create(
name="test issue",