def setUp(self): """ Sets up some resources with which to test. """ test_utils.setup_test_storage() # set up different test resources self.non_downloadable_resource = _import_resource('ILSP10.xml') self.downloadable_resource_1 = \ _import_resource('downloadable_1_license.xml') self.downloadable_resource_3 = \ _import_resource('downloadable_3_licenses.xml') self.ms_commons_resource = \ _import_resource('downloadable_ms_commons_license.xml') self.local_download_resource = \ _import_resource('local_download.xml') # assign and copy downloadable resource self.local_download_resource.storage_object.checksum = \ '3930f5022aff02c7fa27ffabf2eaaba0' self.local_download_resource.storage_object.save() self.local_download_resource.storage_object.update_storage() shutil.copyfile( '{0}/repository/fixtures/archive.zip'.format(settings.ROOT_PATH), '{0}/{1}/archive.zip'.format( settings.STORAGE_PATH, self.local_download_resource.storage_object.identifier)) # set up test users with/without staff permissions and with/without # META-SHARE full membership staffuser = create_user('staffuser', '*****@*****.**', 'secret') staffuser.is_staff = True staffuser.save() create_user('normaluser', '*****@*****.**', 'secret') profile_ct = ContentType.objects.get_for_model(UserProfile) ms_full_member_perm = Permission.objects.get(content_type=profile_ct, codename='ms_full_member') ms_member = create_user('fullmember', '*****@*****.**', 'secret') ms_member.user_permissions.add(ms_full_member_perm) ms_member.save() ms_member = create_user('associatemember', '*****@*****.**', 'secret') ms_member.user_permissions.add( Permission.objects.get(content_type=profile_ct, codename='ms_associate_member')) ms_member.save() # create a test organization with META-SHARE full membership test_organization_ms = Organization.objects.create( name='test_organization_ms') test_organization_ms.permissions.add(ms_full_member_perm) test_organization_ms.save() test_utils.create_organization_member('organization_member_ms', '*****@*****.**', 'secret', (test_organization_ms, ))
def test_non_downloadable_resource_for_normal_organization_members(self): """ Verifies that a resource with an MS Commons license cannot be downloaded by a user of an organization which does not have the META-SHARE full member permission. """ test_passwd = 'secret' test_user = test_utils.create_organization_member( 'organization_member_non_ms', '*****@*****.**', test_passwd, (Organization.objects.create(name='test_organization_non_ms'),)) client = Client() client.login(username=test_user.username, password=test_passwd) # make sure the license page is shown: response = client.get(reverse(views.download, args=(self.ms_commons_resource.storage_object.identifier,)), follow = True) self.assertTemplateUsed(response, 'repository/licence_agreement.html', "license agreement page expected") self.assertContains(response, 'licences/META-SHARE_COMMONS_BYNCSA_v1.0.htm', msg_prefix="the " \ "correct license appears to not be shown in an iframe") # make sure the download cannot be started: response = client.post( reverse(views.download, args=(self.ms_commons_resource.storage_object.identifier,)), { 'in_licence_agree_form': 'True', 'licence_agree': 'True', 'licence': 'MSCommons-BY-NC-SA' }, follow = True) self.assertTemplateUsed(response, 'repository/licence_agreement.html', msg_prefix="a download should not have been started")
def test_non_downloadable_resource_for_normal_organization_members(self): """ Verifies that a resource with an MS Commons license cannot be downloaded by a user of an organization which does not have the META-SHARE full member permission. """ test_passwd = 'secret' test_user = test_utils.create_organization_member( 'organization_member_non_ms', '*****@*****.**', test_passwd, (Organization.objects.create(name='test_organization_non_ms'), )) client = Client() client.login(username=test_user.username, password=test_passwd) # make sure the license page is shown: response = client.get(reverse( views.download, args=(self.ms_commons_resource.storage_object.identifier, )), follow=True) self.assertTemplateUsed(response, 'repository/licence_agreement.html', "license agreement page expected") self.assertContains(response, 'licences/META-SHARE_COMMONS_BYNCSA_v1.0.htm', msg_prefix="the " \ "correct license appears to not be shown in an iframe") # make sure the download cannot be started: response = client.post(reverse( views.download, args=(self.ms_commons_resource.storage_object.identifier, )), { 'in_licence_agree_form': 'True', 'licence_agree': 'True', 'licence': 'MSCommons-BY-NC-SA' }, follow=True) self.assertTemplateUsed( response, 'repository/licence_agreement.html', msg_prefix="a download should not have been started")
def setUp(self): """ Sets up some resources with which to test. """ test_utils.setup_test_storage() # set up different test resources self.non_downloadable_resource = _import_resource('ILSP10.xml') self.downloadable_resource_1 = \ _import_resource('downloadable_1_license.xml') self.downloadable_resource_3 = \ _import_resource('downloadable_3_licenses.xml') self.ms_commons_resource = \ _import_resource('downloadable_ms_commons_license.xml') self.local_download_resource = \ _import_resource('local_download.xml') # assign and copy downloadable resource self.local_download_resource.storage_object.checksum = \ '3930f5022aff02c7fa27ffabf2eaaba0' self.local_download_resource.storage_object.save() self.local_download_resource.storage_object.update_storage() shutil.copyfile( '{0}/repository/fixtures/archive.zip'.format(settings.ROOT_PATH), '{0}/{1}/archive.zip'.format( settings.STORAGE_PATH, self.local_download_resource.storage_object.identifier)) # set up test users with/without staff permissions and with/without # META-SHARE full membership staffuser = create_user('staffuser', '*****@*****.**', 'secret') staffuser.is_staff = True staffuser.save() create_user('normaluser', '*****@*****.**', 'secret') profile_ct = ContentType.objects.get_for_model(UserProfile) ms_full_member_perm = Permission.objects.get(content_type=profile_ct, codename='ms_full_member') ms_member = create_user('fullmember', '*****@*****.**', 'secret') ms_member.user_permissions.add(ms_full_member_perm) ms_member.save() ms_member = create_user('associatemember', '*****@*****.**', 'secret') ms_member.user_permissions.add(Permission.objects.get( content_type=profile_ct, codename='ms_associate_member')) ms_member.save() # create a test organization with META-SHARE full membership test_organization_ms = Organization.objects.create( name='test_organization_ms') test_organization_ms.permissions.add(ms_full_member_perm) test_organization_ms.save() test_utils.create_organization_member('organization_member_ms', '*****@*****.**', 'secret', (test_organization_ms,))