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)
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 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)