Esempio n. 1
0
    def test_non_migrated_db(self, guardian_settings):
        mocked_get_init_anon.reset_mock()
        guardian_settings.GET_INIT_ANONYMOUS_USER = '******'

        create_anonymous_user('sender', using='session')

        mocked_get_init_anon.assert_not_called()
Esempio n. 2
0
    def setUp(self):
        """ Creates a new test client and test user. The user is assigned
        permissions to modify an existing test project.
        """
        self.test_project_id = 3
        self.test_user_id = 3
        self.client = Client()

        p = Project.objects.get(pk=self.test_project_id)

        create_anonymous_user(object())

        user = User.objects.get(pk=3)
        # Assign the new user permissions to browse and annotate projects
        assign_perm('can_browse', user, p)
        assign_perm('can_annotate', user, p)

        cursor = connection.cursor()
        # Make sure all counters are set correctly
        cursor.execute("""
            SELECT setval('concept_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM concept;
        """)
        cursor.execute("""
            SELECT setval('location_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM location;
        """)
Esempio n. 3
0
    def setUp(self):
        """ Creates a new test client and test user. The user is assigned
        permissions to modify an existing test project.
        """
        self.test_project_id = 3
        self.test_user_id = 3
        self.client = Client()

        p = Project.objects.get(pk=self.test_project_id)

        create_anonymous_user(object())

        user = User.objects.get(pk=3)
        # Assign the new user permissions to browse and annotate projects
        assign_perm('can_browse', user, p)
        assign_perm('can_annotate', user, p)

        cursor = connection.cursor()
        # Make sure all counters are set correctly
        cursor.execute("""
            SELECT setval('concept_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM concept;
        """)
        cursor.execute("""
            SELECT setval('location_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM location;
        """)
Esempio n. 4
0
def get_or_create_anonymous_user():
    try:
        anon_user = get_anonymous_user()
    except:
        create_anonymous_user(None)
        anon_user = get_anonymous_user()

    return anon_user
Esempio n. 5
0
def get_or_create_anonymous_user():
    try:
        anon_user = get_anonymous_user()
    except:
        create_anonymous_user(None)
        anon_user = get_anonymous_user()

    return anon_user
    def test_uses_custom_username_field_model(self, guardian_settings):
        mocked_get_init_anon.reset_mock()
        guardian_settings.GET_INIT_ANONYMOUS_USER = '******'
        guardian_settings.ANONYMOUS_USER_NAME = '*****@*****.**'
        User = get_user_model()

        anon = mocked_get_init_anon.return_value = mock.Mock()
        create_anonymous_user('sender')
        mocked_get_init_anon.assert_called_once_with(User)
        anon.save.assert_called_once_with()
Esempio n. 7
0
    def test_uses_custom_username_field_model(self, guardian_settings):
        mocked_get_init_anon.reset_mock()
        guardian_settings.GET_INIT_ANONYMOUS_USER = '******'
        guardian_settings.ANONYMOUS_USER_NAME = '*****@*****.**'
        User = get_user_model()

        anon = mocked_get_init_anon.return_value = mock.Mock()
        create_anonymous_user('sender', using='default')
        mocked_get_init_anon.assert_called_once_with(User)
        anon.save.assert_called_once_with(using='default')
Esempio n. 8
0
def add_anonymous_user_to_anonymous_group(sender, **kwargs):
    """
    Adds AnonymousUser to group specified by the USERS_ANONYMOUS_GROUP setting.
    """
    anon_group, created = Group.objects.get_or_create(
        name=settings.USERS_ANONYMOUS_GROUP)
    create_anonymous_user(sender, **kwargs)  # we need AnonymousUser to exist
    print 'Adding AnonymousUser to the group "%s"' % anon_group.name
    u = User.objects.get(pk=settings.ANONYMOUS_USER_ID)
    u.groups.add(anon_group)
    u.save()
Esempio n. 9
0
def add_anonymous_user_to_anonymous_group(sender, **kwargs):
    """
    Adds AnonymousUser to group specified by the USERS_ANONYMOUS_GROUP setting.
    """
    anon_group, created = Group.objects.get_or_create(
                                        name=settings.USERS_ANONYMOUS_GROUP)
    create_anonymous_user(sender, **kwargs)  # we need AnonymousUser to exist
    print 'Adding AnonymousUser to the group "%s"' % anon_group.name
    u = User.objects.get(pk=settings.ANONYMOUS_USER_ID)
    u.groups.add(anon_group)
    u.save()
Esempio n. 10
0
    def test_uses_custom_function(self, guardian_settings):
        path = 'guardian.testapp.tests.management_test.mocked_get_init_anon'
        guardian_settings.GET_INIT_ANONYMOUS_USER = path
        guardian_settings.ANONYMOUS_USER_ID = 219
        User = get_user_model()

        anon = mocked_get_init_anon.return_value = mock.Mock()

        create_anonymous_user('sender')

        mocked_get_init_anon.assert_called_once_with(User)

        self.assertEqual(anon.pk, 219)
        anon.save.assert_called_once_with()
Esempio n. 11
0
    def setUp(self):
        self.test_project_id = 3
        self.client = Client()

        create_anonymous_user(object())

        # Set up test API. Because we want to test only general access to the
        # methods, it doesn't matter if we use fake parameters.
        url_params = {
            'pid': self.test_project_id,
            'skid': 123456,
            'sid': 1,
        }
        self.can_browse_get_api = [
            '/permissions',
            '/accounts/login',
            '/user-list',
            '/%(pid)s/stacks' % url_params,
            '/%(pid)s/search' % url_params,
            '/%(pid)s/tracing/setup/test' % url_params,
            '/%(pid)s/stats/nodecount' % url_params,
            '/%(pid)s/stats/user-history' % url_params,
        ]
        self.can_browse_post_api = [
            '/permissions',
            '/accounts/login',
            '/user-table-list',
            '/user-profile/update',
            '/%(pid)s/notifications/list' % url_params,
            '/%(pid)s/node/user-info' % url_params,
            '/%(pid)s/node/get_location' % url_params,
            '/%(pid)s/node/list' % url_params,
            '/%(pid)s/skeletons/confidence-compartment-subgraph' % url_params,
            '/%(pid)s/graph/circlesofhell' % url_params,
            '/%(pid)s/connector/list/one_to_many' % url_params,
            '/%(pid)s/%(skid)s/1/1/0/compact-arbor' % url_params,
            '/%(pid)s/annotations/forskeletons' % url_params,
            '/%(pid)s/annotations/table-list' % url_params,
            '/%(pid)s/skeleton/analytics' % url_params,
            '/%(pid)s/skeleton/annotationlist' % url_params,
            '/%(pid)s/skeletons/review-status' % url_params,
            '/%(pid)s/skeleton/%(skid)s/neuronname' % url_params,
            '/%(pid)s/skeleton/connectors-by-partner' % url_params,
            '/%(pid)s/stack/%(sid)s/models' % url_params,
            '/%(pid)s/logs/list' % url_params,
            '/%(pid)s/graphexport/json' % url_params,
            '/%(pid)s/neuroml/neuroml_level3_v181' % url_params,
            '/%(pid)s/treenodearchive/export' % url_params,
            '/%(pid)s/connectorarchive/export' % url_params,
        ]
Esempio n. 12
0
    def test_uses_custom_function(self, guardian_settings):
        mocked_get_init_anon.reset_mock()

        path = 'guardian.testapp.tests.test_management.mocked_get_init_anon'
        guardian_settings.GET_INIT_ANONYMOUS_USER = path
        guardian_settings.ANONYMOUS_USER_NAME = "anonymous"
        User = get_user_model()

        anon = mocked_get_init_anon.return_value = mock.Mock()

        create_anonymous_user('sender')

        mocked_get_init_anon.assert_called_once_with(User)

        anon.save.assert_called_once_with()
Esempio n. 13
0
    def test_uses_custom_function(self, guardian_settings):
        mocked_get_init_anon.reset_mock()

        path = 'guardian.testapp.tests.test_management.mocked_get_init_anon'
        guardian_settings.GET_INIT_ANONYMOUS_USER = path
        guardian_settings.ANONYMOUS_USER_NAME = "anonymous"
        User = get_user_model()

        anon = mocked_get_init_anon.return_value = mock.Mock()

        create_anonymous_user('sender', using='default')

        mocked_get_init_anon.assert_called_once_with(User)

        anon.save.assert_called_once_with(using='default')
Esempio n. 14
0
    def setUp(self):
        super(DjmpTestBase, self).setUp()
        create_anonymous_user(None)

        self.user = '******'
        self.passwd = 'admin'
        self.client = Client()

        self.headers = {
            # TODO(mvv): these headers are specific to mvv's local env, that
            #            may be bad long term
            'X-Script-Name': '/1/map/tms/1.0.0/test/EPSG3857/1/0/0.png',
            'HTTP_HOST': 'localhost:8000',
            'SERVER_NAME': 'michaels-macbook-pro-2.local',
            'X-Forwarded-Host': 'localhost:8000'
        }
Esempio n. 15
0
    def setUp(self):
        super(DjmpTestBase, self).setUp()
        create_anonymous_user(None)

        self.user = '******'
        self.passwd = 'admin'
        self.client = Client()

        self.headers = {
            # TODO(mvv): these headers are specific to mvv's local env, that 
            #            may be bad long term
            'X-Script-Name': '/1/map/tms/1.0.0/test/EPSG3857/1/0/0.png',
            'HTTP_HOST': 'localhost:8000',
            'SERVER_NAME': 'michaels-macbook-pro-2.local',
            'X-Forwarded-Host': 'localhost:8000'
        }
Esempio n. 16
0
    def setUp(self):
        """ Creates a new test client and test user. The user is assigned
        permissions to modify an existing test project.
        """
        init_consistent_data()
        self.test_project_id = 3
        self.test_user_id = 3
        self.client = Client()

        p = Project.objects.get(pk=self.test_project_id)

        create_anonymous_user(object())

        user = User.objects.get(pk=3)
        # Assign the new user permissions to browse and annotate projects
        assign_perm('can_browse', user, p)
        assign_perm('can_annotate', user, p)
Esempio n. 17
0
    def setUp(self):
        """ Creates a new test client and test user. The user is assigned
        permissions to modify an existing test project.
        """
        init_consistent_data()
        self.test_project_id = 3
        self.test_user_id = 3
        self.client = Client()

        p = Project.objects.get(pk=self.test_project_id)

        create_anonymous_user(object())

        user = User.objects.get(pk=3)
        # Assign the new user permissions to browse and annotate projects
        assign_perm('can_browse', user, p)
        assign_perm('can_annotate', user, p)
Esempio n. 18
0
def init_users_groups(sender, **kwargs):
    from django.contrib.auth.models import Group
    from guardian.management import create_anonymous_user
    from guardian.utils import get_anonymous_user

    try:
        anon = get_anonymous_user()
    except ObjectDoesNotExist:
        create_anonymous_user(sender, **kwargs)
        anon = get_anonymous_user()

    g_reg_anon, _ = Group.objects.get_or_create(
        name=settings.REGISTERED_AND_ANON_USERS_GROUP_NAME)
    anon.groups.add(g_reg_anon)

    g_reg, _ = Group.objects.get_or_create(
        name=settings.REGISTERED_USERS_GROUP_NAME)
    anon.groups.remove(g_reg)
Esempio n. 19
0
    def setUpTestData(cls):
        init_consistent_data()
        # Set up data for the whole TestCase
        cls.test_project_id = 3
        cls.test_user_id = 3
        cls.test_project = Project.objects.get(pk=cls.test_project_id)
        cls.test_user = User.objects.get(pk=cls.test_user_id)

        cursor = connection.cursor()
        # Make sure all counters are set correctly
        cursor.execute("""
            SELECT setval('concept_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM concept;
        """)
        cursor.execute("""
            SELECT setval('location_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM location;
        """)

        create_anonymous_user(object())

        # Assign the new user permissions to browse and annotate projects
        assign_perm('can_browse', cls.test_user, cls.test_project)
        assign_perm('can_annotate', cls.test_user, cls.test_project)
Esempio n. 20
0
    def setUpTestData(cls):
        init_consistent_data()
        # Set up data for the whole TestCase
        cls.test_project_id = 3
        cls.test_user_id = 3
        cls.test_project = Project.objects.get(pk=cls.test_project_id)
        cls.test_user = User.objects.get(pk=cls.test_user_id)

        cursor = connection.cursor()
        # Make sure all counters are set correctly
        cursor.execute("""
            SELECT setval('concept_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM concept;
        """)
        cursor.execute("""
            SELECT setval('location_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM location;
        """)

        create_anonymous_user(object())

        # Assign the new user permissions to browse and annotate projects
        assign_perm('can_browse', cls.test_user, cls.test_project)
        assign_perm('can_annotate', cls.test_user, cls.test_project)
Esempio n. 21
0
 def test_create_anonymous_user(self):
     create_anonymous_user(object())
     self.assertEqual(1, User.objects.all().count())
     anonymous = User.objects.all()[0]
     self.assertEqual(anonymous.username,
                      guardian_settings.ANONYMOUS_USER_NAME)
Esempio n. 22
0
 def test_create_anonymous_user(self):
     create_anonymous_user(object())
     self.assertEqual(1, User.objects.all().count())
     anonymous = User.objects.all()[0]
     self.assertEqual(anonymous.pk, settings.ANONYMOUS_USER_ID)
Esempio n. 23
0
def add_anonymous_group(apps, schema_editor):
	create_anonymous_user(None)
	group = Group.objects.create(name="Anonymous")
	user = get_anonymous_user()
	user.groups.add(group)
Esempio n. 24
0
 def test_create_anonymous_user(self):
     create_anonymous_user(object())
     self.assertEqual(1, User.objects.all().count())
     anonymous = User.objects.all()[0]
     self.assertEqual(anonymous.pk, settings.ANONYMOUS_USER_ID)
Esempio n. 25
0
 def test_create_anonymous_user(self):
     create_anonymous_user(object())
     self.assertEqual(1, User.objects.all().count())
     anonymous = User.objects.all()[0]
     self.assertEqual(anonymous.username, guardian_settings.ANONYMOUS_USER_NAME)