本文整理汇总了Python中auth.views.Login类的典型用法代码示例。如果您正苦于以下问题:Python Login类的具体用法?Python Login怎么用?Python Login使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Login类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_context_data
def test_get_context_data(self, get_mock):
request = RequestFactory().get('/')
request.META['HTTP_HOST'] = 'localhost:3333'
view = Login()
view.request = request
response_mock = Mock(status_code=200)
response_mock.json.return_value = {
"name": "oauth",
"data": {
"authorizeUrl":
"http://something.com/?redirect=__redirect_url__"
}
}
get_mock.return_value = response_mock
data = view.get_context_data()
self.assertDictEqual(data["scheme_info"], {
"name": "oauth",
"data": {
"authorizeUrl":
"http://something.com/?redirect=__redirect_url__"
},
})
self.assertEqual(
data["authorize_url"],
"http://something.com/?redirect=http://localhost:3333/auth/callback/"
)
示例2: test_should_set_username_in_the_session
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_send_request_post_to_tsuru_with_args_expected
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"}')
示例4: test_should_set_is_admin_to_false_when_its_missing
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"])
示例5: test_should_set_token_in_the_session
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"])
示例6: test_should_send_request_post_to_tsuru_with_args_expected
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"}')
示例7: test_should_set_is_admin_in_the_session
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"])
示例8: test_get_context_data
def test_get_context_data(self, get_mock):
view = Login()
response_mock = Mock(status_code=200)
response_mock.json.return_value = {"name": "oauth"}
get_mock.return_value = response_mock
data = view.get_context_data()
self.assertDictEqual(data["scheme_info"], {"name": "oauth"})
示例9: test_should_set_username_in_the_session
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"])
示例10: test_redirect_to_team_creation_settings_true
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()
示例11: test_scheme_info
def test_scheme_info(self, get_mock):
view = Login()
expected_url = '{}/auth/scheme'.format(settings.TSURU_HOST)
self.assertDictEqual(view.scheme_info(), {})
get_mock.assert_called_with(expected_url)
response_mock = Mock(status_code=200)
response_mock.json.return_value = {"name": "oauth"}
get_mock.return_value = response_mock
self.assertDictEqual(view.scheme_info(), {"name": "oauth"})
get_mock.assert_called_with(expected_url)
示例12: test_login_get
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)
示例13: test_should_validate_data_from_post
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'])
示例14: test_should_validate_data_from_post
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"])
示例15: test_redirect_to_team_creation_when_login_is_successful
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'])