def test_mark_issue_conversation_as_closed(self): long_time_ago = timezone.now() - relativedelta(days=30) # not cancelled -> should stay open issue = IssueFactory() conversation = issue.conversation conversation.messages.create(content='hello', author=issue.created_by, created_at=long_time_ago) # cancelled but recently commented on -> should stay open with freeze_time(long_time_ago, tick=True): issue_ended_recently = IssueFactory() issue_ended_recently.cancel() conversation_ended_recently = issue_ended_recently.conversation conversation_ended_recently.messages.create( content='hello', author=issue_ended_recently.created_by, created_at=timezone.now() ) # cancelled and not commented on -> should be closed with freeze_time(long_time_ago, tick=True): issue_ended = IssueFactory() issue_ended.cancel() conversation_ended = issue_ended.conversation conversation_ended.messages.create(content='hello', author=issue_ended.created_by, created_at=long_time_ago) conversations = Conversation.objects.filter(target_type__model='issue') self.assertEqual(conversations.count(), 3) self.assertEqual(conversations.filter(is_closed=False).count(), 3) mark_conversations_as_closed() self.assertEqual(conversations.filter(is_closed=False).count(), 2) self.assertEqual(conversations.filter(is_closed=True).first(), conversation_ended)
def test_mark_empty_as_closed(self): long_time_ago = timezone.now() - relativedelta(days=30) # no messages and cancelled some time ago -> should be closed with freeze_time(long_time_ago, tick=True): issue_ended_long_ago = IssueFactory() issue_ended_long_ago.cancel() # no messages and cancelled recently -> should stay open issue_ended_recently = IssueFactory() issue_ended_recently.cancel() mark_conversations_as_closed() conversations = Conversation.objects.filter(target_type__model='issue') self.assertEqual(conversations.filter(is_closed=True).first(), issue_ended_long_ago.conversation) self.assertEqual(conversations.filter(is_closed=False).first(), issue_ended_recently.conversation)