예제 #1
0
    def test_matching_current_session_should_responde_with_success(self):
        user = User(username='******', is_staff=True)
        user.set_password('password')
        user.save()

        backend = Backend()
        request = self.get_view_handler_request(backend, user, 'hearbeat',
                                                'post', '/admin/hearbeat/')

        # log user in
        user.backend = 'django.contrib.auth.backends.ModelBackend'
        auth_login(request, user)
        self.assertTrue(user.is_authenticated())

        # create session object and patch request
        session_key = '123456789123456789123456789123456789'
        session = Session.objects.create(
            session_key=session_key,
            session_data=Session.objects.encode({'_auth_user_id': user.id}),
            expire_date=datetime.datetime.now() + datetime.timedelta(days=1))
        request.session._session_key = session_key

        # run request and verify that we get successful responde
        response = backend.run_handler(request, 'heartbeat')
        json = decode_json(response.content)
        self.assertEqual({'result': 'Success', 'taskInfo': None}, json)
예제 #2
0
 def test_not_matching_session_should_responde_with_error(self):
     backend = Backend()
     request = self.get_view_handler_request(backend, None, 'hearbeat',
                                             'post', '/admin/hearbeat/')
     response = backend.run_handler(request, 'heartbeat')
     json = decode_json(response.content)
     self.assertEqual(
         {
             'message': 'Reload. no session available.',
             'result': 'error',
             'taskInfo': None
         }, json)
예제 #3
0
    def _assert_dispatchable_url(self, name, user):
        backend = Backend()
        section = backend.get_section_by_class(MediaBackendSection)
        subsection = section.get_section_by_class(ImageBackendSection)

        def callback(self):
            return HttpResponse('Foo')

        regexUrl = RegexURLPattern(r'/', callback, name=name)
        backend.dispatchable_url(regexUrl, section, subsection)

        factory = RequestFactory()
        request = factory.get('/')
        request.user = user
        return regexUrl.callback(request)
예제 #4
0
파일: base.py 프로젝트: stephcyrille/cubane
    def get_view_handler_request(self,
                                 view,
                                 user,
                                 handler_name,
                                 method,
                                 url,
                                 data={},
                                 ajax=False):
        factory = RequestFactory()
        f = getattr(factory, method)

        # create request with session store
        request = f(url, data)
        request.session = SessionStore()
        request.META['HTTP_HOST'] = '127.0.0.1'
        request._messages = FallbackStorage(request)

        # user
        if user and user.id:
            self.login(request, user)

        # ajax
        if ajax:
            request.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'

        # user, profile and backend
        request.user = user
        request.user_profile = self.get_user_profile(request.user)
        request.backend = Backend()

        # changelog
        request.changelog = ChangeLogManager(request)

        return request
예제 #5
0
 def test_has_sub_sections_should_return_false_if_backend_has_no_sections(
         self):
     backend = Backend()
     for s in backend.sections:
         s.sections = []
     backend_view = BackendView(backend, backend.sections, None, None)
     self.assertFalse(backend_view.has_sub_sections)
예제 #6
0
 def _run_view_handler(self, data={}):
     backend = Backend()
     return self.run_view_handler(backend,
                                  self.user,
                                  'password_reset',
                                  'post',
                                  '/admin/password-reset/',
                                  data=data)
예제 #7
0
    def test_logout_with_session_should_terminate_session_and_redirect_to_login_page(
            self):
        backend = Backend()

        user = User(username='******', is_staff=True)
        user.set_password('password')
        user.save()

        request, response = self.run_view_handler_request(
            backend, user, 'logout', 'get', '/admin/logout')
        self.assertTrue(user.is_authenticated())
        self.assertIsRedirect(response, reverse('cubane.backend.login'))

        self.logout(request)
        user.delete()
예제 #8
0
    def _assert_login(self,
                      handler_name,
                      url,
                      username,
                      password,
                      is_staff,
                      delete_user=True):
        backend = Backend()
        user = User(username='******', is_staff=is_staff)
        user.set_password('password')
        user.save()

        response = self.run_view_handler(backend, None, handler_name, 'post',
                                         url, {
                                             'username': username,
                                             'password': password
                                         })

        if delete_user:
            user.delete()

        return response
예제 #9
0
 def test_heartbeat_should_deny_GET(self):
     backend = Backend()
     request = self.get_view_handler_request(backend, None, 'hearbeat',
                                             'get', '/admin/hearbeat/')
     response = backend.run_handler(request, 'heartbeat')
     self.assertEqual(405, response.status_code)
예제 #10
0
 def test_index_should_redirect_to_first_visible_section(self):
     backend = Backend()
     admin = User(username='******', is_staff=True, is_superuser=True)
     response = self.run_view_handler(backend, admin, 'index', 'get',
                                      '/admin/')
     self.assertIsRedirect(response, '/admin/images/')
예제 #11
0
 def test_password_forgotten_should_present_page(self):
     backend = Backend()
     self.assertRaises(Http404, self.run_view_handler, backend, None,
                       'password_forgotten', 'get',
                       '/admin/password-forgotten/')
예제 #12
0
 def test_collect_should_install_apis(self):
     backend = Backend()
     self.assertEqual(1, len(backend.apis))
     self.assertIsInstance(backend.apis[0], TestApiView)
예제 #13
0
 def test_logout_without_session_should_redirect_to_login_page(self):
     backend = Backend()
     response = self.run_view_handler(backend, AnonymousUser(), 'logout',
                                      'get', '/admin/logout')
     self.assertIsRedirect(response, reverse('cubane.backend.login'))
예제 #14
0
 def test_get_section_by_class_should_return_section_by_given_class(self):
     backend = Backend()
     section = backend.get_section_by_class(MediaBackendSection)
     self.assertIsInstance(section, MediaBackendSection)
예제 #15
0
 def test_login_page_should_present_login_form(self):
     backend = Backend()
     response = self.run_view_handler(backend, None, 'login', 'get',
                                      '/admin/login/')
     self.assertIsInstance(response.get('form'), BackendLoginForm)
예제 #16
0
 def test_get_section_by_class_should_return_none_if_not_found(self):
     backend = Backend()
     section = backend.get_section_by_class(AccountBackendSection)
     self.assertIsNone(section)
예제 #17
0
 def test_has_sub_sections_should_return_false_if_there_is_no_section_to_begin_with(
         self):
     backend = Backend()
     self.assertFalse(backend.has_sub_sections)
예제 #18
0
 def test_has_sub_sections_should_return_false_if_there_is_no_subsection(
         self):
     backend = Backend()
     for s in backend.sections:
         s.sections = []
     self.assertFalse(backend.has_sub_sections)
예제 #19
0
 def test_has_sub_sections_should_return_true_if_there_is_at_least_one_subsection(
         self):
     backend = Backend()
     self.assertTrue(backend.has_sub_sections)
예제 #20
0
 def setUpClass(cls):
     super(BackendViewsBackendSectionTestCase, cls).setUpClass()
     cls.backend = Backend()
예제 #21
0
 def test_index_should_render_dashboard_if_no_section_is_available(self):
     backend = Backend()
     admin = User(username='******', is_staff=True)
     response = self.run_view_handler(backend, admin, 'index', 'get',
                                      '/admin/')
     self.assertEqual({}, response)
예제 #22
0
파일: urls.py 프로젝트: stephcyrille/cubane
# coding=UTF-8
from __future__ import unicode_literals
from django.conf import settings
from django.conf.urls import url, include
from django.contrib.sitemaps import views as sitemaps_views
from cubane.backend.views import Backend
from cubane.cms.views import get_cms
from cubane.urls import *
from cubane import views as cubane_views

backend = Backend()
cms = get_cms()

setup_default_urls(__name__)

urlpatterns += [
    url(r'^admin/', include(backend.urls)),
    url(r'^sitemap\.xml$', sitemaps_views.sitemap, {'sitemaps': cms.sitemaps}),
    url(r'^robots\.txt$', cubane_views.robots_txt),
    url(r'^', include(cms.urls)),
]
예제 #23
0
 def test_sections_property_should_return_backend_sections(self):
     backend = Backend()
     backend_view = BackendView(backend, backend.sections, None, None)
     self.assertEqual(backend._sections, backend_view.sections)
     backend._sections = []
     self.assertEqual([], backend_view.sections)