コード例 #1
0
ファイル: test_group.py プロジェクト: hydroshare/hydroshare
    def test_group_update_failure(self):
        # test that post data for 'name', 'description', and 'privacy_level' are required
        # when updating a group

        # first create a group to test updating group
        url = reverse('create_user_group')
        grp_data = {'name': 'Test Group-1', 'description': 'This is a cool group-1',
                    'purpose': 'This group has purpose', 'privacy_level': 'public'}
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        response = create_user_group(request)
        new_group = Group.objects.filter(name='Test Group-1').first()

        # now test updating new_group
        url_params = {'group_id': new_group.id}
        url = reverse('update_user_group', kwargs=url_params)
        # test name is required -> update should fail
        grp_data = {'description': 'This is a cool group-2', 'purpose': 'This group has purpose'}
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        # description has not changed proves update failed
        self.assertNotEqual(new_group.gaccess.description, 'This is a cool group-2')
        self.assertEqual(new_group.gaccess.description, 'This is a cool group-1')
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # test description is required -> update should fail
        grp_data = {'name': 'Test Group-2', 'purpose': 'This group has purpose',
                    'privacy_level': 'public'}
        request = self.factory.post(url, data=grp_data)

        self._update_failure(new_group, request)

        # test privacy_level is required -> update should fail
        grp_data = {'name': 'Test Group-2', 'description': 'This is a cool group',
                    'purpose': 'This group has purpose'}
        request = self.factory.post(url, data=grp_data)

        self._update_failure(new_group, request)

        # test trying to update group with a duplicate name ('HydroShare Author') should fail
        grp_data = {'name': 'Hydroshare Author', 'description': 'This is a cool group-1',
                    'purpose': 'This group has purpose'}
        request = self.factory.post(url, data=grp_data)
        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        # name has not changed proves update failed
        self.assertEqual(Group.objects.filter(name='Hydroshare Author').count(), 1)
        updated_group = Group.objects.filter(name='Hydroshare Author').first()
        self.assertNotEqual(updated_group.id, new_group.id)
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])
コード例 #2
0
ファイル: test_group.py プロジェクト: zhangmingda/hydroshare
    def test_group_update_failure(self):
        # test that post data for 'name', 'description', and 'privacy_level' are required
        # when updating a group

        # first create a group to test updating group
        url = reverse('create_user_group')
        grp_data = {'name': 'Test Group-1', 'description': 'This is a cool group-1',
                    'purpose': 'This group has purpose', 'privacy_level': 'public'}
        request = self.factory.post(url, data=grp_data)

        self._set_request_message_attributes(request)
        request.user = self.john
        response = create_user_group(request)
        new_group = Group.objects.filter(name='Test Group-1').first()

        # now test updating new_group
        url_params = {'group_id': new_group.id}
        url = reverse('update_user_group', kwargs=url_params)
        # test name is required -> update should fail
        grp_data = {'description': 'This is a cool group-2', 'purpose': 'This group has purpose'}
        request = self.factory.post(url, data=grp_data)

        self._set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        # description has not changed proves update failed
        self.assertNotEqual(new_group.gaccess.description, 'This is a cool group-2')
        self.assertEqual(new_group.gaccess.description, 'This is a cool group-1')
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # test description is required -> update should fail
        grp_data = {'name': 'Test Group-2', 'purpose': 'This group has purpose',
                    'privacy_level': 'public'}
        request = self.factory.post(url, data=grp_data)

        self._update_failure(new_group, request)

        # test privacy_level is required -> update should fail
        grp_data = {'name': 'Test Group-2', 'description': 'This is a cool group',
                    'purpose': 'This group has purpose'}
        request = self.factory.post(url, data=grp_data)

        self._update_failure(new_group, request)

        # test trying to update group with a duplicate name ('HydroShare Author') should fail
        grp_data = {'name': 'Hydroshare Author', 'description': 'This is a cool group-1',
                    'purpose': 'This group has purpose'}
        request = self.factory.post(url, data=grp_data)
        self._set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        # name has not changed proves update failed
        self.assertEqual(Group.objects.filter(name='Hydroshare Author').count(), 1)
        updated_group = Group.objects.filter(name='Hydroshare Author').first()
        self.assertNotEqual(updated_group.id, new_group.id)
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])
コード例 #3
0
    def test_update_group(self):
        # here we are testing the update_user_group view function

        # there should be 1 group at this point
        self.assertEqual(Group.objects.count(), 1)
        # let john create a new group
        new_group = self.john.uaccess.create_group(title='Test Group',
                                                   description='This is a great group',
                                                   purpose='To have fun',
                                                   auto_approve=True)

        # there should be 2 groups at this point
        self.assertEqual(Group.objects.count(), 2)

        # update new_group
        post_data = {'name': "Test Group-1", 'description': "This is great group",
                     'purpose': "To have fun", 'auto_approve': False, 'privacy_level': 'public'}
        url = reverse('update_user_group', kwargs={'group_id': new_group.id})

        request = self.factory.post(url, data=post_data)
        request.user = self.john
        request.META['HTTP_REFERER'] = '/group/{}'.format(new_group.id)
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)
        response = update_user_group(request, group_id=new_group.id)
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])
        flag_messages = get_messages(request)
        success_messages = [m for m in flag_messages if m.tags == 'success']
        self.assertNotEqual(len(success_messages), 0)
        # there should be 2 group at this point
        self.assertEqual(Group.objects.count(), 2)
コード例 #4
0
    def _update_failure(self, group, request):
        group_name = group.name
        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=group.id)
        # name has not changed proves update failed
        updated_group = Group.objects.filter(name='Test Group-2').first()
        self.assertEqual(updated_group, None)
        original_group = Group.objects.filter(name=group_name).first()
        self.assertNotEqual(original_group, None)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])
コード例 #5
0
ファイル: test_group.py プロジェクト: hydroshare/hydroshare
    def _update_failure(self, group, request):
        group_name = group.name
        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=group.id)
        # name has not changed proves update failed
        updated_group = Group.objects.filter(name='Test Group-2').first()
        self.assertEqual(updated_group, None)
        original_group = Group.objects.filter(name=group_name).first()
        self.assertNotEqual(original_group, None)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])
コード例 #6
0
    def test_update_group(self):
        # TODO: test with picture file upload for the group

        # first create a group to test updating group
        url = reverse('create_user_group')
        grp_data = {
            'name': 'Test Group-1',
            'description': 'This is a cool group-1',
            'purpose': 'This group has no purpose',
            'privacy_level': 'public'
        }
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        response = create_user_group(request)
        new_group = Group.objects.filter(name='Test Group-1').first()
        self.assertEqual(new_group.gaccess.active, True)
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description,
                         'This is a cool group-1')
        self.assertEqual(new_group.gaccess.purpose,
                         'This group has no purpose')
        self.assertEqual(new_group.gaccess.public, True)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)
        self.assertEqual(new_group.gaccess.shareable, True)
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'],
                         reverse('group', args=[new_group.id]))

        # now test updating new_group
        url_params = {'group_id': new_group.id}
        url = reverse('update_user_group', kwargs=url_params)
        # update name, description, purpose
        grp_data = {
            'name': 'Test Group-2',
            'description': 'This is a cool group-2',
            'purpose': 'This group now has purpose',
            'privacy_level': 'public'
        }
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description,
                         'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose,
                         'This group now has purpose')
        self.assertEqual(new_group.gaccess.public, True)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # update group to remove purpose
        grp_data = {
            'name': 'Test Group-2',
            'description': 'This is a cool group-2',
            'privacy_level': 'public'
        }
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description,
                         'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose, '')
        self.assertEqual(new_group.gaccess.public, True)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # update privacy_level (set to private)- this set public to false and discoverable to false
        grp_data = {
            'name': 'Test Group-2',
            'description': 'This is a cool group-2',
            'privacy_level': 'private'
        }
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description,
                         'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose, '')
        self.assertEqual(new_group.gaccess.public, False)
        self.assertEqual(new_group.gaccess.discoverable, False)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # update privacy_level (set to public) - this set public to true and discoverable to true
        grp_data = {
            'name': 'Test Group-2',
            'description': 'This is a cool group-2',
            'privacy_level': 'public'
        }
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description,
                         'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose, '')
        self.assertEqual(new_group.gaccess.public, True)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # update privacy_level (set to discoverable) - this should set discoverable to
        # true and public to false
        grp_data = {
            'name': 'Test Group-2',
            'description': 'This is a cool group-2',
            'privacy_level': 'discoverable'
        }
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description,
                         'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose, '')
        self.assertEqual(new_group.gaccess.public, False)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])
コード例 #7
0
ファイル: test_group.py プロジェクト: hydroshare/hydroshare
    def test_update_group(self):
        # TODO: test with picture file upload for the group

        # first create a group to test updating group
        url = reverse('create_user_group')
        grp_data = {'name': 'Test Group-1', 'description': 'This is a cool group-1',
                    'purpose': 'This group has no purpose', 'privacy_level': 'public'}
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        response = create_user_group(request)
        new_group = Group.objects.filter(name='Test Group-1').first()
        self.assertEqual(new_group.gaccess.active, True)
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description, 'This is a cool group-1')
        self.assertEqual(new_group.gaccess.purpose, 'This group has no purpose')
        self.assertEqual(new_group.gaccess.public, True)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)
        self.assertEqual(new_group.gaccess.shareable, True)
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], reverse('group', args=[new_group.id]))

        # now test updating new_group
        url_params = {'group_id': new_group.id}
        url = reverse('update_user_group', kwargs=url_params)
        # update name, description, purpose
        grp_data = {'name': 'Test Group-2', 'description': 'This is a cool group-2',
                    'purpose': 'This group now has purpose', 'privacy_level': 'public'}
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description, 'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose, 'This group now has purpose')
        self.assertEqual(new_group.gaccess.public, True)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # update group to remove purpose
        grp_data = {'name': 'Test Group-2', 'description': 'This is a cool group-2',
                    'privacy_level': 'public'}
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description, 'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose, '')
        self.assertEqual(new_group.gaccess.public, True)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # update privacy_level (set to private)- this set public to false and discoverable to false
        grp_data = {'name': 'Test Group-2', 'description': 'This is a cool group-2',
                    'privacy_level': 'private'}
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description, 'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose, '')
        self.assertEqual(new_group.gaccess.public, False)
        self.assertEqual(new_group.gaccess.discoverable, False)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # update privacy_level (set to public) - this set public to true and discoverable to true
        grp_data = {'name': 'Test Group-2', 'description': 'This is a cool group-2',
                    'privacy_level': 'public'}
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description, 'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose, '')
        self.assertEqual(new_group.gaccess.public, True)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])

        # update privacy_level (set to discoverable) - this should set discoverable to
        # true and public to false
        grp_data = {'name': 'Test Group-2', 'description': 'This is a cool group-2',
                    'privacy_level': 'discoverable'}
        request = self.factory.post(url, data=grp_data)

        self.set_request_message_attributes(request)
        request.user = self.john
        request.META['HTTP_REFERER'] = "/some_url/"
        response = update_user_group(request, group_id=new_group.id)
        new_group = Group.objects.filter(name='Test Group-2').first()
        self.assertNotEqual(new_group, None)
        self.assertEqual(new_group.gaccess.description, 'This is a cool group-2')
        self.assertEqual(new_group.gaccess.purpose, '')
        self.assertEqual(new_group.gaccess.public, False)
        self.assertEqual(new_group.gaccess.discoverable, True)
        self.assertEqual(new_group.gaccess.active, True)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        self.assertEqual(response['Location'], request.META['HTTP_REFERER'])