From 9c3fedc5c3f05e87180daedaa291c467a3f41b4e Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 15 Jun 2024 19:27:20 +0200 Subject: [PATCH] stash --- core/tickets/serializers.py | 2 +- core/tickets/tests/v2/test_shipping_codes.py | 32 ++++++++++++++++++++ core/tickets/tests/v2/test_tickets.py | 10 ++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 core/tickets/tests/v2/test_shipping_codes.py diff --git a/core/tickets/serializers.py b/core/tickets/serializers.py index 6625a81..c1576f8 100644 --- a/core/tickets/serializers.py +++ b/core/tickets/serializers.py @@ -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') diff --git a/core/tickets/tests/v2/test_shipping_codes.py b/core/tickets/tests/v2/test_shipping_codes.py new file mode 100644 index 0000000..7c64460 --- /dev/null +++ b/core/tickets/tests/v2/test_shipping_codes.py @@ -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) diff --git a/core/tickets/tests/v2/test_tickets.py b/core/tickets/tests/v2/test_tickets.py index 8223506..0fea3dc 100644 --- a/core/tickets/tests/v2/test_tickets.py +++ b/core/tickets/tests/v2/test_tickets.py @@ -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",