Exemplo n.º 1
0
    def test_send_mail_auth(self):
        """Test send mail authorization.

        Test user authorization for :view:`mailer/email_users`.
        """
        request_index = self.factory.get("/index")
        request_send_mail = self.factory.get("/mail/send")

        # ## Set anonymous user
        request_index.user = request_send_mail.user = AnonymousUser()
        self.confirm_email_users_unaccessible(request_index, request_send_mail)

        # ## Set normal user
        # User is not staff or superuser
        request_index.user = request_send_mail.user = self.user
        self.confirm_email_users_unaccessible(request_index, request_send_mail)

        # ## Set staff user
        self.user.is_staff = True
        self.user.save()

        # Confirm menu item displayed
        view = IndexView.as_view()
        response = view(request_index)
        self.assertContains(response, 'href="/mail/send/"', status_code=200)

        # Confirm send email view access
        response = email_users(request_send_mail)
        self.assertContains(response, '<h1>Email users</h1>', status_code=200)
Exemplo n.º 2
0
    def test_send_mail_auth(self):
        """Test send mail authorization.

        Test user authorization for :view:`mailer/email_users`.
        """
        request_index = self.factory.get("/index")
        request_send_mail = self.factory.get("/mail/send")

        # ## Set anonymous user
        request_index.user = request_send_mail.user = AnonymousUser()
        self.confirm_email_users_unaccessible(request_index, request_send_mail)

        # ## Set normal user
        # User is not staff or superuser
        request_index.user = request_send_mail.user = self.user
        self.confirm_email_users_unaccessible(request_index, request_send_mail)

        # ## Set staff user
        self.user.is_staff = True
        self.user.save()

        # Confirm menu item displayed
        view = IndexView.as_view()
        response = view(request_index)
        self.assertContains(response, 'href="/mail/send/"', status_code=200)

        # Confirm send email view access
        response = email_users(request_send_mail)
        self.assertContains(response, '<h1>Email users</h1>', status_code=200)
Exemplo n.º 3
0
    def test_index(self):
        """Test index view."""
        request = self.factory.get("/index")
        request.user = AnonymousUser()

        view = IndexView.as_view()
        response = view(request)
        self.assertContains(response, 'Log in', status_code=200)
        self.assertContains(response, '<h2>Welcome!</h2>', status_code=200)
Exemplo n.º 4
0
    def test_index(self):
        """Test index view."""
        request = self.factory.get("/index")
        request.user = AnonymousUser()

        view = IndexView.as_view()
        response = view(request)
        self.assertContains(response, 'Log in', status_code=200)
        self.assertContains(response, '<h2>Welcome!</h2>', status_code=200)
Exemplo n.º 5
0
    def confirm_email_users_unaccessible(self, request_index,
                                         request_send_mail):
        """Confirm AnonymousUsers and normal users cannot send email.

        Only staff and superusers have access to the email users view
        and can send emails to users.
        """
        # Confirm menu item not displayed
        view = IndexView.as_view()
        response = view(request_index)
        self.assertNotContains(response, 'href="/mail/send/"', status_code=200)

        # Confirm redirect
        response = email_users(request_send_mail)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, '/admin/login/?next=/mail/send')
Exemplo n.º 6
0
    def confirm_email_users_unaccessible(self,
                                         request_index,
                                         request_send_mail):
        """Confirm AnonymousUsers and normal users cannot send email.

        Only staff and superusers have access to the email users view
        and can send emails to users.
        """
        # Confirm menu item not displayed
        view = IndexView.as_view()
        response = view(request_index)
        self.assertNotContains(response, 'href="/mail/send/"', status_code=200)

        # Confirm redirect
        response = email_users(request_send_mail)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, '/admin/login/?next=/mail/send')
Exemplo n.º 7
0
from django.conf.urls import url
from library.views import IndexView, ItemsView, ItemView, ItemResourceView, ItemCommentView, ItemArchiveView

urlpatterns = [
    url(r'^$', IndexView.as_view(), name='index'),
    url(r'^library_archive/$',
        ItemArchiveView.as_view(),
        name="library-archive"),
    url(r'^(?P<slug>[\w-]+)/$', ItemsView.as_view(), name='library-items'),
    url(r'^(?P<stack>[\w-]+)/(?P<slug>[\w-]+)/$',
        ItemView.as_view(),
        name='library-item'),
    url(r'^item/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/(?P<filename>[\w_\.]+)$',
        ItemResourceView.as_view(),
        name='resource'),
    url(r'^(?P<stack>[\w-]+)/(?P<slug>[\w-]+)/comment/$',
        ItemCommentView.as_view(),
        name='comment'),
]
Exemplo n.º 8
0
 def _get_index(self):
     request = self.factory.get("/index")
     request.user = AnonymousUser()
     view = IndexView.as_view()
     return view(request)
Exemplo n.º 9
0
# Copyright © 2016 SUSE LLC, James Mason <*****@*****.**>.
#
# This file is part of openbare.
#
# openbare is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# openbare is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with openbare. If not, see <http://www.gnu.org/licenses/>.

from django.conf.urls import include, url
from django.contrib import admin
from library.views import IndexView

urlpatterns = [
    url('', include('django.contrib.auth.urls', namespace='auth')),
    url('', include('social.apps.django_app.urls', namespace='social')),
    url(r'^admin/', admin.site.urls),
    url(r'^library/', include('library.urls', namespace='library')),
    url(r'^mail/', include('mailer.urls', namespace='mailer')),
    url(r'^$', IndexView.as_view(), name='home'),
]
Exemplo n.º 10
0
from django.conf.urls import url
from library.views import IndexView, ItemsView, ItemView, ItemResourceView, ItemCommentView, ItemArchiveView

urlpatterns = [
	url(r'^$', IndexView.as_view(), name='index'),
    url(r'^library_archive/$', ItemArchiveView.as_view(), name="library-archive"),
	url(r'^(?P<slug>[\w-]+)/$', ItemsView.as_view(), name='library-items'),
	url(r'^(?P<stack>[\w-]+)/(?P<slug>[\w-]+)/$', ItemView.as_view(), 
    name='library-item'),
	url(r'^item/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/(?P<filename>[\w_\.]+)$', 
		ItemResourceView.as_view(), name='resource'),
	url(r'^(?P<stack>[\w-]+)/(?P<slug>[\w-]+)/comment/$', 
    ItemCommentView.as_view(), name='comment'),
]
Exemplo n.º 11
0
The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from library.views import IndexView, edit, save_edit, add, save_add, del_book, login, signin, logout

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', IndexView.as_view(), name='index'),
    path('edit/<edit_id>', edit, name='edit'),
    path('save_edit/<edit_id>', save_edit, name='save_edit'),
    path('add/', add, name='add'),
    path('save_add/', save_add, name='save_add'),
    path('del_book/<del_id>', del_book, name='del'),
    path('login/', login, name='login'),
    path('signin/', signin, name='signin'),
    path('logout/', logout)
]