fixes in tests

This commit is contained in:
Artur Barseghyan 2016-09-22 00:58:32 +02:00
parent aaa06c36ae
commit 82ffcde86a
8 changed files with 139 additions and 68 deletions

View file

@ -5,6 +5,10 @@ DEBUG = True
DEBUG_TOOLBAR = not True
TEMPLATE_DEBUG = not True
DEV = True
os.environ.setdefault(
'FOBI_SOURCE_PATH',
'/home/foreverchild/bbrepos/django-fobi/release/django-fobi/src'
)
DATABASES = {
'default': {

View file

@ -663,4 +663,6 @@ if DEBUG:
# Make the `django-fobi` package available without installation.
if DEV:
import sys
sys.path.insert(0, os.path.abspath('../../src'))
fobi_source_path = os.environ.get('FOBI_SOURCE_PATH', '../../src')
# sys.path.insert(0, os.path.abspath('../../src'))
sys.path.insert(0, os.path.abspath(fobi_source_path))

8
scripts/configure.sh Executable file
View file

@ -0,0 +1,8 @@
#pip install -r examples/requirements.txt
#python setup.py install
mkdir -p examples/logs examples/db examples/media examples/media/static examples/media/fobi_plugins/content_image
mkdir -p examples/media/fobi_plugins/file
python examples/simple/manage.py collectstatic --noinput
python examples/simple/manage.py syncdb --noinput
python examples/simple/manage.py migrate --noinput
python examples/simple/manage.py fobi_create_test_data

4
scripts/test_dev.sh Executable file
View file

@ -0,0 +1,4 @@
reset
#./scripts/uninstall.sh
./scripts/configure.sh
python examples/simple/manage.py test fobi --settings=settings_test

View file

@ -1,12 +1,15 @@
import unittest
import gc
import logging
import unittest
from time import sleep
# from selenium.webdriver.firefox.webdriver import WebDriver
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import WebDriverException
from django.core.management import call_command
from django.core.urlresolvers import reverse
from django.test import LiveServerTestCase
from django.conf import settings
@ -41,14 +44,25 @@ class FobiBrowserBuldDynamicFormsTest(LiveServerTestCase):
Backed up by selenium. This test is based on the bootstrap3 theme.
"""
cleans_up_after_itself = True
try:
LIVE_SERVER_URL = settings.LIVE_SERVER_URL
except Exception as e:
LIVE_SERVER_URL = None
def tearDown(self):
"""Tear down."""
super(FobiBrowserBuldDynamicFormsTest, self).tearDown()
call_command('flush', verbosity=0, interactive=False,
reset_sequences=False,
allow_cascade=False,
inhibit_post_migrate=False)
gc.collect()
@classmethod
def setUpClass(cls):
"""Set up."""
"""Set up class."""
# cls.selenium = WebDriver()
cls.selenium = webdriver.Firefox()
@ -60,13 +74,18 @@ class FobiBrowserBuldDynamicFormsTest(LiveServerTestCase):
@classmethod
def tearDownClass(cls):
"""Tear down."""
"""Tear down class."""
try:
cls.selenium.quit()
except Exception as e:
print(e)
except Exception as err:
print(err)
super(FobiBrowserBuldDynamicFormsTest, cls).tearDownClass()
call_command('flush', verbosity=0, interactive=False,
reset_sequences=False,
allow_cascade=False,
inhibit_post_migrate=False)
gc.collect()
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ -134,6 +153,33 @@ class FobiBrowserBuldDynamicFormsTest(LiveServerTestCase):
self.__sleep(wait)
def _scroll_to_element(self, form_element, simple=False):
"""Scroll to element."""
coordinates = form_element.location_once_scrolled_into_view
if simple:
return
x = coordinates.get('x', 0)
y = coordinates.get('y', 0)
self.selenium.execute_script(
"window.scrollTo({0}, {1});".format(x, y)
)
self.selenium.execute_script(
"window.scrollBy({0}, {1});".format(0, -100)
)
def _scroll_to(self, x, y):
"""Scroll to."""
self.selenium.execute_script(
"window.scrollTo({0}, {1});".format(x, y)
)
def _scroll_by(self, x, y):
"""Scroll by."""
self.selenium.execute_script(
"window.scrollBy({0}, {1});".format(x, y)
)
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ++++++++++++++++++++++ Form related +++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ -210,6 +256,8 @@ class FobiBrowserBuldDynamicFormsTest(LiveServerTestCase):
add_form_element_link = self.selenium.find_element_by_xpath(
"""//a[contains(text(), 'Choose form element to add') and contains(@class, "dropdown-toggle")]"""
)
self._scroll_to(0, 0)
add_form_element_link.click()
# Find the parent element
@ -227,6 +275,9 @@ class FobiBrowserBuldDynamicFormsTest(LiveServerTestCase):
add_form_element_available_elements_container.find_element_by_xpath(
'//a[text()="{0}"]'.format(form_element_name)
)
self._scroll_to_element(form_element_to_add, simple=True)
self._scroll_by(0, -150)
form_element_to_add.click()
# Adding form data

View file

@ -1,9 +1,3 @@
__title__ = 'fobi.tests.test_core'
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2016 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
__all__ = ('FobiCoreTest',)
import unittest
from django.test import TestCase, RequestFactory
@ -18,18 +12,25 @@ from fobi.tests.constants import TEST_FORM_NAME, TEST_FORM_SLUG
from fobi.tests.base import print_info
from fobi.tests.helpers import setup_fobi, get_or_create_admin_user
__title__ = 'fobi.tests.test_core'
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2016 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
__all__ = ('FobiCoreTest',)
class FobiCoreTest(TestCase):
"""
Tests of django-fobi core functionality.
"""
"""Tests of django-fobi core functionality."""
def setUp(self):
"""Set up."""
setup_fobi(fobi_sync_plugins=True)
@print_info
def test_01_get_registered_form_element_plugins(self):
"""
Test registered form element plugins
(`get_registered_form_element_plugins`).
"""Test registered form element plugins.
Calling the `get_registered_form_element_plugins`.
"""
res = get_registered_form_element_plugins()
self.assertTrue(len(res) > 0)
@ -37,8 +38,9 @@ class FobiCoreTest(TestCase):
@print_info
def test_02_get_registered_form_handler_plugins(self):
"""
Test registered form handlers (`get_registered_form_handler_plugins`).
"""Test registered form handlers.
Calling `get_registered_form_handler_plugins`.
"""
res = get_registered_form_handler_plugins()
self.assertTrue(len(res) > 0)
@ -46,8 +48,9 @@ class FobiCoreTest(TestCase):
@print_info
def test_03_get_registered_form_callbacks(self):
"""
Test registered form callbacks (`get_registered_form_callbacks`).
"""Test registered form callbacks.
Calling `get_registered_form_callbacks`.
"""
res = get_registered_form_callbacks()
self.assertTrue(len(res) > 0)
@ -55,14 +58,16 @@ class FobiCoreTest(TestCase):
@print_info
def test_04_get_registered_themes(self):
"""
Test registered themes (`get_registered_themes`).
"""Test registered themes.
Calling `get_registered_themes`.
"""
res = get_registered_themes()
self.assertTrue(len(res) > 0)
return res
def _test_form_action_url(self, form_entry, action_url):
"""Test form action URL."""
request_factory = RequestFactory()
request = request_factory.post(
'/en/fobi/forms/edit/27/',
@ -73,9 +78,10 @@ class FobiCoreTest(TestCase):
'success_page_message': '',
'action': action_url,
}
)
)
request.META['SERVER_NAME'] = 'localhost'
form = FormEntryForm(request.POST, request=request, instance=form_entry)
form = FormEntryForm(request.POST, request=request,
instance=form_entry)
saved = False
try:
@ -89,52 +95,51 @@ class FobiCoreTest(TestCase):
return saved
def _create_form_entry(self):
"""Create form entry."""
user = get_or_create_admin_user()
self.assertTrue(user is not None)
form_entry = FormEntry(
name = TEST_FORM_NAME,
slug = TEST_FORM_SLUG,
user = user
)
name=TEST_FORM_NAME,
slug=TEST_FORM_SLUG,
user=user
)
form_entry.save()
return form_entry
@print_info
def test_05_action_url(self):
"""
Test `action` field of the URL.
"""
"""Test `action` field of the URL."""
form_entry = self._create_form_entry()
# Local URL, OK test
saved = self._test_form_action_url(
form_entry, '/en/fobi/forms/edit/27/'
)
)
self.assertTrue(saved)
# Local URL, fail test
saved = self._test_form_action_url(
form_entry, '/en/idontexist/'
)
)
self.assertTrue(not saved)
# External URL, OK test
saved = self._test_form_action_url(
form_entry, 'http://delusionalinsanity.com/portfolio/'
)
)
self.assertTrue(saved)
# External URL, fail test
saved = self._test_form_action_url(
form_entry, 'http://delusionalinsanity.com2/portfolio/'
)
)
self.assertTrue(not saved)
# External URL, fail test
saved = self._test_form_action_url(
form_entry, 'http://delusionalinsanity2.com/portfolio/'
)
)
self.assertTrue(not saved)

View file

@ -1,9 +1,3 @@
__title__ = 'fobi.tests.test_dynamic_forms'
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2016 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
__al__ = ('FobiDynamicFormsTest',)
import unittest
from django.test import TestCase
@ -14,20 +8,25 @@ from fobi.tests.helpers import (
setup_fobi, get_or_create_admin_user, create_form_with_entries
)
__title__ = 'fobi.tests.test_dynamic_forms'
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2016 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
__all__ = ('FobiDynamicFormsTest',)
class FobiDynamicFormsTest(TestCase):
"""
Tests of django-fob dynamic forms functionality.
"""
"""Tests of django-fob dynamic forms functionality."""
def setUp(self):
"""Set up."""
setup_fobi(fobi_sync_plugins=True)
user = get_or_create_admin_user()
create_form_with_entries(user)
@print_info
def test_01_assemble_form_class_and_render_form(self):
"""
Test form class assembling and rendering.
"""
"""Test form class assembling and rendering."""
flow = []
# Getting entry with created plugins

View file

@ -1,9 +1,3 @@
__title__ = 'fobi.tests.test_dynamic_forms'
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2016 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
__all__ = ('FobiDataStructuresTest',)
import unittest
from copy import copy
@ -14,31 +8,36 @@ from fobi.data_structures import SortableDict
from fobi.tests.base import print_info
__title__ = 'fobi.tests.test_dynamic_forms'
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2016 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
__all__ = ('FobiDataStructuresTest',)
class FobiDataStructuresTest(TestCase):
"""
Tests of django-fobi ``data_structures`` module functionality.
"""
"""Tests of django-fobi ``data_structures`` module functionality."""
def setUp(self):
"""Set up."""
self.initial = SortableDict(
[
('b', 1),
('a', 2),
('c', 3),
]
)
)
self.expected = SortableDict(
[
('a', 2),
('b', 1),
('c', 3),
]
)
)
@print_info
def test_01_sortable_dict_move_before_key(self):
"""
Test the ``fobi.data_structures.SortableDict.move_before_key`` method.
"""
"""Test the `fobi.data_structures.SortableDict.move_before_key`."""
flow = []
flow.append(copy(self.initial))
@ -54,14 +53,13 @@ class FobiDataStructuresTest(TestCase):
@print_info
def test_02_sortable_dict_move_after_key(self):
"""
Test the ``fobi.data_structures.SortableDict.move_after_key`` method.
"""
"""Test the `fobi.data_structures.SortableDict.move_after_key`."""
flow = []
flow.append(copy(self.initial))
res = self.initial.move_after_key(source_key='b', target_key='a') # Expected: a, b, c
# Expected: a, b, c
res = self.initial.move_after_key(source_key='b', target_key='a')
self.assertTrue(res)
flow.append(copy(self.initial))