django.test.RequestFactory.get

Here are the examples of the python api django.test.RequestFactory.get taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

162 Examples 7

Example 151

Project: django-waffle Source File: test_waffle.py
Function: get
def get(**kw):
    request = RequestFactory().get('/foo', data=kw)
    request.user = AnonymousUser()
    return request

Example 152

Project: django-sudo Source File: base.py
Function: get
    def get(self, *args, **kwargs):
        return RequestFactory().get(*args, **kwargs)

Example 153

Project: browsercompat Source File: tests.py
Function: set_up
    def setUp(self):
        self.view = MyAuthorizationView()
        self.view.request = RequestFactory().get('/authorize')

Example 154

Project: django-experiments Source File: test_templatetags.py
    def test_template_auto_create_on(self):
        request = RequestFactory().get('/')
        request.user = User.objects.create(username='test')
        Template("{% load experiments %}{% experiment test_experiment control %}{% endexperiment %}").render(Context({'request': request}))
        self.assertTrue(Experiment.objects.filter(name="test_experiment").exists())

Example 155

Project: django-speedbar Source File: tests.py
    def test_templatetags_loaded(self):
        request = RequestFactory().get('/')
        request.user = User.objects.create(username='test')
        Template('{% load speedbar %}{% metric "overall" "time" %}').render(Context({'request': request}))

Example 156

Project: fjord Source File: test_browsers.py
Function: test_middleware
    def test_middleware(self):
        """Check that the middleware injects data properly."""
        ua = 'Mozilla/5.0 (Android; Mobile; rv:14.0) Gecko/14.0 Firefox/14.0.2'
        d = {
            'HTTP_USER_AGENT': ua,
        }
        request = test.RequestFactory().get('/', **d)
        ret = middleware.UserAgentMiddleware().process_request(request)
        assert ret is None

        checks = {
            'browser': 'Firefox for Android',
            'browser_version': '14.0.2',
            'platform': 'Android',
            'platform_version': '',
            'mobile': True,
        }

        assert hasattr(request, 'BROWSER')
        for k, v in checks.items():
            assert hasattr(request.BROWSER, k)
            assert getattr(request.BROWSER, k) == v

Example 157

Project: kuma Source File: generate_sphinx_template.py
    def handle(self, *args, **options):

        # Not ideal, but we need to temporarily remove inline elements as a
        # void/ignored element
        # TO DO:  Can this clone code be shortened?
        new_void_set = set()
        for item in html5lib_constants.voidElements:
            new_void_set.add(item)
        new_void_set.remove('link')
        new_void_set.remove('img')
        html5lib_constants.voidElements = frozenset(new_void_set)

        # Create a mock request for the sake of rendering the template
        request = RequestFactory().get('/')
        request.LANGUAGE_CODE = settings.LANGUAGE_CODE  # for Jinja2
        translation.activate(settings.LANGUAGE_CODE)  # for context var LANG
        host = 'developer.mozilla.org'
        request.META['SERVER_NAME'] = host
        this_year = datetime.date.today().year
        # Load the page with sphinx template
        with override_settings(
                ALLOWED_HOSTS=[host],
                SITE_URL=settings.PRODUCTION_URL,
                DEBUG=False):
            response = render(request, 'wiki/sphinx.html',
                              {'is_sphinx': True,
                               'this_year': this_year})
        content = response.content

        # Use a filter to make links absolute
        tool = parse(content, is_full_docuement=True)
        content = tool.absolutizeAddresses(
            base_url=settings.PRODUCTION_URL,
            tag_attributes={
                'a': 'href',
                'img': 'src',
                'form': 'action',
                'link': 'href',
                'script': 'src'
            }).serialize()

        # Make in-comment script src absolute for IE
        content = content.replace('src="/static/',
                                  'src="%s/static/' % settings.PRODUCTION_URL)

        # Fix missing DOCTYPE
        assert content.startswith("<html")
        content = u"<!DOCTYPE html>\n" + content

        # Output the response
        print content.encode('utf8')

Example 158

Project: moztrap Source File: test_finder.py
Function: test_ajax
    @patch("moztrap.view.lists.finder.render")
    def test_ajax(self, render):
        """Ajax response is rendered column template."""
        render.return_value = "some HTML"

        MockFinder = Mock()
        f = MockFinder.return_value
        f.column_template.return_value = "some/finder/_column.html"
        f.objects.return_value = ["some", "objects"]

        req = RequestFactory().get(
            "/some/url",
            {"finder": "1", "col": "things", "id": "2"},
            HTTP_X_REQUESTED_WITH="XMLHttpRequest")
        res = self.on_template_response(
            {}, request=req, decorator=self.finder(MockFinder))

        self.assertEqual(res, "some HTML")

        self.assertEqual(
            render.call_args[0][1:],
            (
                "some/finder/_column.html",
                {
                    "colname": "things",
                    "finder": {
                        "finder": f,
                        "things": ["some", "objects"]
                        }
                    }
                )
            )

        f.column_template.assert_called_with("things")
        f.objects.assert_called_with("things", "2")

Example 159

Project: remo Source File: test_api.py
    def test_base(self):
        mentor = UserFactory.create()
        functional_areas = FunctionalAreaFactory.create_batch(2)
        user = UserFactory.create(userprofile__mentor=mentor, groups=['Rep'],
                                  userprofile__functional_areas=functional_areas)

        url = '/api/remo/v1/users/%s' % user.id
        request = RequestFactory().get(url)
        profile = user.userprofile
        data = UserProfileDetailedSerializer(user.userprofile, context={'request': request}).data

        eq_(data['first_name'], user.first_name)
        eq_(data['last_name'], user.last_name)
        eq_(data['display_name'], profile.display_name)
        eq_(data['date_joined_program'], profile.date_joined_program.strftime('%Y-%m-%d'))
        eq_(data['date_left_program'], profile.date_left_program)
        eq_(data['city'], profile.city)
        eq_(data['region'], profile.region)
        eq_(data['country'], profile.country)
        eq_(data['twitter_account'], profile.twitter_account)
        eq_(data['jabber_id'], profile.jabber_id)
        eq_(data['irc_name'], profile.irc_name)
        eq_(data['wiki_profile_url'], profile.wiki_profile_url)
        eq_(data['irc_channels'], profile.irc_channels)
        eq_(data['linkedin_url'], profile.linkedin_url)
        eq_(data['facebook_url'], profile.facebook_url)
        eq_(data['diaspora_url'], profile.diaspora_url)
        eq_(data['bio'], profile.bio)
        eq_(data['mozillians_profile_url'], profile.mozillians_profile_url)
        eq_(data['timezone'], profile.timezone)
        eq_(data['groups'][0]['name'], 'Rep')
        eq_(data['mentor']['first_name'], mentor.first_name)
        eq_(data['mentor']['last_name'], mentor.last_name)
        eq_(data['mentor']['display_name'], mentor.userprofile.display_name)
        ok_(data['mentor']['_url'])
        eq_(data['functional_areas'][0]['name'], functional_areas[0].name)
        eq_(data['functional_areas'][1]['name'], functional_areas[1].name)

Example 160

Project: snippets-service Source File: test_middleware.py
    def test_unknown_url(self):
        request = RequestFactory().get('/admin')
        self.assertEqual(self.middleware.process_request(request), None)

Example 161

Project: pombola Source File: tests.py
    def test_mp_with_two_constituencies(self):
        Position.objects.create(
            category='political',
            person=self.person,
            place=self.constituency,
            organisation=self.na,
            title=self.na_member_title,
            start_date=ApproximateDate(2015, 1, 1),
            )

        Position.objects.create(
            category='political',
            person=self.person,
            place=self.constituency2,
            organisation=self.na,
            title=self.na_member_title,
            start_date=ApproximateDate(2015, 1, 2),
            )

        request = RequestFactory().get('/person/test-person/')
        request.user = AnonymousUser()
        response = KEPersonDetail.as_view()(request, slug='test-person')

        self.assertEqual(len(response.context_data['constituencies']), 1)
        self.assertEqual(response.context_data['constituencies'][0], self.constituency2)

        # Check that admins got mailed.
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            mail.outbox[0].subject,
            '[Django] ERROR: test-person - Too many NA memberships (2)',
            )

Example 162

Project: django-GNU-Terry-Pratchett Source File: test_decorators.py
Function: test_view_decorator
def test_view_decorator():
    request = RequestFactory().get('/')
    response = view(request)
    eq_(response['x-clacks-overhead'], 'GNU Terry Pratchett')
See More Examples - Go to Next Page
Page 1 Page 2 Page 3 Page 4 Selected