def setUp(self): addon = Addon.objects.get(pk=3615) self.thread = CommunicationThread(addon=addon) user = UserProfile.objects.all()[0] self.token = CommunicationThreadToken(thread=self.thread, user=user) self.token.modified = datetime.now() self.token.use_count = 0
def create_comm_thread(self, **kwargs): """Create a thread/note objects for communication.""" if not waffle.switch_is_active('comm-dashboard'): return action = kwargs['action'] action_note_types = { 'approve': comm.APPROVAL, 'disable': comm.DISABLED, 'escalate': comm.ESCALATION, 'info': comm.MORE_INFO_REQUIRED, 'comment': comm.REVIEWER_COMMENT, 'reject': comm.REJECTION } thread = CommunicationThread.objects.filter(addon=self.addon, version=self.version) perms = {} for key in self.data['action_visibility']: perms['read_permission_%s' % key] = True if thread.exists(): thread = thread[0] else: thread = CommunicationThread(addon=self.addon, version=self.version, **perms) # Set permissions from the form. thread.save() self.comm_note = CommunicationNote.objects.create( note_type=action_note_types[action], body=self.data['comments'], author=self.request.amo_user, thread=thread, **perms) self.comm_thread = thread moz_emails = self.addon.get_mozilla_contacts() # CC mozilla contact. for email in moz_emails: try: moz_contact = UserProfile.objects.get(email=email) except UserProfile.DoesNotExist: pass else: CommunicationThreadCC.objects.create(thread=thread, user=moz_contact)