def setUp(self): """ Setup fixtures before running e2e test. """ super(AuthorizationTestCase, self).setUp() call_command('index') LilyUserFactory.create(is_active=True, email='*****@*****.**', password=make_password('testing'))
def users(self, size, tenant): LilyUserFactory.create_batch(size, tenant=tenant) user = LilyUserFactory.create(tenant=tenant, is_active=True, email='*****@*****.**' % tenant.pk) self.stdout.write('You can now login as a normal user in %(tenant)s with:\n%(email)s\n%(password)s\n' % { 'tenant': tenant, 'email': user.email, 'password': '******' })
def setUp(self): """ Setup fixtures before running e2e test. """ super(AuthorizationTestCase, self).setUp() call_command("index") call_command("testdata", target="contacts_and_accounts,cases,deals,notes") LilyUserFactory.create(is_active=True, email="*****@*****.**", password=make_password("testing"))
def setUp(self): """ Setup fixtures before running e2e test. """ super(AuthorizationTestCase, self).setUp() call_command('index') LilyUserFactory.create(is_active=True, email='*****@*****.**', password=make_password('testing'))
def users(self, size, tenant): LilyUserFactory.create_batch(size, tenant=tenant) user = LilyUserFactory.create(tenant=tenant, is_active=True, email='*****@*****.**' % tenant.pk) self.stdout.write( 'You can now login as a normal user in %(tenant)s with:\n%(email)s\n%(password)s\n' % { 'tenant': tenant, 'email': user.email, 'password': '******' })
def users_login(self, **kwargs): kwargs.update({ 'tenant': kwargs.get('tenant', self.tenant), 'teams': kwargs.get('teams') if kwargs.get('teams') else iterator(self.users_team), 'is_active': kwargs.get('is_active', True), 'email': '*****@*****.**' % self.tenant.pk, }) user = LilyUserFactory.create(**kwargs) self.stdout.write('\nYou can now login as a normal user in %(tenant)s with:\n%(email)s\n%(password)s\n' % { 'tenant': self.tenant, 'email': user.email, 'password': '******' }) kwargs['email'] = '*****@*****.**' % self.tenant.pk superuser = LilySuperUserFactory.create(**kwargs) self.stdout.write('\nYou can now login as a superuser in %(tenant)s with:\n%(email)s\n%(password)s\n\n' % { 'tenant': self.tenant, 'email': superuser.email, 'password': '******' }) return [user, superuser]
def users_login(self, **kwargs): kwargs.update({ 'tenant': kwargs.get('tenant', self.tenant), 'teams': kwargs.get('teams') if kwargs.get('teams') else iterator(self.users_team), 'is_active': kwargs.get('is_active', True), 'email': '*****@*****.**' % self.tenant.pk, }) user = LilyUserFactory.create(**kwargs) self.stdout.write('\nYou can now login as a normal user in %(tenant)s with:\n%(email)s\n%(password)s\n' % { 'tenant': self.tenant, 'email': user.email, 'password': '******' }) kwargs['email'] = '*****@*****.**' % self.tenant.pk superuser = LilySuperUserFactory.create(**kwargs) self.stdout.write('\nYou can now login as a superuser in %(tenant)s with:\n%(email)s\n%(password)s\n\n' % { 'tenant': self.tenant, 'email': superuser.email, 'password': '******' }) return [user, superuser]
def setUp(self): # Reset changes made to the email account in a test. self.email_account.refresh_from_db() self.tenant = TenantFactory.create() self.users = LilyUserFactory.create_batch(size=3) self.owner = self.users[0]
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 users_login(self, **kwargs): kwargs.update( { "tenant": kwargs.get("tenant", self.tenant), "teams": kwargs.get("teams") if kwargs.get("teams") else iterator(self.users_team), "is_active": kwargs.get("is_active", True), "email": "*****@*****.**" % self.tenant.pk, } ) user = LilyUserFactory.create(**kwargs) self.stdout.write( "\nYou can now login as a normal user in %(tenant)s with:\n%(email)s\n%(password)s\n" % {"tenant": self.tenant, "email": user.email, "password": "******"} ) kwargs["email"] = "*****@*****.**" % self.tenant.pk superuser = LilySuperUserFactory.create(**kwargs) self.stdout.write( "\nYou can now login as a superuser in %(tenant)s with:\n%(email)s\n%(password)s\n\n" % {"tenant": self.tenant, "email": superuser.email, "password": "******"} ) return [user, superuser]
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 setUpClass(cls): """ Creates a user and logs it in before running the account tests. """ # Remove leftovers from previous tests LilyUser.objects.all().delete() cls.user = LilyUserFactory.create(is_active=True, email='*****@*****.**', password=make_password('test')) cls.client = APIClient() cls.client.login(email='*****@*****.**', password='******')
def users_user(self, **kwargs): kwargs.update({ 'size': kwargs.get('size', self.batch_size) / 2, 'tenant': kwargs.get('tenant', self.tenant), 'teams': kwargs.get('teams') if kwargs.get('teams') else iterator(self.users_team) }) users = LilyUserFactory.create_batch(**kwargs) superusers = LilySuperUserFactory.create_batch(**kwargs) self.stdout.write('Done with users_user.') return users + superusers
def test_contact_closed_deals_cases_account(self): """ Test having a contact attached to a contact with no cases or deals. """ assigned_to_user = LilyUserFactory.create(tenant=self.user_obj.tenant, is_active=True) account = AccountFactory.create(tenant=self.user_obj.tenant, assigned_to=assigned_to_user) Function.objects.create(account=account, contact=self.contact) # 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 users_user(self, **kwargs): kwargs.update({ 'size': kwargs.get('size', self.batch_size) / 2, 'tenant': kwargs.get('tenant', self.tenant), 'teams': kwargs.get('teams') if kwargs.get('teams') else iterator(self.users_team) }) users = LilyUserFactory.create_batch(**kwargs) superusers = LilySuperUserFactory.create_batch(**kwargs) self.stdout.write('Done with users_user.') return users + superusers
def contacts_and_accounts(self, size, tenant): # create various contacts ContactFactory.create_batch(size, tenant=tenant) # create accounts with zero contact AccountFactory.create_batch(size, tenant=tenant) # create account with multi contacts function_factory(tenant).create_batch( size, account=AccountFactory(tenant=tenant)) # create account with assigned_to function_factory(tenant).create_batch( size, account=AccountFactory(tenant=tenant, assigned_to=LilyUserFactory(tenant=tenant)))
def users_user(self, **kwargs): kwargs.update( { "size": kwargs.get("size", self.batch_size) / 2, "tenant": kwargs.get("tenant", self.tenant), "teams": kwargs.get("teams") if kwargs.get("teams") else iterator(self.users_team), } ) users = LilyUserFactory.create_batch(**kwargs) superusers = LilySuperUserFactory.create_batch(**kwargs) self.stdout.write("Done with users_user.") return users + superusers
def test_contact_closed_deals_cases_account(self): """ Test having a contact attached to a contact with no cases or deals. """ assigned_to_user = LilyUserFactory.create(tenant=self.user_obj.tenant, is_active=True) account = AccountFactory.create(tenant=self.user_obj.tenant, assigned_to=assigned_to_user) Function.objects.create(account=account, contact=self.contact) # 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 _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 = [] casetype = CaseTypeFactory(**kwargs) casestatus = CaseStatusFactory(**kwargs) for iteration in range(0, size): obj = self.factory_cls.stub(**kwargs).__dict__ del obj['tenant'] # The minimum viable case instance needs these relations, so always make them. obj['type'] = { 'id': casetype.pk } obj['status'] = { 'id': casestatus.pk } if with_relations: # If relations are needed, override them, because a dict is needed instead of an instance. obj['account'] = AccountFactory.stub().__dict__ obj['contact'] = ContactFactory.stub().__dict__ obj['assigned_to'] = LilyUserFactory.stub().__dict__ del obj['account']['tenant'] del obj['contact']['tenant'] del obj['assigned_to']['tenant'] del obj['created_by'] else: # Delete the related objects, since they can't be serialized. del obj['account'] del obj['assigned_to'] del obj['created_by'] 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 _get_logged_in_user(self): tenant = TenantFactory() current_user = get_current_user() # Ugly! if current_user: current_user.tenant = tenant user = LilyUserFactory(tenant=tenant) user.set_password('test') user.save() self.client.login(username=user.primary_email.email_address, password='******') return user
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) casetype = CaseTypeFactory(**kwargs) casestatus = CaseStatusFactory(**kwargs) for iteration in range(0, size): obj = self.factory_cls.stub(**kwargs).__dict__ del obj['tenant'] # The minimum viable case instance needs these relations, so always make them. obj['account'] = { 'id': account.pk, } obj['type'] = { 'id': casetype.pk } obj['status'] = { 'id': casestatus.pk } if with_relations: # If relations are needed, override them, because a dict is needed instead of an instance. obj['assigned_to'] = LilyUserFactory.stub().__dict__ del obj['assigned_to']['tenant'] del obj['created_by'] else: # Delete the related objects, since they can't be serialized. del obj['assigned_to'] del obj['created_by'] 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 test_no_errors(self): """ Test that the stats pages give no errors. """ user_obj = LilyUserFactory(is_active=True) team = TeamFactory() self.client.login(email=user_obj.email, password='******') for pattern in case_patterns: # Loop over case patterns, these need the team_id kwarg. response = self.client.get( reverse(pattern.name, kwargs={ 'team_id': team.id, })) self.assertEqual(response.status_code, 200) for pattern in deal_patterns: # Loop over deal patterns, these need no kwargs. response = self.client.get(reverse(pattern.name)) self.assertEqual(response.status_code, 200)
def test_new_user_has_invalid_credentials(self): user = LilyUserFactory.build() self.assertIsNone(get_credentials(user))