OpenSlides/tests/core/test_views.py

47 lines
1.8 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from django.test.client import Client
from mock import patch
from openslides import get_version
2013-10-30 17:48:09 +01:00
from openslides.agenda.models import Item
2013-11-14 19:29:08 +01:00
from openslides.config.api import config
from openslides.participant.models import User
from openslides.utils.test import TestCase
class VersionViewTest(TestCase):
2013-10-30 17:48:09 +01:00
def setUp(self):
User.objects.create_user('CoreMaximilian', 'xxx@xx.xx', 'default')
2013-10-30 17:48:09 +01:00
self.client = Client()
self.client.login(username='CoreMaximilian', password='default')
def test_get(self):
response = self.client.get('/version/')
self.assertContains(response, get_version(), status_code=200)
2013-10-30 17:48:09 +01:00
@patch('openslides.core.views.settings')
def test_with_missing_plugin(self, mock_settings):
"""
Tests that a not existing app does not appear on the version view.
2013-10-30 17:48:09 +01:00
"""
mock_settings.INSTALLED_PLUGINS = ('unexisting_app_nvhbkdfgmnsd',)
self.assertRaises(ImportError, self.client.get, '/version/')
2013-10-30 17:48:09 +01:00
class SearchViewTest(TestCase):
def test_simple_search(self):
Item.objects.create(title='agenda_item_bnghfdjkgndkjdfg')
User.objects.create_user('CoreMaximilian', 'xxx@xx.xx', 'default')
self.client = Client()
self.client.login(username='CoreMaximilian', password='default')
response = self.client.get('/search/?q=agenda_item_bnghfd')
text = '<span class="highlighted">agenda_item_bnghfd</span>jkgndkjdfg'
self.assertContains(response, text)
2013-11-14 19:29:08 +01:00
def test_anonymous(self):
self.assertFalse(config['system_enable_anonymous'])
self.assertEqual(Client().get('/search/').status_code, 403)
config['system_enable_anonymous'] = True
self.assertEqual(Client().get('/search/').status_code, 200)