Exemple #1
0
    def test_list_organizations(self):
        """
        Ensure that we can list the organizations we have access to and
        only organizations that we have access to.
        """
        url = reverse('client-organization-list')

        response = self.client.get(url, format='json')
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(response.data['count'], 1)
        self.assertEquals(response.data['results'][0]['id'], self.organization.id)

        other_org = Organization(
            name='Other Organization',
            address_1='123 Any Street',
            address_2='Suite 001',
            city='Ames',
            state='IA',
            phone='515-555-1234'
        )
        other_org.save()

        response = self.client.get(url, format='json')
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(response.data['count'], 1)
        self.assertEquals(response.data['results'][0]['id'], self.organization.id)
Exemple #2
0
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()
Exemple #3
0
    def get_queryset(self):
        organization_id = self.kwargs.get('pk')
        if not organization_id:
            raise Http404

        organization = Organization.get_by_id(organization_id)

        metas = UserMeta.objects.filter(organization=organization)
        return [meta.user for meta in metas]
Exemple #4
0
    def test_cant_get_other_organization(self):
        """
        Ensure we can get organization detail view for an organization
        that the logged in user doesn't have access to.
        """
        other_org = Organization(
            name='Other Organization',
            address_1='123 Any Street',
            address_2='Suite 001',
            city='Ames',
            state='IA',
            phone='515-555-1234'
        )
        other_org.save()

        url = reverse('client-organization-detail', kwargs={'pk': other_org.id})
        response = self.client.patch(url)
        self.assertEquals(response.status_code, status.HTTP_403_FORBIDDEN)
Exemple #5
0
    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'])