class BaseTestCase(APITestCase): def setUp(self): """ Sets up a number of test entites in the database for testing. Included: user: A webapp user organization: An organization that user belongs to domain: A domain that belongs to organization """ # Creating Users self.user = MBUser( email='*****@*****.**', first_name='test', last_name='tester', is_admin=False, is_platform=False, is_webapp=True, ) self.user.set_password('test') self.user.save() self.client.login(username='******', password='******') # Organization self.organization = Organization( name='Test Organization', address_1='123 Any Street', address_2='Suite 001', city='New York', state='NY', phone='555-555-1234' ) self.organization.save() self.user_meta = UserMeta( user=self.user, organization=self.organization ) self.user_meta.save() # Domain self.domain = Domain( domain_name='test.com', organization=self.organization, whitelisted=False ) self.domain.save()
def handle(self, *args, **options): # Create the organization org = Organization(**organization).save() if not org: self.stdout.write("Org failed") return self.stdout.write("Successfully created the MailBeaker organization") # Create the domain in the organization dom = Domain(organization=org, **domain) self.stdout.write("Successfully created the MailBeaker domain") # Create all of the users in the domain for user in users: mb_user = MBUser(**user).save() user_meta = UserMeta(user=mb_user, organization=org) self.stdout.write("Successfully created the %s user and associated meta" % mb_user.email) # Create all of the rules for rule in rules: rule_entity = Rule(domain=dom, **rule) self.stdout.write("Successfully created the rule: %s" % rule['description'])
def test_cant_get_other_user_detail(self): """ Ensure that we can't get the user detail view for a user that is not currently logged in. """ other_user = MBUser( email='*****@*****.**', first_name='other', last_name='otherer', is_admin=False, is_platform=False, is_webapp=True, ) other_user.set_password('other') other_user.save() url = reverse('client-user-detail', kwargs={'pk': other_user.id}) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)