add migrations for state change

This commit is contained in:
j3d1 2023-12-28 21:20:49 +01:00
parent 626c9f23fe
commit fe9795d147
3 changed files with 59 additions and 20 deletions

View file

@ -86,24 +86,24 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
self.assertEqual(len(Email.objects.all()), 2) self.assertEqual(len(Email.objects.all()), 2)
self.assertEqual(len(IssueThread.objects.all()), 1) self.assertEqual(len(IssueThread.objects.all()), 1)
aiosmtplib.send.assert_called_once() aiosmtplib.send.assert_called_once()
self.assertEqual(Email.objects.all()[0].subject, 'test') self.assertEqual('test', Email.objects.all()[0].subject)
self.assertEqual(Email.objects.all()[0].sender, 'test1@test') self.assertEqual('test1@test', Email.objects.all()[0].sender)
self.assertEqual(Email.objects.all()[0].recipient, 'test2@test') self.assertEqual('test2@test', Email.objects.all()[0].recipient)
self.assertEqual(Email.objects.all()[0].body, 'test') self.assertEqual('test', Email.objects.all()[0].body)
self.assertEqual(Email.objects.all()[0].issue_thread, IssueThread.objects.all()[0]) self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[0].issue_thread)
self.assertEqual(Email.objects.all()[0].reference, '<1@test>') self.assertEqual('<1@test>', Email.objects.all()[0].reference)
self.assertEqual(Email.objects.all()[0].in_reply_to, None) self.assertEqual(None, Email.objects.all()[0].in_reply_to)
self.assertEqual(Email.objects.all()[1].subject, 'Message received') self.assertEqual('Message received', Email.objects.all()[1].subject)
self.assertEqual(Email.objects.all()[1].sender, 'test2@test') self.assertEqual('test2@test', Email.objects.all()[1].sender)
self.assertEqual(Email.objects.all()[1].recipient, 'test1@test') self.assertEqual('test1@test', Email.objects.all()[1].recipient)
self.assertEqual(Email.objects.all()[1].body, 'Thank you for your message.') self.assertEqual('Thank you for your message.', Email.objects.all()[1].body)
self.assertEqual(Email.objects.all()[1].issue_thread, IssueThread.objects.all()[0]) self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[1].issue_thread)
self.assertTrue(Email.objects.all()[1].reference.startswith("<")) self.assertTrue(Email.objects.all()[1].reference.startswith("<"))
self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>")) self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>"))
self.assertEqual(Email.objects.all()[1].in_reply_to, "<1@test>") self.assertEqual("<1@test>", Email.objects.all()[1].in_reply_to)
self.assertEqual(IssueThread.objects.all()[0].name, 'test') self.assertEqual('test', IssueThread.objects.all()[0].name)
self.assertEqual(IssueThread.objects.all()[0].state, 'new') self.assertEqual('pending_new', IssueThread.objects.all()[0].state)
self.assertEqual(IssueThread.objects.all()[0].assigned_to, None) self.assertEqual(None, IssueThread.objects.all()[0].assigned_to)
def test_handle_client_reply(self): def test_handle_client_reply(self):
issue_thread = IssueThread.objects.create( issue_thread = IssueThread.objects.create(
@ -149,7 +149,7 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
self.assertEqual(Email.objects.all()[2].reference, '<3@test>') self.assertEqual(Email.objects.all()[2].reference, '<3@test>')
self.assertEqual(Email.objects.all()[2].in_reply_to, mail1_reply.reference) self.assertEqual(Email.objects.all()[2].in_reply_to, mail1_reply.reference)
self.assertEqual(IssueThread.objects.all()[0].name, 'test') self.assertEqual(IssueThread.objects.all()[0].name, 'test')
self.assertEqual(IssueThread.objects.all()[0].state, 'new') self.assertEqual(IssueThread.objects.all()[0].state, 'pending_new')
self.assertEqual(IssueThread.objects.all()[0].assigned_to, None) self.assertEqual(IssueThread.objects.all()[0].assigned_to, None)
def test_mail_reply(self): def test_mail_reply(self):

View file

@ -0,0 +1,39 @@
# Generated by Django 4.2.7 on 2023-12-28 20:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tickets', '0002_alter_issuethread_options_and_more'),
]
def convert_state(apps, schema_editor):
IssueThread = apps.get_model('tickets', 'IssueThread')
for issue in IssueThread.objects.all():
if issue.state == 'new':
issue.state = 'pending_new'
issue.save()
StateChange = apps.get_model('tickets', 'StateChange')
for change in StateChange.objects.all():
if change.state == 'new':
change.state = 'pending_new'
change.save()
operations = [
migrations.AlterField(
model_name='issuethread',
name='state',
field=models.CharField(
choices=[('pending_new', 'New'), ('pending_open', 'Open'), ('pending_shipping', 'Needs to be shipped'),
('pending_physical_confirmation', 'Needs to be confirmed physically'),
('pending_return', 'Needs to be returned'), ('waiting_details', 'Waiting for details'),
('waiting_pre_shipping', 'Waiting for Address/Shipping Info'),
('closed_returned', 'Closed: Returned'), ('closed_shipped', 'Closed: Shipped'),
('closed_not_found', 'Closed: Not found'),
('closed_not_our_problem', 'Closed: Not our problem'),
('closed_duplicate', 'Closed: Duplicate'), ('closed_timeout', 'Closed: Timeout'),
('closed_spam', 'Closed: Spam')], default='pending_new', max_length=32, verbose_name='state'),
),
migrations.RunPython(convert_state),
]

View file

@ -39,7 +39,7 @@ class IssueApiTest(TestCase):
) )
state = StateChange.objects.create( state = StateChange.objects.create(
issue_thread=issue, issue_thread=issue,
state="new", state="pending_new",
timestamp=now + timedelta(seconds=1), timestamp=now + timedelta(seconds=1),
) )
mail2 = Email.objects.create( mail2 = Email.objects.create(
@ -62,7 +62,7 @@ class IssueApiTest(TestCase):
self.assertEqual(len(response.json()), 1) self.assertEqual(len(response.json()), 1)
self.assertEqual(response.json()[0]['id'], issue.id) self.assertEqual(response.json()[0]['id'], issue.id)
self.assertEqual(response.json()[0]['name'], "test issue") self.assertEqual(response.json()[0]['name'], "test issue")
self.assertEqual(response.json()[0]['state'], "new") self.assertEqual(response.json()[0]['state'], "pending_new")
self.assertEqual(response.json()[0]['assigned_to'], None) self.assertEqual(response.json()[0]['assigned_to'], None)
self.assertEqual(response.json()[0]['last_activity'], issue.last_activity.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) self.assertEqual(response.json()[0]['last_activity'], issue.last_activity.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
self.assertEqual(len(response.json()[0]['timeline']), 4) self.assertEqual(len(response.json()[0]['timeline']), 4)
@ -80,7 +80,7 @@ class IssueApiTest(TestCase):
self.assertEqual(response.json()[0]['timeline'][0]['body'], 'test') self.assertEqual(response.json()[0]['timeline'][0]['body'], 'test')
self.assertEqual(response.json()[0]['timeline'][0]['timestamp'], self.assertEqual(response.json()[0]['timeline'][0]['timestamp'],
mail1.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) mail1.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
self.assertEqual(response.json()[0]['timeline'][1]['state'], 'new') self.assertEqual(response.json()[0]['timeline'][1]['state'], 'pending_new')
self.assertEqual(response.json()[0]['timeline'][1]['timestamp'], self.assertEqual(response.json()[0]['timeline'][1]['timestamp'],
state.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) state.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
self.assertEqual(response.json()[0]['timeline'][2]['sender'], 'test') self.assertEqual(response.json()[0]['timeline'][2]['sender'], 'test')