예제 #1
0
    def test_database_router(self):
        router = TestRouter()

        if _VERSION <= (1, 6):
            self.assertTrue(
                router.allow_syncdb(DEFAULT_DB_ALIAS, get_user_model()))
        elif _VERSION == (1, 7):
            self.assertTrue(
                router.allow_migrate(DEFAULT_DB_ALIAS, get_user_model()))
        else:
            self.assertTrue(
                router.allow_migrate(DEFAULT_DB_ALIAS, 'user', 'CustomUser'))
예제 #2
0
    def from_assertion(self, assertion):
        u"""
        Заполнить из утверждения. Загрузить.
        Определяется сессия, пользователь, атрибуты пользователя.

        :param assertion: Утверждение, из которого надо получить данные
        :type assertion: etree.ElementTree
        """
        if self.validate and (not self.public_key_str
                              or not verify_assertion(assertion,
                                                      self.public_key_str)):
            raise SSOException("Response not valid")
        self.session_id = get_session_from_response_assertion(assertion)
        self.attributes = get_attributes_from_assertion(assertion)
        userid = get_userid_from_assertion(assertion)
        if self.get_user_method:
            self.user = self.get_user_method(userid, self.attributes)
        else:
            User = get_user_model()
            try:
                self.user = User.objects.get(username=userid)
                # возьмем первый попавшийся бэкенд
                self.user.backend = settings.AUTHENTICATION_BACKENDS[0]
            except User.DoesNotExist:
                self.user = None
예제 #3
0
 def setUp(self):
     super(AuthTestCases, self).setUp()
     User = get_user_model()
     self.user = User.objects.create_user(
         username='******',
         password='******',
         email='*****@*****.**',
     )
예제 #4
0
    def test__get_template__function(self):
        u"""Проверка правильности работы функции get_template."""
        from django.http import HttpRequest
        from django.template.context import Context
        from django.template.context import RequestContext
        from m3_django_compat import get_template

        request = HttpRequest()
        request.user = get_user_model()(username='******')

        template = get_template('get_template.html')

        self.assertEqual(template.render({'var': 'value'}),
                         '<p>value</p><p></p>')
        self.assertEqual(template.render(Context({'var': 'value'})),
                         '<p>value</p><p></p>')
        self.assertEqual(template.render({'var': 'value'}, request),
                         '<p>value</p><p>testuser</p>')
        self.assertEqual(template.render(Context({'var': 'value'}), request),
                         '<p>value</p><p>testuser</p>')
        self.assertEqual(
            template.render(RequestContext(request, {'var': 'value'})),
            '<p>value</p><p>testuser</p>')
예제 #5
0
 def _is_user_exist(self, username):
     return get_user_model().objects.filter(username=username).exists()
예제 #6
0
 def _create_user(self, username):
     user = get_user_model()(username=username)
     user.set_unusable_password()
     user.save()
예제 #7
0
    def tearDownClass(cls):
        get_user_model().objects.all().delete()

        super(AtomicTestCase, cls).tearDownClass()
예제 #8
0
 def test_get_user_model(self):
     u"""Проверка функции get_user_model."""
     user_model = get_model(*AUTH_USER_MODEL.split('.'))
     self.assertIs(user_model, get_user_model())
예제 #9
0
 def _allow(self, db, app_label, model_name):
     return (db == DEFAULT_DB_ALIAS
             and get_model(app_label, model_name) is get_user_model())