def test_campaign_permissions_assigned(self): # this is the important call, it applies the permissions to the # campaign object before saving authorization.apply_campaign_permissions(self.user, self.campaign_one) #check that our created user has ALL permissions to the campaign self.assertTrue(self.user.has_perm('catamidb.view_campaign', self.campaign_one)) self.assertTrue(self.user.has_perm('catamidb.add_campaign', self.campaign_one)) self.assertTrue(self.user.has_perm('catamidb.change_campaign', self.campaign_one)) self.assertTrue(self.user.has_perm('catamidb.delete_campaign', self.campaign_one)) # check that the only thing the anonymous user can do is view the # campaign self.assertTrue(self.anonymous_user.has_perm('catamidb.view_campaign', self.campaign_one)) self.assertFalse(self.anonymous_user.has_perm('catamidb.add_campaign', self.campaign_one)) self.assertFalse(self.anonymous_user.has_perm( 'catamidb.change_campaign', self.campaign_one) ) self.assertFalse( self.anonymous_user.has_perm( 'catamidb.delete_campaign', self.campaign_one ) )
def setUp(self): #Tastypie stuff super(TestDeploymentResource, self).setUp() self.bob_api_client = TestApiClient() self.bill_api_client = TestApiClient() self.anon_api_client = TestApiClient() # Create a user bob. self.user_bob_username = '******' self.user_bob_password = '******' self.user_bob = User.objects.create_user(self.user_bob_username, '*****@*****.**', self.user_bob_password) # Create a user bob. self.user_bill_username = '******' self.user_bill_password = '******' self.user_bill = User.objects.create_user(self.user_bill_username, '*****@*****.**', self.user_bill_password) self.bob_api_client.client.login(username='******', password='******') self.bill_api_client.client.login(username='******', password='******') #assign users to the Public group public_group, created = Group.objects.get_or_create(name='Public') self.user_bob.groups.add(public_group) self.user_bill.groups.add(public_group) guardian.utils.get_anonymous_user().groups.add(public_group) #make a couple of campaigns and save self.campaign_bobs = mommy.make_one('catamidb.Campaign', id=1) self.campaign_bills = mommy.make_one('catamidb.Campaign', id=2) #make a deployments self.deployment_bobs = mommy.make_recipe('catamidb.Deployment1', id=1, campaign=self.campaign_bobs) self.deployment_bills = mommy.make_recipe('catamidb.Deployment2', id=2, campaign=self.campaign_bills) #assign this one to bob authorization.apply_campaign_permissions( self.user_bob, self.campaign_bobs) #assign this one to bill authorization.apply_campaign_permissions(self.user_bill, self.campaign_bills) #the API url for deployments self.deployment_url = '/api/dev/deployment/' #some post data for testing deployment creation self.post_data = { 'type': 'AUV', 'operator': 'XXX', }
def setUp(self): # Tastypie stuff super(TestCameraResource, self).setUp() self.bob_api_client = TestApiClient() self.bill_api_client = TestApiClient() self.anon_api_client = TestApiClient() # Create a user bob. self.user_bob_username = "******" self.user_bob_password = "******" self.user_bob = User.objects.create_user(self.user_bob_username, "*****@*****.**", self.user_bob_password) # Create a user bob. self.user_bill_username = "******" self.user_bill_password = "******" self.user_bill = User.objects.create_user( self.user_bill_username, "*****@*****.**", self.user_bill_password ) self.bob_api_client.client.login(username="******", password="******") self.bill_api_client.client.login(username="******", password="******") # assign users to the Public group public_group, created = Group.objects.get_or_create(name="Public") self.user_bob.groups.add(public_group) self.user_bill.groups.add(public_group) guardian.utils.get_anonymous_user().groups.add(public_group) # make a couple of campaigns and save self.campaign_bobs = mommy.make_one("catamidb.Campaign", id=1) self.campaign_bills = mommy.make_one("catamidb.Campaign", id=2) # make a deployments self.deployment_bobs = mommy.make_recipe("catamidb.Deployment1", id=1, campaign=self.campaign_bobs) self.deployment_bills = mommy.make_recipe("catamidb.Deployment2", id=2, campaign=self.campaign_bills) # make images self.image_bobs = mommy.make_recipe("catamidb.Image1", id=1, deployment=self.deployment_bobs) self.image_bills = mommy.make_recipe("catamidb.Image2", id=2, deployment=self.deployment_bills) # make cameras self.camera_bobs = mommy.make_one("catamidb.Camera", id=1, image=self.image_bobs) self.camera_bills = mommy.make_one("catamidb.Camera", id=2, image=self.image_bills) # assign this one to bob authorization.apply_campaign_permissions(self.user_bob, self.campaign_bobs) # assign this one to bill authorization.apply_campaign_permissions(self.user_bill, self.campaign_bills) # the API url for deployments self.camera_url = "/api/dev/camera/" # some post data for testing camera creation self.post_data = []
def setUp(self): #Tastypie stuff super(TestCampaignResource, self).setUp() self.bob_api_client = TestApiClient() self.bill_api_client = TestApiClient() self.anon_api_client = TestApiClient() # Create a user bob. self.user_bob_username = '******' self.user_bob_password = '******' self.user_bob = User.objects.create_user(self.user_bob_username, '*****@*****.**', self.user_bob_password) # Create a user bob. self.user_bill_username = '******' self.user_bill_password = '******' self.user_bill = User.objects.create_user(self.user_bill_username, '*****@*****.**', self.user_bill_password) self.bob_api_client.client.login(username='******', password='******') self.bill_api_client.client.login(username='******', password='******') #assign users to the Public group public_group, created = Group.objects.get_or_create(name='Public') self.user_bob.groups.add(public_group) self.user_bill.groups.add(public_group) guardian.utils.get_anonymous_user().groups.add(public_group) #make a couple of campaigns and save self.campaign_bobs = mommy.make_one('catamidb.Campaign', id=1) self.campaign_bills = mommy.make_one('catamidb.Campaign', id=2) #assign this one to bob authorization.apply_campaign_permissions( self.user_bob, self.campaign_bobs) #assign this one to bill authorization.apply_campaign_permissions( self.user_bill, self.campaign_bills) #the API url for campaigns self.campaign_url = '/api/dev/campaign/' #some post data for testing campaign creation self.post_data = { 'short_name': 'Blah', 'description': 'Blah', 'associated_researchers': 'Blah', 'associated_publications': 'Blah', 'associated_research_grant': 'Blah', 'date_start': '2012-05-01', 'date_end': '2012-05-01', 'contact_person': 'Blah', }
def setUp(self): # Tastypie stuff super(TestCampaignResource, self).setUp() self.bob_api_client = TestApiClient() self.bill_api_client = TestApiClient() self.anon_api_client = TestApiClient() # Create a user bob. self.user_bob_username = "******" self.user_bob_password = "******" self.user_bob = User.objects.create_user(self.user_bob_username, "*****@*****.**", self.user_bob_password) # Create a user bob. self.user_bill_username = "******" self.user_bill_password = "******" self.user_bill = User.objects.create_user( self.user_bill_username, "*****@*****.**", self.user_bill_password ) self.bob_api_client.client.login(username="******", password="******") self.bill_api_client.client.login(username="******", password="******") # assign users to the Public group public_group, created = Group.objects.get_or_create(name="Public") self.user_bob.groups.add(public_group) self.user_bill.groups.add(public_group) guardian.utils.get_anonymous_user().groups.add(public_group) # make a couple of campaigns and save self.campaign_bobs = mommy.make_one("catamidb.Campaign") self.campaign_bills = mommy.make_one("catamidb.Campaign") # assign this one to bob authorization.apply_campaign_permissions(self.user_bob, self.campaign_bobs) # assign this one to bill authorization.apply_campaign_permissions(self.user_bill, self.campaign_bills) # the API url for campaigns self.campaign_url = "/api/dev/campaign/" # some post data for testing campaign creation self.post_data = { "short_name": "Blah", "description": "Blah", "associated_researchers": "Blah", "associated_publications": "Blah", "associated_research_grant": "Blah", "date_start": "2012-05-01", "date_end": "2012-05-01", "contact_person": "Blah", }
def obj_create(self, bundle, **kwargs): """ We are overiding this function so we can get access to the newly created campaign. Once we have reference to it, we can apply object level permissions to the object. """ # get real user user = get_real_user_object(bundle.request.user) # create the bundle super(CampaignResource, self).obj_create(bundle) # make sure we apply permissions to this newly created object authorization.apply_campaign_permissions(user, bundle.obj) return bundle
def setUp(self): # Tastypie stuff super(TestMeasurementsResource, self).setUp() self.bob_api_client = TestApiClient() self.bill_api_client = TestApiClient() self.anon_api_client = TestApiClient() # Create a user bob. self.user_bob_username = "******" self.user_bob_password = "******" self.user_bob = User.objects.create_user(self.user_bob_username, "*****@*****.**", self.user_bob_password) # Create a user bob. self.user_bill_username = "******" self.user_bill_password = "******" self.user_bill = User.objects.create_user( self.user_bill_username, "*****@*****.**", self.user_bill_password ) self.bob_api_client.client.login(username="******", password="******") self.bill_api_client.client.login(username="******", password="******") # assign users to the Public group public_group, created = Group.objects.get_or_create(name="Public") self.user_bob.groups.add(public_group) self.user_bill.groups.add(public_group) guardian.utils.get_anonymous_user().groups.add(public_group) # make a couple of campaigns and save self.campaign_bobs = mommy.make_one("catamidb.Campaign", id=1) self.campaign_bills = mommy.make_one("catamidb.Campaign", id=2) # make a deployments self.deployment_bobs = mommy.make_recipe("catamidb.Deployment1", id=1, campaign=self.campaign_bobs) self.deployment_bills = mommy.make_recipe("catamidb.Deployment2", id=2, campaign=self.campaign_bills) # make images self.image_bobs = mommy.make_recipe("catamidb.Image1", id=1, deployment=self.deployment_bobs) self.image_bills = mommy.make_recipe("catamidb.Image2", id=2, deployment=self.deployment_bills) # make measurements self.measurements_bobs = mommy.make_one("catamidb.Measurement", id=1, image=self.image_bobs) self.measurements_bills = mommy.make_one("catamidb.Measurement", id=2, image=self.image_bills) # assign this one to bob authorization.apply_campaign_permissions(self.user_bob, self.campaign_bobs) # assign this one to bill authorization.apply_campaign_permissions(self.user_bill, self.campaign_bills) # the API url for Measurements self.image_measurement_url = "/api/dev/measurements/" self.post_data = { "altitude": "13", "pitch": "1", "roll": "5", "salinity": "20", "temperature": "22", "yaw": "1", }
def setUp(self): #Tastypie stuff super(TestScientificImageMeasurementResource, self).setUp() self.bob_api_client = TestApiClient() self.bill_api_client = TestApiClient() self.anon_api_client = TestApiClient() # Create a user bob. self.user_bob_username = '******' self.user_bob_password = '******' self.user_bob = User.objects.create_user(self.user_bob_username, '*****@*****.**', self.user_bob_password) # Create a user bob. self.user_bill_username = '******' self.user_bill_password = '******' self.user_bill = User.objects.create_user(self.user_bill_username, '*****@*****.**', self.user_bill_password) self.bob_api_client.client.login(username='******', password='******') self.bill_api_client.client.login(username='******', password='******') #assign users to the Public group public_group, created = Group.objects.get_or_create(name='Public') self.user_bob.groups.add(public_group) self.user_bill.groups.add(public_group) guardian.utils.get_anonymous_user().groups.add(public_group) #make a couple of campaigns and save self.campaign_bobs = mommy.make_one('catamidb.Campaign', id=1) self.campaign_bills = mommy.make_one('catamidb.Campaign', id=2) #make a deployments self.deployment_bobs = mommy.make_recipe('catamidb.auvdeployment1', id=1, campaign=self.campaign_bobs) self.deployment_bills = mommy.make_recipe('catamidb.auvdeployment2', id=2, campaign=self.campaign_bills) #make poses self.pose_bobs = mommy.make_recipe('catamidb.pose1', id=1, deployment=self.deployment_bobs) self.pose_bills = mommy.make_recipe('catamidb.pose2', id=2, deployment=self.deployment_bills) #make cameras self.camera_bobs = mommy.make_one('catamidb.Camera', id=1, deployment=self.deployment_bobs) self.camera_bills = mommy.make_one('catamidb.Camera', id=2, deployment=self.deployment_bills) #make images self.image_bobs = mommy.make_one( 'catamidb.Image', id=1, pose=self. pose_bobs, camera=self.camera_bobs) self.image_bills = mommy.make_one( 'catamidb.Image', id=2, pose=self. pose_bills, camera=self.camera_bills) #make image measurements self.image_measurement_bobs = mommy.make_one( 'catamidb.ScientificImageMeasurement', id=1, image=self.image_bobs ) self.image_measurement_bills = mommy.make_one( 'catamidb.ScientificImageMeasurement', id=2, image=self. image_bills) #assign this one to bob authorization.apply_campaign_permissions( self.user_bob, self.campaign_bobs) #assign this one to bill authorization.apply_campaign_permissions( self.user_bill, self.campaign_bills) #the API url for campaigns self.image_measurement_url = '/api/dev/scientificimagemeasurement/' self.post_data = []
def setUp(self): #Tastypie stuff super(TestMeasurementsResource, self).setUp() self.bob_api_client = TestApiClient() self.bill_api_client = TestApiClient() self.anon_api_client = TestApiClient() # Create a user bob. self.user_bob_username = '******' self.user_bob_password = '******' self.user_bob = User.objects.create_user(self.user_bob_username, '*****@*****.**', self.user_bob_password) # Create a user bob. self.user_bill_username = '******' self.user_bill_password = '******' self.user_bill = User.objects.create_user(self.user_bill_username, '*****@*****.**', self.user_bill_password) self.bob_api_client.client.login(username='******', password='******') self.bill_api_client.client.login(username='******', password='******') #assign users to the Public group public_group, created = Group.objects.get_or_create(name='Public') self.user_bob.groups.add(public_group) self.user_bill.groups.add(public_group) guardian.utils.get_anonymous_user().groups.add(public_group) #make a couple of campaigns and save self.campaign_bobs = mommy.make_one('catamidb.Campaign', id=1) self.campaign_bills = mommy.make_one('catamidb.Campaign', id=2) #make a deployments self.deployment_bobs = mommy.make_recipe('catamidb.Deployment1', id=1, campaign=self.campaign_bobs) self.deployment_bills = mommy.make_recipe('catamidb.Deployment2', id=2, campaign=self.campaign_bills) #make images self.image_bobs = mommy.make_recipe( 'catamidb.Image1', id=1, deployment=self.deployment_bobs) self.image_bills = mommy.make_recipe( 'catamidb.Image2', id=2, deployment=self.deployment_bills) #make measurements self.measurements_bobs = mommy.make_one( 'catamidb.Measurements', id=1, image=self.image_bobs) self.measurements_bills = mommy.make_one( 'catamidb.Measurements', id=2, image=self.image_bills) #assign this one to bob authorization.apply_campaign_permissions( self.user_bob, self.campaign_bobs) #assign this one to bill authorization.apply_campaign_permissions( self.user_bill, self.campaign_bills) #the API url for Measurements self.image_measurement_url = '/api/dev/measurements/' self.post_data = { 'altitude': '13', 'pitch': '1', 'roll': '5', 'salinity': '20', 'temperature': '22', 'yaw': '1' }
def setUp(self): # turn on collections for testing # Flag.objects.create(name='Collections', everyone=True) # self.flag_mommy = mommy.make_one('waffle.Flag', id=1, # name='Collections', everyone=True) this turns on waffle switched # collection code for test we might like to load th waffle.json fixture # instead, but it's sitting in catamidb/fixtures Switch.objects.create(name='Collections', active=True) self.user_bob = User.objects.create_user('bob', '*****@*****.**', 'bob') self.factory = RequestFactory() self.first_campaign_id = 1 self.campaign_01 = mommy.make_one('catamidb.Campaign', id=1) self.deployment1 = mommy.make_recipe('webinterface.auvdeployment1', id=1, campaign=self.campaign_01) self.deployment2 = mommy.make_recipe('webinterface.auvdeployment2', id=2, campaign=self.campaign_01) self.pose_01 = mommy.make_recipe('webinterface.pose_01', id=1, deployment=self.deployment1) self.pose_02 = mommy.make_recipe('webinterface.pose_01', id=2, deployment=self.deployment2) self.camera_01 = mommy.make_one('catamidb.Camera', deployment=self. deployment1) self.image_01 = mommy.make_one('catamidb.Image', id=1, pose=self.pose_01, camera=self.camera_01 ) self.collection_01 = mommy.make_one('collection.Collection', images=[ self.image_01]) self.second_campaign_id = 2 self.third_campaign_id = 3 self.campaign_02 = mommy.make_one('catamidb.Campaign', id=self. second_campaign_id) self.campaign_03 = mommy.make_one('catamidb.Campaign', id=self. third_campaign_id) self.dummy_dep = mommy.make_one('catamidb.Deployment', start_position=Point(12.4604, 43.9420), end_position=Point( 12.4604, 43.9420), transect_shape=Polygon(((0.0, 0.0), (0.0, 50.0 ), (50.0, 50.0), (50.0, 0.0), (0.0, 0.0))), id=1, campaign=self. campaign_02) self.dummy_dep1 = mommy.make_recipe('webinterface.auvdeployment', id=3, campaign=self.campaign_02) self.dummy_dep2 = mommy.make_recipe('webinterface.bruvdeployment', id=4, campaign=self.campaign_02) self.dummy_dep3 = mommy.make_recipe('webinterface.dovdeployment', id=5, campaign=self.campaign_02) self.dummy_dep4 = mommy.make_recipe('webinterface.tvdeployment', id=6, campaign=self.campaign_02) self.dummy_dep5 = mommy.make_recipe('webinterface.tideployment', id=7, campaign=self.campaign_02) #apply permissions to the campaigns so we get nice reponses authorization.apply_campaign_permissions(self.user_bob, self.campaign_01) authorization.apply_campaign_permissions(self.user_bob, self.campaign_02) authorization.apply_campaign_permissions(self.user_bob, self.campaign_03)
def setUp(self): #Tastypie stuff super(TestGenericPointAnnotationResource, self).setUp() create_setup(self) self.bob_api_client = TestApiClient() self.bill_api_client = TestApiClient() self.anon_api_client = TestApiClient() # Create a user bob. self.user_bob_username = '******' self.user_bob_password = '******' self.user_bob = User.objects.create_user(self.user_bob_username, '*****@*****.**', self.user_bob_password) # Create a user bob. self.user_bill_username = '******' self.user_bill_password = '******' self.user_bill = User.objects.create_user(self.user_bill_username, '*****@*****.**', self.user_bill_password) self.bob_api_client.client.login(username='******', password='******') self.bill_api_client.client.login(username='******', password='******') #add the users to the main campaign for permission purposes catamidbauthorization.apply_campaign_permissions(self.user_bob, self.campaign_one) catamidbauthorization.apply_campaign_permissions(self.user_bill, self.campaign_one) #assign users to the Public group public_group, created = Group.objects.get_or_create(name='Public') self.user_bob.groups.add(public_group) self.user_bill.groups.add(public_group) guardian.utils.get_anonymous_user().groups.add(public_group) #make a couple of projects and save #self.project_bobs = mommy.make_recipe('project.project1', id=1, owner=self.user_bob) #self.project_bills = mommy.make_recipe('project.project2', id=2, owner=self.user_bill) self.project_bobs = mommy.make_one(Project, owner=self.user_bob, creation_date=datetime.now(), modified_date=datetime.now(), generic_images=[self.mock_image_one, self.mock_image_two]) self.project_bills = mommy.make_one(Project, owner=self.user_bill, creation_date=datetime.now(), modified_date=datetime.now(), generic_images=[self.mock_image_one, self.mock_image_two]) #assign this one to bob authorization.apply_project_permissions( self.user_bob, self.project_bobs) #assign this one to bill authorization.apply_project_permissions( self.user_bill, self.project_bills) self.generic_annotation_set_bobs = mommy.make_one(GenericAnnotationSet, project=self.project_bobs, owner=self.user_bob, creation_date=datetime.now(), modified_date=datetime.now(), generic_images=[self.mock_image_one, self.mock_image_two], annotation_methodology=0, image_sampling_methodology=0) self.generic_annotation_set_bills = mommy.make_one(GenericAnnotationSet, project=self.project_bills, owner=self.user_bob, creation_date=datetime.now(), modified_date=datetime.now(), generic_images=[self.mock_image_one, self.mock_image_two], annotation_methodology=1, image_sampling_methodology=0) #assign this one to bob authorization.apply_generic_annotation_set_permissions( self.user_bob, self.generic_annotation_set_bobs) #assign this one to bill authorization.apply_generic_annotation_set_permissions( self.user_bill, self.generic_annotation_set_bills) self.annotation_point_bobs = mommy.make_one(GenericPointAnnotation, generic_annotation_set=self.generic_annotation_set_bobs, image=self.mock_image_one, owner=self.user_bob, ) self.annotation_point_bills = mommy.make_one(GenericPointAnnotation, generic_annotation_set=self.generic_annotation_set_bills, image=self.mock_image_one, owner=self.user_bill, ) #the API url for annotation points self.point_annotation_url = '/api/dev/generic_point_annotation/'
def setUp(self): #Tastypie stuff super(TestProjectResource, self).setUp() create_setup(self) self.bob_api_client = TestApiClient() self.bill_api_client = TestApiClient() self.anon_api_client = TestApiClient() # Create a user bob. self.user_bob_username = '******' self.user_bob_password = '******' self.user_bob = User.objects.create_user(self.user_bob_username, '*****@*****.**', self.user_bob_password) # Create a user bob. self.user_bill_username = '******' self.user_bill_password = '******' self.user_bill = User.objects.create_user(self.user_bill_username, '*****@*****.**', self.user_bill_password) self.bob_api_client.client.login(username='******', password='******') self.bill_api_client.client.login(username='******', password='******') #need these permissions for bill and bob to attach images to projects catamidbauthorization.apply_campaign_permissions(self.user_bob, self.campaign_one) catamidbauthorization.apply_campaign_permissions(self.user_bill, self.campaign_one) #assign users to the Public group public_group, created = Group.objects.get_or_create(name='Public') self.user_bob.groups.add(public_group) self.user_bill.groups.add(public_group) guardian.utils.get_anonymous_user().groups.add(public_group) #make a couple of projects and save #self.project_bobs = mommy.make_recipe('project.project1', id=1, owner=self.user_bob) #self.project_bills = mommy.make_recipe('project.project2', id=2, owner=self.user_bill) self.project_bobs = mommy.make_one(Project, owner=self.user_bob, creation_date=datetime.now(), modified_date=datetime.now(), generic_images=[self.mock_image_one, self.mock_image_two]) self.project_bills = mommy.make_one(Project, owner=self.user_bill, creation_date=datetime.now(), modified_date=datetime.now(), generic_images=[self.mock_image_one, self.mock_image_two]) #assign this one to bob authorization.apply_project_permissions( self.user_bob, self.project_bobs) #assign this one to bill authorization.apply_project_permissions( self.user_bill, self.project_bills) #the API url for campaigns self.project_url = '/api/dev/project/'