def test_set_resource_flag_make_public(self):
        # here we are testing the set_resource_flag view function to make a resource public

        # test that trying set the resource flag to public  when there is no content file
        # or required metadata it should not change the resource flag

        # test that the resource is not public
        self.assertEqual(self.gen_res_one.raccess.public, False)
        url_params = {'shortkey': self.gen_res_one.short_id}
        post_data = {'flag': 'make_public'}
        url = reverse('set_resource_flag', kwargs=url_params)
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)
        set_resource_flag(request, shortkey=self.gen_res_one.short_id)
        # check that the resource is still not public
        self.gen_res_one.raccess.refresh_from_db()
        self.assertEqual(self.gen_res_one.raccess.public, False)
        flag_messages = get_messages(request)
        err_messages = [m for m in flag_messages if m.tags == 'error']
        self.assertNotEqual(len(err_messages), 0)

        # setting flag to public for 2nd resource should succeed
        # test that the resource is not public
        self.assertEqual(self.gen_res_two.raccess.public, False)
        url_params = {'shortkey': self.gen_res_two.short_id}
        post_data = {'flag': 'make_public'}
        url = reverse('set_resource_flag', kwargs=url_params)
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)
        response = set_resource_flag(request,
                                     shortkey=self.gen_res_two.short_id)
        self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
        flag_messages = get_messages(request)
        err_messages = [m for m in flag_messages if m.tags == 'error']
        self.assertEqual(len(err_messages), 0)
        # check that the resource is public now
        self.gen_res_two.raccess.refresh_from_db()
        self.assertEqual(self.gen_res_two.raccess.public, True)

        # clean up
        hydroshare.delete_resource(self.gen_res_one.short_id)
        hydroshare.delete_resource(self.gen_res_two.short_id)
    def test_set_resource_flag_make_shareable(self):
        # here we are testing the set_resource_flag view function to make a resource shareable

        # test that the resource is  shareable
        self.assertEqual(self.gen_res_one.raccess.shareable, True)
        # set it not shareable
        self.gen_res_one.raccess.shareable = False
        self.gen_res_one.raccess.save()

        url_params = {'shortkey': self.gen_res_one.short_id}
        post_data = {'flag': 'make_shareable'}
        url = reverse('set_resource_flag', kwargs=url_params)
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)
        response = set_resource_flag(request, shortkey=self.gen_res_one.short_id)
        response_data = json.loads(response.content)
        self.assertEqual(response_data['status'], 'success')

        # check that the resource is shareable now
        self.gen_res_one.raccess.refresh_from_db()
        self.assertEqual(self.gen_res_one.raccess.shareable, True)
        # clean up
        hydroshare.delete_resource(self.gen_res_one.short_id)
        hydroshare.delete_resource(self.gen_res_two.short_id)
    def test_set_resource_flag_make_not_shareable(self):
        # here we are testing the set_resource_flag view function to make a resource not shareable

        # test that the resource is  shareable
        self.assertEqual(self.gen_res_one.raccess.shareable, True)

        url_params = {'shortkey': self.gen_res_one.short_id}
        post_data = {'flag': 'make_not_shareable'}
        url = reverse('set_resource_flag', kwargs=url_params)
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)
        response = set_resource_flag(request,
                                     shortkey=self.gen_res_one.short_id)
        self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
        flag_messages = get_messages(request)
        err_messages = [m for m in flag_messages if m.tags == 'error']
        self.assertEqual(len(err_messages), 0)
        # check that the resource is not shareable now
        self.gen_res_one.raccess.refresh_from_db()
        self.assertEqual(self.gen_res_one.raccess.shareable, False)
        # clean up
        hydroshare.delete_resource(self.gen_res_one.short_id)
        hydroshare.delete_resource(self.gen_res_two.short_id)
예제 #4
0
    def test_set_resource_flag_make_discoverable(self):
        # here we are testing the set_resource_flag view function to make a resource discoverable

        # test that trying set the resource discoverable when there is no content file
        # or required metadata it should not make the resource discoverable

        # test that the resource is not discoverable
        self.assertEqual(self.gen_res_one.raccess.discoverable, False)
        url_params = {'shortkey': self.gen_res_one.short_id}
        post_data = {'flag': 'make_discoverable'}
        url = reverse('set_resource_flag', kwargs=url_params)
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)
        response = set_resource_flag(request,
                                     shortkey=self.gen_res_one.short_id)
        # check that the resource is still not discoverable
        self.gen_res_one.raccess.refresh_from_db()
        self.assertEqual(self.gen_res_one.raccess.discoverable, False)
        response_data = json.loads(response.content.decode())
        self.assertEqual(response_data['status'], 'error')

        # setting flag to discoverable for 2nd resource should succeed
        # test that the resource is not discoverable
        self.assertEqual(self.gen_res_two.raccess.discoverable, False)
        url_params = {'shortkey': self.gen_res_two.short_id}
        post_data = {'flag': 'make_discoverable'}
        url = reverse('set_resource_flag', kwargs=url_params)
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)
        response = set_resource_flag(request,
                                     shortkey=self.gen_res_two.short_id)
        response_data = json.loads(response.content.decode())
        self.assertEqual(response_data['status'], 'success')

        # check that the resource is discoverable now
        self.gen_res_two.raccess.refresh_from_db()
        self.assertEqual(self.gen_res_two.raccess.discoverable, True)

        # clean up
        hydroshare.delete_resource(self.gen_res_one.short_id)
        hydroshare.delete_resource(self.gen_res_two.short_id)
    def test_set_resource_flag_make_public(self):
        # here we are testing the set_resource_flag view function to make a resource public

        # test that trying set the resource flag to public  when there is no content file
        # or required metadata it should not change the resource flag

        # test that the resource is not public
        self.assertEqual(self.gen_res_one.raccess.public, False)
        url_params = {'shortkey': self.gen_res_one.short_id}
        post_data = {'flag': 'make_public'}
        url = reverse('set_resource_flag', kwargs=url_params)
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)
        response = set_resource_flag(request, shortkey=self.gen_res_one.short_id)
        # check that the resource is still not public
        self.gen_res_one.raccess.refresh_from_db()
        self.assertEqual(self.gen_res_one.raccess.public, False)
        response_data = json.loads(response.content)
        self.assertEqual(response_data['status'], 'error')

        # setting flag to public for 2nd resource should succeed
        # test that the resource is not public
        self.assertEqual(self.gen_res_two.raccess.public, False)
        url_params = {'shortkey': self.gen_res_two.short_id}
        post_data = {'flag': 'make_public'}
        url = reverse('set_resource_flag', kwargs=url_params)
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)
        response = set_resource_flag(request, shortkey=self.gen_res_two.short_id)
        response_data = json.loads(response.content)
        self.assertEqual(response_data['status'], 'success')

        # check that the resource is public now
        self.gen_res_two.raccess.refresh_from_db()
        self.assertEqual(self.gen_res_two.raccess.public, True)

        # clean up
        hydroshare.delete_resource(self.gen_res_one.short_id)
        hydroshare.delete_resource(self.gen_res_two.short_id)