本文整理汇总了Python中auth.views.Login.as_view方法的典型用法代码示例。如果您正苦于以下问题:Python Login.as_view方法的具体用法?Python Login.as_view怎么用?Python Login.as_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类auth.views.Login
的用法示例。
在下文中一共展示了Login.as_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_send_request_post_to_tsuru_with_args_expected
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_should_send_request_post_to_tsuru_with_args_expected(self, post):
data = {'username': '[email protected]', 'password': '123456'}
request = RequestFactory().post('/', data)
expected_url = '%s/users/[email protected]/tokens' % settings.TSURU_HOST
Login.as_view()(request)
self.assertEqual(1, post.call_count)
post.assert_called_with(expected_url,
data='{"password": "123456"}')
示例2: test_should_set_username_in_the_session
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_should_set_username_in_the_session(self, post):
post.return_value = Mock(status_code=200,
text='{"token": "t"}')
data = {'username': '[email protected]', 'password': '123456'}
request = RequestFactory().post('/', data)
request.session = {}
Login.as_view()(request)
self.assertEqual(data["username"], request.session["username"])
示例3: test_should_set_is_admin_to_false_when_its_missing
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_should_set_is_admin_to_false_when_its_missing(self, post):
response_mock = Mock(status_code=200)
response_mock.json.return_value = {"token": "my beautiful token"}
post.return_value = response_mock
data = {'username': '[email protected]', 'password': '123456'}
request = RequestFactory().post('/', data)
request.session = {}
Login.as_view()(request)
self.assertFalse(request.session["is_admin"])
示例4: test_should_set_token_in_the_session
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_should_set_token_in_the_session(self, post):
data = {'username': '[email protected]', 'password': '123456'}
request = RequestFactory().post('/', data)
request.session = {}
text = '{"token": "my beautiful token"}'
post.return_value = Mock(status_code=200, text=text)
Login.as_view()(request)
self.assertEqual('type my beautiful token',
request.session["tsuru_token"])
示例5: test_should_send_request_post_to_tsuru_with_args_expected
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_should_send_request_post_to_tsuru_with_args_expected(self, get_mock, post):
data = {"username": "[email protected]", "password": "123456"}
request = RequestFactory().post("/", data)
request.session = {"next_url": "/"}
expected_url = "%s/users/[email protected]/tokens" % settings.TSURU_HOST
Login.as_view()(request)
self.assertEqual(1, post.call_count)
post.assert_called_with(expected_url,
data='{"password": "123456"}')
示例6: test_should_set_is_admin_in_the_session
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_should_set_is_admin_in_the_session(self, post):
response_mock = Mock(status_code=200)
response_mock.json.return_value = {"token": "my beautiful token",
"is_admin": True}
post.return_value = response_mock
data = {"username": "[email protected]", "password": "123456"}
request = RequestFactory().post("/", data)
request.session = {}
Login.as_view()(request)
self.assertTrue(request.session["is_admin"])
示例7: test_should_set_username_in_the_session
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_should_set_username_in_the_session(self, post):
response_mock = Mock(status_code=200)
response_mock.json.return_value = {"token": "my beautiful token",
"is_admin": True}
post.return_value = response_mock
data = {'username': '[email protected]', 'password': '123456'}
request = RequestFactory().post('/', data)
request.session = {}
Login.as_view()(request)
self.assertEqual(data["username"], request.session["username"])
示例8: test_redirect_to_team_creation_settings_true
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_redirect_to_team_creation_settings_true(self, post):
data = {'username': '[email protected]', 'password': '123456'}
request = RequestFactory().post('/intro', data)
request.session = {}
text = '{"token": "my beautiful token"}'
post.return_value = Mock(status_code=200, text=text)
response = Login.as_view()(request)
self.assertIsInstance(response, HttpResponseRedirect)
self.assertEqual('/intro', response['Location'])
response = Login.as_view()(request)
self.assertIsInstance(response, HttpResponseRedirect)
self.assertEqual('/apps', response['Location'])
Intro.objects.filter(email=data['username']).delete()
示例9: test_login_get
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_login_get(self, get_mock):
request = RequestFactory().get("/")
request.session = {"next_url": "/"}
response = Login.as_view()(request)
self.assertIn("auth/login.html", response.template_name)
form = response.context_data["form"]
self.assertIsInstance(form, LoginForm)
示例10: test_should_validate_data_from_post
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_should_validate_data_from_post(self, get_mock):
data = {'username': 'invalid name', 'password': ''}
request = RequestFactory().post('/', data)
response = Login.as_view()(request)
form = response.context_data['form']
self.assertIn('auth/login.html', response.template_name)
self.assertIsInstance(form, LoginForm)
self.assertEqual('invalid name', form.data['username'])
示例11: test_should_validate_data_from_post
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_should_validate_data_from_post(self, get_mock):
data = {"username": "invalid name", "password": ""}
request = RequestFactory().post("/", data)
request.session = {"next_url": "/"}
response = Login.as_view()(request)
form = response.context_data["form"]
self.assertIn("auth/login.html", response.template_name)
self.assertIsInstance(form, LoginForm)
self.assertEqual("invalid name", form.data["username"])
示例12: test_redirect_to_team_creation_when_login_is_successful
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_redirect_to_team_creation_when_login_is_successful(self, post):
data = {'username': '[email protected]', 'password': '123456'}
request = RequestFactory().post('/', data)
request.session = {}
text = '{"token": "my beautiful token"}'
post.return_value = Mock(status_code=200, text=text)
response = Login.as_view()(request)
self.assertIsInstance(response, HttpResponseRedirect)
self.assertEqual('/apps', response['Location'])
示例13: test_redirect_to_team_creation_settings_false
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_redirect_to_team_creation_settings_false(self, post):
response_mock = Mock(status_code=200)
response_mock.json.return_value = {"token": "my beautiful token",
"is_admin": True}
post.return_value = response_mock
data = {'username': '[email protected]', 'password': '123456'}
request = RequestFactory().post('/', data)
request.session = {}
response = Login.as_view()(request)
self.assertIsInstance(response, HttpResponseRedirect)
self.assertEqual('/apps', response['Location'])
示例14: test_redirect_to_apps
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_redirect_to_apps(self, post):
response_mock = Mock(status_code=200)
response_mock.json.return_value = {"token": "my beautiful token",
"is_admin": True}
post.return_value = response_mock
data = {"username": "[email protected]", "password": "123456"}
request = RequestFactory().post("/", data)
request.session = {}
response = Login.as_view()(request)
self.assertIsInstance(response, HttpResponseRedirect)
self.assertEqual("/apps", response["Location"])
示例15: test_redirect_to_apps_when_the_intro_alread_exist
# 需要导入模块: from auth.views import Login [as 别名]
# 或者: from auth.views.Login import as_view [as 别名]
def test_redirect_to_apps_when_the_intro_alread_exist(self, post):
data = {'username': '[email protected]', 'password': '123456'}
intro = Intro.objects.create(email=data['username'])
request = RequestFactory().post('/', data)
request.session = {}
text = '{"token": "my beautiful token"}'
post.return_value = Mock(status_code=200, text=text)
response = Login.as_view()(request)
self.assertIsInstance(response, HttpResponseRedirect)
self.assertEqual('/apps', response['Location'])
intro.delete()