コード例 #1
0
    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
0
 def test_should_send_request_post_to_tsuru_with_args_expected(self, post):
     data = {'username': '******', 'password': '******'}
     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": "******"}')
コード例 #3
0
 def test_should_set_username_in_the_session(self, post):
     post.return_value = Mock(status_code=200, text='{"token": "t"}')
     data = {'username': '******', 'password': '******'}
     request = RequestFactory().post('/', data)
     request.session = {}
     Login.as_view()(request)
     self.assertEqual(data["username"], request.session["username"])
コード例 #4
0
 def test_should_send_request_post_to_tsuru_with_args_expected(self, post):
     data = {'username': '******', 'password': '******'}
     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": "******"}')
コード例 #5
0
ファイル: test_login_view.py プロジェクト: pombredanne/abyss
 def test_should_set_username_in_the_session(self, post):
     post.return_value = Mock(status_code=200,
                              text='{"token": "t"}')
     data = {'username': '******', 'password': '******'}
     request = RequestFactory().post('/', data)
     request.session = {}
     Login.as_view()(request)
     self.assertEqual(data["username"], request.session["username"])
コード例 #6
0
 def test_should_set_token_in_the_session(self, post):
     data = {'username': '******', 'password': '******'}
     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"])
コード例 #7
0
 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': '******', 'password': '******'}
     request = RequestFactory().post('/', data)
     request.session = {}
     Login.as_view()(request)
     self.assertFalse(request.session["is_admin"])
コード例 #8
0
 def test_should_send_request_post_to_tsuru_with_args_expected(
         self, get_mock, post):
     data = {"username": "******", "password": "******"}
     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": "******"}')
コード例 #9
0
ファイル: test_login_view.py プロジェクト: pombredanne/abyss
 def test_should_set_token_in_the_session(self, post):
     data = {'username': '******', 'password': '******'}
     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"])
コード例 #10
0
 def test_should_send_request_post_to_tsuru_with_args_expected(self, get_mock, post):
     data = {"username": "******", "password": "******"}
     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": "******"}')
コード例 #11
0
 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': '******', 'password': '******'}
     request = RequestFactory().post('/', data)
     request.session = {}
     Login.as_view()(request)
     self.assertFalse(request.session["is_admin"])
コード例 #12
0
 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": "******", "password": "******"}
     request = RequestFactory().post("/", data)
     request.session = {}
     Login.as_view()(request)
     self.assertTrue(request.session["is_admin"])
コード例 #13
0
    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"})
コード例 #14
0
 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': '******', 'password': '******'}
     request = RequestFactory().post('/', data)
     request.session = {}
     Login.as_view()(request)
     self.assertEqual(data["username"], request.session["username"])
コード例 #15
0
 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': '******', 'password': '******'}
     request = RequestFactory().post('/', data)
     request.session = {}
     Login.as_view()(request)
     self.assertEqual(data["username"], request.session["username"])
コード例 #16
0
    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"})
コード例 #17
0
 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": "******", "password": "******"}
     request = RequestFactory().post("/", data)
     request.session = {}
     Login.as_view()(request)
     self.assertTrue(request.session["is_admin"])
コード例 #18
0
 def test_redirect_to_team_creation_settings_true(self, post):
     data = {'username': '******', 'password': '******'}
     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()
コード例 #19
0
ファイル: test_login_view.py プロジェクト: pombredanne/abyss
 def test_redirect_to_team_creation_settings_true(self, post):
     data = {'username': '******', 'password': '******'}
     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()
コード例 #20
0
    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)
コード例 #21
0
    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)
コード例 #22
0
 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)
コード例 #23
0
 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)
コード例 #24
0
    def test_get_context_data_with_data_is_none(self, get_mock):
        request = RequestFactory().get("/")
        request.META["HTTP_HOST"] = "localhost:3333"
        request.session = {"next_url": "/"}
        view = Login()
        view.request = request

        response_mock = Mock(status_code=200)
        response_mock.json.return_value = {"name": "native", "data": None}
        get_mock.return_value = response_mock

        data = view.get_context_data()

        self.assertDictEqual(data["scheme_info"], {
            "name": "native",
            "data": None,
        })
コード例 #25
0
 def test_should_validate_data_from_post(self):
     data = {'username': '******', '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'])
コード例 #26
0
 def test_should_validate_data_from_post(self, get_mock):
     data = {'username': '******', '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'])
コード例 #27
0
 def test_should_validate_data_from_post(self, get_mock):
     data = {"username": "******", "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"])
コード例 #28
0
ファイル: test_login_view.py プロジェクト: pombredanne/abyss
 def test_redirect_to_team_creation_when_login_is_successful(self, post):
     data = {'username': '******', 'password': '******'}
     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'])
コード例 #29
0
 def test_redirect_to_team_creation_when_login_is_successful(self, post):
     data = {'username': '******', 'password': '******'}
     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'])
コード例 #30
0
 def test_should_validate_data_from_post(self, get_mock):
     data = {"username": "******", "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"])
コード例 #31
0
    def test_get_context_data_with_data_is_none(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": "native",
            "data": None
        }
        get_mock.return_value = response_mock

        data = view.get_context_data()

        self.assertDictEqual(data["scheme_info"], {
            "name": "native",
            "data": None,
        })
コード例 #32
0
ファイル: test_login_view.py プロジェクト: pombredanne/abyss
 def test_redirect_to_apps_when_the_intro_alread_exist(self, post):
     data = {'username': '******', 'password': '******'}
     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()
コード例 #33
0
 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": "******", "password": "******"}
     request = RequestFactory().post("/", data)
     request.session = {}
     response = Login.as_view()(request)
     self.assertIsInstance(response, HttpResponseRedirect)
     self.assertEqual("/apps", response["Location"])
コード例 #34
0
 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': '******', 'password': '******'}
     request = RequestFactory().post('/', data)
     request.session = {}
     response = Login.as_view()(request)
     self.assertIsInstance(response, HttpResponseRedirect)
     self.assertEqual('/apps', response['Location'])
コード例 #35
0
 def test_redirect_to_apps_when_the_intro_alread_exist(self, post):
     data = {'username': '******', 'password': '******'}
     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()
コード例 #36
0
 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': '******', 'password': '******'}
     request = RequestFactory().post('/', data)
     request.session = {}
     response = Login.as_view()(request)
     self.assertIsInstance(response, HttpResponseRedirect)
     self.assertEqual('/apps', response['Location'])
コード例 #37
0
 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": "******", "password": "******"}
     request = RequestFactory().post("/", data)
     request.session = {}
     response = Login.as_view()(request)
     self.assertIsInstance(response, HttpResponseRedirect)
     self.assertEqual("/apps", response["Location"])
コード例 #38
0
ファイル: urls.py プロジェクト: rbwong/tadhack2014
from django.conf.urls import patterns, include, url
from django.contrib.auth.decorators import login_required
from auth.views import Register, Login, Logout


from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
                       url(r'^register/$', login_required(Register.as_view()),
                           name='register'),
                       url(r'^login/$', Login.as_view(), name='login'),
                       url(r'^logout/$', Logout.as_view(), name='logout'),
                       )
コード例 #39
0
ファイル: urls.py プロジェクト: prateek-adhikari/poller
from django.urls import path
from auth.views import Login, Logout
urlpatterns = [
    path('login/', Login.as_view(), name="auth_login"),
    path('logout/', Logout.as_view(), name="auth_logout"),
]
コード例 #40
0
 def test_login_get(self):
     request = RequestFactory().get('/')
     response = Login.as_view()(request)
     self.assertIn('auth/login.html', response.template_name)
     form = response.context_data['form']
     self.assertIsInstance(form, LoginForm)
コード例 #41
0
from django.urls import path
from auth.views import ListUsers, Login, GoogleSignIn
from rest_framework_simplejwt import views as jwt_views

urlpatterns = [
    path('users', ListUsers.as_view()),
    path('auth/login', Login.as_view()),
    path('auth/google/signin', GoogleSignIn.as_view()),
    path('token',
         jwt_views.TokenObtainPairView.as_view(),
         name='token_obtain_pair'),
    path('token/refresh',
         jwt_views.TokenRefreshView.as_view(),
         name='token_refresh'),
    path('token/verify',
         jwt_views.TokenVerifyView.as_view(),
         name='token_verify'),
]
コード例 #42
0
ファイル: urls.py プロジェクト: taoprogramer/Blog
"""
from django.conf.urls import url, include
from django.contrib import admin
from django.views.generic import RedirectView
from article.views import ArticleDelete, ArticleList, ArticleDetail, ArticleEdit, ArticleUpdate
from auth.views import Login, Logout
from comment.views import CommentAdd,CommentDelete

urlpatterns = [
    url(r'^admin/', admin.site.urls),

    url(r'^$', RedirectView.as_view(url='article')),
    url(r'^article/$', ArticleList.as_view(), name='article_list'),

    url(r'^tag/(?P<tag_id>[0-9]+)/$', ArticleList.as_view()),

    url(r'^article/(?P<article_id>[0-9]+)/$', ArticleDetail.as_view()),
    url(r'^article/edit/(?P<article_id>[0-9]+)/$', ArticleEdit.as_view()),
    url(r'^article/update/$', ArticleUpdate.as_view(), name='article_edit'),
    url(r'^article/delete/$', ArticleDelete.as_view(), name='article_delete'),
    url(r'^article/add/$', ArticleEdit.as_view(), name='article_add'),


    url(r'^comment/add/$',CommentAdd.as_view(),name='comment_add'),
    url(r'^comment/delete/$',CommentDelete.as_view(),name='comment_delete'),

    url(r'^login/$', Login.as_view(), name='login'),
    url(r'^logout/$', Logout.as_view(), name='logout')

]
コード例 #43
0
from django.urls import path
from auth.views import Login, signup, Logout

urlpatterns = [
    path('login/', Login.as_view(), name='login'),
    path('logout/', Logout, name='logout'),
    path('signup/', signup, name='signup')
]
コード例 #44
0
 def test_login_get(self, get_mock):
     request = RequestFactory().get('/')
     response = Login.as_view()(request)
     self.assertIn('auth/login.html', response.template_name)
     form = response.context_data['form']
     self.assertIsInstance(form, LoginForm)