def _create_object_stub(self, with_relations=False, size=1, **kwargs): """ Create an object dict with relation dicts using factories. """ # Set a default tenant of the user. kwargs['tenant'] = self.user_obj.tenant if not kwargs.get('tenant') else kwargs['tenant'] object_list = [] account = AccountFactory(**kwargs) assigned_to = LilyUserFactory(**kwargs) next_step = DealNextStepFactory(**kwargs) why_customer = DealWhyCustomerFactory(**kwargs) found_through = DealFoundThroughFactory(**kwargs) contacted_by = DealContactedByFactory(**kwargs) status = DealStatusFactory(**kwargs) why_lost = DealWhyLostFactory(**kwargs) for iteration in range(0, size): obj = self.factory_cls.stub(**kwargs).__dict__ del obj['tenant'] del obj['contact'] # The minimum viable deal instance needs these relations, so always make them. obj['account'] = { 'id': account.pk, } obj['assigned_to'] = { 'id': assigned_to.pk, } obj['next_step'] = { 'id': next_step.pk, } obj['why_customer'] = { 'id': why_customer.pk, } obj['found_through'] = { 'id': found_through.pk, } obj['contacted_by'] = { 'id': contacted_by.pk, } obj['status'] = { 'id': status.pk, } obj['why_lost'] = { 'id': why_lost.pk, } if with_relations: # If relations are needed, override them, because a dict is needed instead of an instance. obj['tags'] = [TagFactory.stub().__dict__, ] obj['notes'] = [NoteFactory.stub().__dict__, ] object_list.append(obj) if size > 1: return object_list else: # If required size is 1, just give the object instead of a list. return object_list[0]
def notes_note(self, **kwargs): kwargs.update({ 'size': kwargs.get('size', self.batch_size), 'tenant': kwargs.get('tenant', self.tenant), 'author': kwargs.get('author') if kwargs.get('author') else iterator(self.users_user), 'subject': kwargs.get('subject') if kwargs.get('subject') else iterator(self._notes_subject), }) self.stdout.write('Done with notes_note.') return NoteFactory.create_batch(**kwargs)
def notes_note(self, **kwargs): kwargs.update( { "size": kwargs.get("size", self.batch_size), "tenant": kwargs.get("tenant", self.tenant), "author": kwargs.get("author") if kwargs.get("author") else iterator(self.users_user), "subject": kwargs.get("subject") if kwargs.get("subject") else iterator(self._notes_subject), } ) self.stdout.write("Done with notes_note.") return NoteFactory.create_batch(**kwargs)
def notes(self, size, tenant): NoteFactory.create_batch(size, tenant=tenant) # create multiple notes for single subject and multi author NoteFactory.create_batch(size, tenant=tenant, subject=AccountFactory(tenant=tenant)) # create multiple notes for single subject and single author NoteFactory.create_batch(size, tenant=tenant, author=CustomUserFactory(tenant=tenant), subject=AccountFactory(tenant=tenant))
def test_update_modified(self): """ Test that the modified date of a case gets set properly. """ tenant = TenantFactory.create() note = NoteFactory.create(tenant=tenant) modified = note.modified time.sleep(1) note.save(update_modified=False) self.assertEqual(modified, note.modified) note.save(update_modified=True) self.assertNotEqual(modified, note.modified)
def notes(self, size, tenant): NoteFactory.create_batch(size, tenant=tenant) # create multiple notes for single subject and multi author NoteFactory.create_batch(size, tenant=tenant, subject=AccountFactory(tenant=tenant)) # create multiple notes for single subject and single author NoteFactory.create_batch(size, tenant=tenant, author=LilyUserFactory(tenant=tenant), subject=AccountFactory(tenant=tenant))
def test_contact_open_deal_open_case_notes(self): """ Test having a contact with open deals and cases. Both with notes. """ # There are open cases and open deals, both have attached notes. The most recent note is for a case. cases = CaseFactory.create_batch(size=5, tenant=self.user_obj.tenant) Case.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc)) case = cases[0] case.contact = self.contact case.is_deleted = False case.status = self.case_status_new case.modified = datetime(2018, 1, 3, tzinfo=utc) case.update_modified = False case.save() case_notes = NoteFactory.create_batch( size=5, tenant=self.user_obj.tenant, gfk_content_type=case.content_type, gfk_object_id=case.id) for note in case_notes: case.notes.add(note)
class InternalNumberSearchAPITestCase(UserBasedTest, APITestCase): search_url = 'search_internal_number_view' @classmethod def setUpTestData(cls): super(InternalNumberSearchAPITestCase, cls).setUpTestData() cls.four_days_ago = datetime.now(tz=utc) - timedelta(days=4) cls.five_days_ago = datetime.now(tz=utc) - timedelta(days=5) cls.nine_days_ago = datetime.now(tz=utc) - timedelta(days=9) cls.case_status_new = CaseStatusFactory.create( tenant=cls.user_obj.tenant, name='New') cls.case_status_closed = CaseStatusFactory.create( tenant=cls.user_obj.tenant, name='Closed') cls.deal_status_open = DealStatusFactory.create( tenant=cls.user_obj.tenant, name='Open') cls.deal_status_lost = DealStatusFactory.create( tenant=cls.user_obj.tenant, name='Lost') cls.phone_number = PhoneNumberFactory(tenant=cls.user_obj.tenant, number='+31611223344') cls.contact = ContactFactory.create(tenant=cls.user_obj.tenant) cls.contact.phone_numbers.add(cls.phone_number) def test_contact_open_deal_open_case_notes(self): """ Test having a contact with open deals and cases. Both with notes. """ # There are open cases and open deals, both have attached notes. The most recent note is for a case. cases = CaseFactory.create_batch(size=5, tenant=self.user_obj.tenant) Case.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc)) case = cases[0] case.contact = self.contact case.is_deleted = False case.status = self.case_status_new case.modified = datetime(2018, 1, 3, tzinfo=utc) case.update_modified = False case.save() case_notes = NoteFactory.create_batch( size=5, tenant=self.user_obj.tenant, gfk_content_type=case.content_type, gfk_object_id=case.id) for note in case_notes: case.notes.add(note) case_note = case_notes[0] deals = DealFactory.create_batch(size=5, tenant=self.user_obj.tenant) Deal.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc)) deal = deals[0] deal.is_deleted = False deal.status = self.deal_status_open deal.contact = self.contact deal.modified = datetime(2018, 1, 2, tzinfo=utc) deal.update_modified = False deal.save() deal_notes = NoteFactory.create_batch( size=5, tenant=self.user_obj.tenant, gfk_content_type=deal.content_type, gfk_object_id=deal.id) for note in deal_notes: deal.notes.add(note) deal_note = deal_notes[0] Note.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc)) Note.objects.filter(pk=case_note.pk).update( modified=datetime(2018, 2, 3, tzinfo=utc)) Note.objects.filter(pk=deal_note.pk).update( modified=datetime(2018, 2, 2, tzinfo=utc)) assigned_to_user = case.assigned_to # Make api call. response = self.user.get( reverse(self.search_url, kwargs={'number': self.phone_number.number})) # Verify response. self._verify_response(response, assigned_to_user) # There are open cases and open deals, both have attached notes. The most recent note is for a deal. Note.objects.filter(pk=case_note.pk).update( modified=datetime(2018, 2, 2, tzinfo=utc)) Note.objects.filter(pk=deal_note.pk).update( modified=datetime(2018, 2, 3, tzinfo=utc)) assigned_to_user = deal.assigned_to # Make api call. response = self.user.get( reverse(self.search_url, kwargs={'number': self.phone_number.number})) # Verify response. self._verify_response(response, assigned_to_user)
def test_contact_open_deal_open_case_notes(self): """ Test having a contact with open deals and cases. Both with notes. """ # There are open cases and open deals, both have attached notes. The most recent note is for a case. cases = CaseFactory.create_batch(size=5, tenant=self.user_obj.tenant) Case.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc)) case = cases[0] case.contact = self.contact case.is_deleted = False case.status = self.case_status_new case.modified = datetime(2018, 1, 3, tzinfo=utc) case.update_modified = False case.save() case_notes = NoteFactory.create_batch( size=5, tenant=self.user_obj.tenant, gfk_content_type=case.content_type, gfk_object_id=case.id ) for note in case_notes: case.notes.add(note) case_note = case_notes[0] deals = DealFactory.create_batch(size=5, tenant=self.user_obj.tenant) Deal.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc)) deal = deals[0] deal.is_deleted = False deal.status = self.deal_status_open deal.contact = self.contact deal.modified = datetime(2018, 1, 2, tzinfo=utc) deal.update_modified = False deal.save() deal_notes = NoteFactory.create_batch( size=5, tenant=self.user_obj.tenant, gfk_content_type=deal.content_type, gfk_object_id=deal.id ) for note in deal_notes: deal.notes.add(note) deal_note = deal_notes[0] Note.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc)) Note.objects.filter(pk=case_note.pk).update(modified=datetime(2018, 2, 3, tzinfo=utc)) Note.objects.filter(pk=deal_note.pk).update(modified=datetime(2018, 2, 2, tzinfo=utc)) assigned_to_user = case.assigned_to # Make api call. response = self.user.get(reverse(self.search_url, kwargs={'number': self.phone_number.number})) # Verify response. self._verify_response(response, assigned_to_user) # There are open cases and open deals, both have attached notes. The most recent note is for a deal. Note.objects.filter(pk=case_note.pk).update(modified=datetime(2018, 2, 2, tzinfo=utc)) Note.objects.filter(pk=deal_note.pk).update(modified=datetime(2018, 2, 3, tzinfo=utc)) assigned_to_user = deal.assigned_to # Make api call. response = self.user.get(reverse(self.search_url, kwargs={'number': self.phone_number.number})) # Verify response. self._verify_response(response, assigned_to_user)