当前位置: 首页>>代码示例>>Python>>正文


Python HttpRequest.user方法代码示例

本文整理汇总了Python中django.http.request.HttpRequest.user方法的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest.user方法的具体用法?Python HttpRequest.user怎么用?Python HttpRequest.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.http.request.HttpRequest的用法示例。


在下文中一共展示了HttpRequest.user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_upload_file

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
    def test_upload_file(self):
        VARIANT_SET_NAME = 'newVariant'
        self.assertEqual(0, VariantSet.objects.count())
        refGenome = self.common_entities['reference_genome']
        request = HttpRequest()
        request.POST = {
            'refGenomeUid': refGenome.uid,
            'variantSetName': VARIANT_SET_NAME,
            'createSetType': 'from-file'
        }
        request.method = 'POST'
        request.user = self.common_entities['user']
        authenticate(username=TEST_USERNAME, password=TEST_PASSWORD)
        self.assertTrue(request.user.is_authenticated())

        #random test file selected
        variant_set_file = os.path.join(GD_ROOT, 'test_data',
                'recoli_321UAG_variant_set_upload.vcf')
        mock_uploaded_file = UploadedFile(
                file=StringIO.StringIO(),
                name=variant_set_file)
        request.FILES['vcfFile'] = mock_uploaded_file

        response = create_variant_set(request)
        self.assertEqual(STATUS_CODE__SUCCESS, response.status_code)

        variantsets = VariantSet.objects.all()
        self.assertEqual(1, len(variantsets))
        self.assertEqual(VARIANT_SET_NAME, VariantSet.objects.get().label)
        self.assertEqual(refGenome, VariantSet.objects.get().reference_genome)
开发者ID:woodymit,项目名称:millstone,代码行数:32,代码来源:test_xhr_handlers.py

示例2: test_and

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
 def test_and(self):
     req = HttpRequest()
     req.user = AnonymousUser()
     self.assertTrue(AlwaysAndAlways(request=req).is_authorized())
     self.assertFalse(AlwaysAndNever(request=req).is_authorized())
     self.assertFalse(NeverAndAlways(request=req).is_authorized())
     self.assertFalse(NeverAndNever(request=req).is_authorized())
开发者ID:finnishnetsolutions,项目名称:nuortenideat,代码行数:9,代码来源:tests.py

示例3: test_list_owner_is_saved_if_user_is_authenticated

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
 def test_list_owner_is_saved_if_user_is_authenticated(self):
     request = HttpRequest()
     request.user = User.objects.create(email='[email protected]')
     request.POST['text'] = 'new list item'
     new_list(request)
     list_ = List.objects.first()
     self.assertEqual(list_.owner, request.user)
开发者ID:liscju,项目名称:superlists,代码行数:9,代码来源:test_views.py

示例4: handle

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
    def handle(self, *args, **options):
        # Check params
        if len(args) != 4:
            raise CommandError('Invalid number of parameters!')

        # Get translation object
        try:
            translation = Translation.objects.get(
                subproject__project__slug=args[0],
                subproject__slug=args[1],
                language__code=args[2],
            )
        except Translation.DoesNotExist:
            raise CommandError('No matching translation project found!')

        # Get user
        try:
            user = User.objects.get(email=options['author'])
        except User.DoesNotExist:
            raise CommandError('Import user does not exist!')

        # Create fake request object
        request = HttpRequest()
        request.user = user

        # Process import
        try:
            with open(args[3], 'r') as handle:
                translation.merge_upload(
                    request, handle, False, method='suggest',
                    author=get_author_name(user),
                )
        except IOError:
            raise CommandError('Failed to import translation file!')
开发者ID:nrasic,项目名称:weblate,代码行数:36,代码来源:add_suggestions.py

示例5: handle

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
    def handle(self, *args, **options):
        # Check params
        if len(args) != 4:
            raise CommandError('Invalid number of parameters!')

        # Get translation object
        translation = self.get_translation(args)

        # Get user
        try:
            user = User.objects.get(email=options['author'])
        except User.DoesNotExist:
            raise CommandError('Import user does not exist!')

        # Create fake request object
        request = HttpRequest()
        request.user = user

        # Process import
        try:
            with open(args[3], 'rb') as handle:
                translation.merge_upload(
                    request, handle, False, method='suggest',
                    author=get_author_name(user),
                )
        except IOError:
            raise CommandError('Failed to import translation file!')
开发者ID:Acidburn0zzz,项目名称:weblate,代码行数:29,代码来源:add_suggestions.py

示例6: test_mixed

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
 def test_mixed(self):
     req = HttpRequest()
     req.user = AnonymousUser()
     AAAAndAON = And(AlwaysAndAlways, AlwaysOrNever)
     AOAAndAAN = And(AlwaysOrAlways, AlwaysAndNever)
     self.assertTrue(AAAAndAON(request=req).is_authorized())
     self.assertFalse(AOAAndAAN(request=req).is_authorized())
开发者ID:finnishnetsolutions,项目名称:nuortenideat,代码行数:9,代码来源:tests.py

示例7: test_upload_single_sample__unpaired

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
    def test_upload_single_sample__unpaired(self):
        project = self.common_entities['project']
        request = HttpRequest()
        request.POST = {
            'projectUid': project.uid
        }
        request.method = 'POST'
        request.user = self.common_entities['user']
        authenticate(username=TEST_USERNAME, password=TEST_PASSWORD)
        self.assertTrue(request.user.is_authenticated())

        EXPERIMENT_SAMPLE_LABEL = 'my sample'
        request.POST['sampleLabel'] = EXPERIMENT_SAMPLE_LABEL

        request.FILES['fastq1'] = UploadedFile(
                file=open(TEST_FQ1_FILE),
                name='read1.fq')

        response = upload_single_sample(request)
        self.assertEqual(STATUS_CODE__SUCCESS, response.status_code)
        self.assertFalse('error' in json.loads(response.content))

        sample = ExperimentSample.objects.get(label=EXPERIMENT_SAMPLE_LABEL)
        self.assertTrue(sample)

        datasets = sample.dataset_set.all()
        # num_datasets: 1 fastq + 1 fastqc = 2
        self.assertEqual(2, len(datasets))
        for dataset in datasets:
            self.assertEqual(Dataset.STATUS.READY, dataset.status)
开发者ID:woodymit,项目名称:millstone,代码行数:32,代码来源:test_xhr_handlers.py

示例8: test_not

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
 def test_not(self):
     req = HttpRequest()
     req.user = AnonymousUser()
     self.assertFalse(NotAlways(request=req).is_authorized())
     self.assertTrue(NotNever(request=req).is_authorized())
     self.assertFalse(NotNeverAlways(request=req).is_authorized())
     self.assertFalse(NotAlwaysNever(request=req).is_authorized())
     self.assertTrue(NotNeverNever(request=req).is_authorized())
开发者ID:finnishnetsolutions,项目名称:nuortenideat,代码行数:10,代码来源:tests.py

示例9: get_request

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
 def get_request(self):
     request = HttpRequest()
     request.META['REMOTE_ADDR'] = '1.2.3.4'
     request.method = 'POST'
     request.session = SessionStore()
     request._messages = default_storage(request)
     request.user = AnonymousUser()
     return request
开发者ID:nijel,项目名称:weblate,代码行数:10,代码来源:test_ratelimit.py

示例10: test_object_permitted

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
 def test_object_permitted(self):
     tmpl = """
     {% if "editable" in perm.permitter_test.CanEditObject %}
         success!
     {% endif %}
     """
     req = HttpRequest()
     req.user = AnonymousUser()
     resp = Template(tmpl).render(RequestContext(req))
     self.assertTrue('success!' in resp)
开发者ID:finnishnetsolutions,项目名称:nuortenideat,代码行数:12,代码来源:tests.py

示例11: test_missing_required_perm_arguments

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
 def test_missing_required_perm_arguments(self):
     tmpl = """
     {% if perm.permitter_test.CanEditObject %}
         fail
     {% endif %}
     """
     req = HttpRequest()
     req.user = User()
     tmpl, ctx = Template(tmpl), RequestContext(req)
     self.assertRaises(KeyError, lambda: tmpl.render(ctx))
开发者ID:finnishnetsolutions,项目名称:nuortenideat,代码行数:12,代码来源:tests.py

示例12: test_simple_not_permitted

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
 def test_simple_not_permitted(self):
     tmpl = """
     {% if not perm.permitter_test.NeverAuthorized %}
         success!
     {% endif %}
     """
     req = HttpRequest()
     req.user = AnonymousUser()
     resp = Template(tmpl).render(RequestContext(req))
     self.assertTrue('success!' in resp)
开发者ID:finnishnetsolutions,项目名称:nuortenideat,代码行数:12,代码来源:tests.py

示例13: _get_list_response_internal

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
    def _get_list_response_internal(self, **kwargs):
        logger.info('kwargs: %r', kwargs)
        request = HttpRequest()
        class User:
            is_superuser = True
#             @staticmethod
#             def is_superuser():
#                 return true
        request.user = User
        result = self._get_list_response(request, **kwargs)
        return result
开发者ID:hmsiccbl,项目名称:lims,代码行数:13,代码来源:sqlalchemy_resource.py

示例14: test_commit_groupping

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
    def test_commit_groupping(self):
        component = self.create_component()
        translation = component.translation_set.get(language_code='cs')
        request = HttpRequest()
        request.user = create_test_user()
        start_rev = component.repository.last_revision
        # Initial translation
        for unit in translation.unit_set.all():
            unit.translate(request, 'test2', STATE_TRANSLATED)
        # Translation completed, no commit forced
        self.assertEqual(start_rev, component.repository.last_revision)
        # Translation from same author should not trigger commit
        for unit in translation.unit_set.all():
            unit.translate(request, 'test3', STATE_TRANSLATED)
        for unit in translation.unit_set.all():
            unit.translate(request, 'test4', STATE_TRANSLATED)
        self.assertEqual(start_rev, component.repository.last_revision)
        # Translation from other author should trigger commmit
        for i, unit in enumerate(translation.unit_set.all()):
            request.user = User.objects.create(
                full_name='User {}'.format(unit.pk),
                username='user-{}'.format(unit.pk),
                email='{}@example.com'.format(unit.pk)
            )
            # Fetch current pending state, it might have been
            # updated by background commit
            unit.pending = Unit.objects.get(pk=unit.pk).pending
            unit.translate(request, 'test', STATE_TRANSLATED)
            if i == 0:
                # First edit should trigger commit
                self.assertNotEqual(
                    start_rev, component.repository.last_revision
                )
                start_rev = component.repository.last_revision

        # No further commit now
        self.assertEqual(start_rev, component.repository.last_revision)

        # Commit pending changes
        translation.commit_pending('test', None)
        self.assertNotEqual(start_rev, component.repository.last_revision)
开发者ID:nijel,项目名称:weblate,代码行数:43,代码来源:test_models.py

示例15: test_email_confirmation_required_w_redirect

# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import user [as 别名]
    def test_email_confirmation_required_w_redirect(self):
        request = HttpRequest()
        request.user = self.u
        # Set the required properties of your request
        function = lambda x: x
        decorator = email_confirmation_required(function)
        response = decorator(request)

        rurl = reverse("gogonzo_email_confirmation:alert", kwargs={"email": self.u.email})

        # Testing that it redirects, since the user is not confirmed
        self.assertTrue(rurl == response.url)
开发者ID:ImportantCool,项目名称:gogonzo,代码行数:14,代码来源:tests.py


注:本文中的django.http.request.HttpRequest.user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。