How to use response_401 method in Django Test Plus

Best Python code snippet using django-test-plus_python

test_api.py

Source:test_api.py Github

copy

Full Screen

...62 self.user1 = self.make_user("u1")63class PublisherViews(GameCatalogAbstractTestCase):64 def test_list_retrieval(self):65 self.get("api-publisher-list", extra=self.extra)66 self.response_401()67 with self.login(username=self.user1.username):68 self.get("api-publisher-list", extra=self.extra)69 def test_detail_retrieval(self):70 url_kwargs = {"slug": self.mcg.slug, **self.extra}71 self.get("api-publisher-detail", **url_kwargs)72 self.response_401()73 with self.login(username=self.user1.username):74 self.get("api-publisher-detail", **url_kwargs)75 serialized_data = GamerPublisherSerializer(76 self.mcg,77 context={"request": self.last_response.wsgi_request, "format": "json"},78 )79 assert serialized_data.data == self.last_response.data80class GameSystemViews(GameCatalogAbstractTestCase):81 def test_list_view(self):82 url_kwargs = self.extra83 self.get("api-system-list", **url_kwargs)84 self.response_401()85 with self.login(username=self.user1.username):86 self.get("api-system-list", **url_kwargs)87 def test_detail_view(self):88 url_kwargs = {"slug": self.cypher.slug, **self.extra}89 self.get("api-system-detail", **url_kwargs)90 self.response_401()91 with self.login(username=self.user1.username):92 self.get("api-system-detail", **url_kwargs)93 serialized_object = GameSystemSerializer(94 self.cypher,95 context={"request": self.last_response.wsgi_request, "format": "json"},96 )97 assert serialized_object.data == self.last_response.data98class PublishedGameViews(GameCatalogAbstractTestCase):99 def test_list_view(self):100 url_kwargs = self.extra101 self.get("api-publishedgame-list", **url_kwargs)102 self.response_401()103 with self.login(username=self.user1.username):104 self.get("api-publishedgame-list", **url_kwargs)105 def test_detail_view(self):106 url_kwargs = {"slug": self.numensource.slug, **self.extra}107 print(type(self.numensource))108 self.get("api-publishedgame-detail", **url_kwargs)109 self.response_401()110 with self.login(username=self.user1.username):111 print(reverse("api-publishedgame-detail", kwargs=url_kwargs))112 self.get("api-publishedgame-detail", **url_kwargs)113 serialized_object = PublishedGamerSerializer(114 self.numensource,115 context={"request": self.last_response.wsgi_request, "format": "json"},116 )117 assert serialized_object.data == self.last_response.data118class EditionViews(GameCatalogAbstractTestCase):119 def test_list_view(self):120 url_kwargs = {"parent_lookup_game__slug": self.numensource.slug, **self.extra}121 self.get("api-edition-list", **url_kwargs)122 self.response_401()123 with self.login(username=self.user1.username):124 self.get("api-edition-list", **url_kwargs)125 def test_detail_view(self):126 url_kwargs = {127 "parent_lookup_game__slug": self.numensource.slug,128 "slug": self.numen.slug,129 **self.extra,130 }131 self.get("api-edition-detail", **url_kwargs)132 self.response_401()133 with self.login(username=self.user1.username):134 self.get("api-edition-detail", **url_kwargs)135 serialized_object = GameEditionSerializer(136 self.numen,137 context={"request": self.last_response.wsgi_request, "format": "json"},138 )139 assert serialized_object.data == self.last_response.data140class SourcebookViews(GameCatalogAbstractTestCase):141 def setUp(self):142 super().setUp()143 self.url_kwargs = {144 "parent_lookup_edition__game__slug": self.numensource.slug,145 "parent_lookup_edition__slug": self.numen.slug,146 **self.extra,147 }148 def test_list_view(self):149 self.get("api-sourcebook-list", **self.url_kwargs)150 self.response_401()151 with self.login(username=self.user1.username):152 self.get("api-sourcebook-list", **self.url_kwargs)153 def test_detail_view(self):154 url_kwargs = self.url_kwargs.copy()155 url_kwargs["slug"] = self.discovery.slug156 self.get("api-sourcebook-detail", **url_kwargs)157 self.response_401()158 with self.login(username=self.user1.username):159 self.get("api-sourcebook-detail", **url_kwargs)160 request_used = self.last_response.wsgi_request161 serialized_object = SourcebookSerializer(162 self.discovery,163 context={"request": self.last_response.wsgi_request, "format": "json"},164 )165 assert serialized_object.data == self.last_response.data166class PublishedModuleViews(GameCatalogAbstractTestCase):167 def setUp(self):168 super().setUp()169 self.url_kwargs = {170 "parent_lookup_parent_game_edition__game__slug": self.numensource.slug,171 "parent_lookup_parent_game_edition__slug": self.numen.slug,172 **self.extra,173 }174 def test_list_view(self):175 self.get("api-publishedmodule-list", **self.url_kwargs)176 self.response_401()177 with self.login(username=self.user1.username):178 self.get("api-publishedmodule-list", **self.url_kwargs)179 def test_detail_view(self):180 url_kwargs = self.url_kwargs.copy()181 url_kwargs["slug"] = self.vv.slug182 self.get("api-publishedmodule-detail", **url_kwargs)183 self.response_401()184 with self.login(username=self.user1.username):185 self.get("api-publishedmodule-detail", **url_kwargs)186 serialized_object = PublishedModuleSerializer(187 self.vv,188 context={"request": self.last_response.wsgi_request, "format": "json"},189 )...

Full Screen

Full Screen

test___init__.py

Source:test___init__.py Github

copy

Full Screen

1# Copyright (c) 2013 Rackspace, Inc.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or12# implied.13# See the License for the specific language governing permissions and14# limitations under the License.15from mock import patch16from testtools import TestCase17from webob import Request18from curryproxy.responses import ErrorResponse19from curryproxy.tests.utils import RequestsResponseMock20class Test__Init__(TestCase):21 def test_400_class_status_code(self):22 request = Request.blank('http://example.com/1')23 headers = {'Content-Type': 'text/html'}24 response_200 = RequestsResponseMock(status_code=200, headers=headers)25 response_401 = RequestsResponseMock(status_code=401, headers=headers)26 error_response = ErrorResponse(request,27 [response_200, response_401],28 [])29 self.assertEqual(401, error_response.response.status_code)30 def test_502_aggregate_response_bodies(self):31 with patch.object(ErrorResponse, '_aggregate_response_bodies') as m:32 headers = {'Content-Type': 'text/html'}33 response_1 = RequestsResponseMock(status_code=200, headers=headers)34 response_2 = RequestsResponseMock(status_code=502, headers=headers)35 ErrorResponse(None, [response_1, response_2], [])36 m.assert_called_with()37 def test_502_status_code(self):38 headers = {'Content-Type': 'text/html'}39 response_200 = RequestsResponseMock(status_code=200, headers=headers)40 response_500 = RequestsResponseMock(status_code=500, headers=headers)41 error_response = ErrorResponse(None, [response_200, response_500], [])42 self.assertEqual(502, error_response.response.status_code)43 def test_priority_error_multiple(self):44 request = Request.blank('http://example.com/1')45 headers = {'Content-Type': 'text/html'}46 response_200 = RequestsResponseMock(status_code=200, headers=headers)47 response_500 = RequestsResponseMock(status_code=404, headers=headers)48 response_401 = RequestsResponseMock(status_code=401, headers=headers)49 responses = [response_200, response_500, response_401]50 error_response = ErrorResponse(request, responses, [401, 404])51 self.assertEqual(401, error_response.response.status_code)52 def test_priority_error_multiple_first_missing(self):53 request = Request.blank('http://example.com/1')54 headers = {'Content-Type': 'text/html'}55 response_200 = RequestsResponseMock(status_code=200, headers=headers)56 response_500 = RequestsResponseMock(status_code=404, headers=headers)57 response_401 = RequestsResponseMock(status_code=401, headers=headers)58 responses = [response_200, response_500, response_401]59 error_response = ErrorResponse(request, responses, [403, 404])60 self.assertEqual(404, error_response.response.status_code)61 def test_priority_error_single(self):62 request = Request.blank('http://example.com/1')63 headers = {'Content-Type': 'text/html'}64 response_200 = RequestsResponseMock(status_code=200, headers=headers)65 response_500 = RequestsResponseMock(status_code=500, headers=headers)66 response_401 = RequestsResponseMock(status_code=401, headers=headers)67 responses = [response_200, response_500, response_401]68 error_response = ErrorResponse(request, responses, [401])...

Full Screen

Full Screen

api.py

Source:api.py Github

copy

Full Screen

...48 $ref: '#/components/responses/401'49 """50 try:51 if g.user is None or g.user.is_anonymous:52 return self.response_401()53 except NoAuthorizationError:54 return self.response_401()55 return self.response(200, result=user_response_schema.dump(g.user))56 @expose("/roles/", methods=["GET"])57 @safe58 def get_my_roles(self) -> Response:59 """Get the user roles corresponding to the agent making the request60 ---61 get:62 description: >-63 Returns the user roles corresponding to the agent making the request,64 or returns a 401 error if the user is unauthenticated.65 responses:66 200:67 description: The current user68 content:69 application/json:70 schema:71 type: object72 properties:73 result:74 $ref: '#/components/schemas/UserResponseSchema'75 401:76 $ref: '#/components/responses/401'77 """78 try:79 if g.user is None or g.user.is_anonymous:80 return self.response_401()81 except NoAuthorizationError:82 return self.response_401()83 user = bootstrap_user_data(g.user, include_perms=True)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Django Test Plus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful