Skip to content

Commit

Permalink
Move tests around.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Jun 8, 2013
1 parent f53e91e commit ecc5ec9
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 29 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from unittest import TestCase
from tests.unit.dummy import DummyContact

from abilian.core.entities import SEARCHABLE, NOT_SEARCHABLE, AUDITABLE
from abilian.core.subjects import User

from .dummy import DummyContact


class EntityTestCase(TestCase):
def test(self):
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions abilian/services/security/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ def __init__(self, app=None):

def init_app(self, app):
self.app = app

if not hasattr(app, 'extensions'):
app.extensions = {}

app.extensions['security'] = self

def start(self):
Expand Down
Empty file added abilian/web/tests/__init__.py
Empty file.
22 changes: 8 additions & 14 deletions tests/unit/test_actions.py → abilian/web/tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# coding=utf-8
from unittest import TestCase

from flask import Flask

from abilian.web.action import actions, Action
from abilian.testing import BaseTestCase


BASIC = Action('cat_1', 'basic', 'Basic Action', url='http://some.where')
CONDITIONAL = Action('cat_1', 'conditional', 'Conditional Action',
Expand All @@ -10,25 +13,16 @@
OTHER_CAT = Action('cat_2', 'other', 'Other Action',
url=lambda ctx: 'http://count?%d' % len(ctx))

class TestActions(TestCase):
""" Test Action and ActionRegistry

class TestActions(BaseTestCase):
""" Test Action and ActionRegistry.
"""
def setUp(self):
self.app = Flask('test_actions')
self.app.testing = True
actions.init_app(self.app)

with self.app.app_context():
actions.register(BASIC, CONDITIONAL, OTHER_CAT)

self.ctx = self.app.test_request_context('/')
self.ctx.push()
actions.register(BASIC, CONDITIONAL, OTHER_CAT)
actions._before_request()
actions.context['show_all'] = True

def tearDown(self):
self.ctx.pop()

def test_installed(self):
assert actions.installed() # test current_app (==self.app)
assert actions.installed(self.app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from jinja2 import Environment

from abilian.core.util import system_tz
from abilian.web.filters import init_filters, filesize, date_age, paragraphs

from ..filters import init_filters, filesize, date_age, paragraphs


class FakeApp(object):
def __init__(self, env):
Expand All @@ -13,6 +15,7 @@ def __init__(self, env):
env = Environment()
init_filters(FakeApp(env))


class TestFilters(unittest.TestCase):

def test_filesize(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import abilian.web.forms

from abilian.core.extensions import babel
from abilian.web.widgets import MainTableView, SingleView, Panel, Row, \

from ..widgets import MainTableView, SingleView, Panel, Row, \
linkify_url, text2html, EmailWidget


Expand Down Expand Up @@ -51,10 +52,11 @@ class DummyForm(Form):


class BaseTestCase(TestCase):
# TODO: use abilian.testing.BaseTestCase instead

def setUp(self):
# Hack to set up the template folder properly.
template_dir = os.path.dirname(__file__) + "/../../abilian/templates"
template_dir = os.path.dirname(__file__) + "/../../templates"
template_dir = os.path.normpath(template_dir)
self.app = Flask(__name__, template_folder=template_dir)
self.app.config.update({
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
requirements = parse_requirements([u'etc/deps.txt'])
dependency_links = parse_dependency_links([u'etc/deps.txt'])

print requirements
print dependency_links

def get_long_description():
import os
Expand Down
17 changes: 12 additions & 5 deletions tests/integration/test_search.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
"""
Test the index service.
"""
from sqlalchemy import UnicodeText, Text, Column
from abilian.core.entities import Entity, SEARCHABLE
from abilian.services import index_service

from .base import IntegrationTestCase
from ..unit.dummy import DummyContact

from abilian.services import index_service

class DummyContact1(Entity):
salutation = Column(UnicodeText, default=u"")
first_name = Column(UnicodeText, default=u"", info=SEARCHABLE)
last_name = Column(UnicodeText, default=u"", info=SEARCHABLE)
email = Column(Text, default=u"")


class IndexingTestCase(IntegrationTestCase):
Expand All @@ -20,16 +27,16 @@ def tearDown(self):
index_service.stop()

def test_contacts_are_indexed(self):
contact = DummyContact(first_name=u"John", last_name=u"Test User", email=u"test@example.com")
contact = DummyContact1(first_name=u"John", last_name=u"Test User", email=u"test@example.com")
self.session.add(contact)
self.session.commit()

# Check 3 different APIs
search_result = list(DummyContact.search_query(u"john").all())
search_result = list(DummyContact1.search_query(u"john").all())
assert len(search_result) == 1
assert contact == search_result[0]

search_result = list(DummyContact.search_query.search(u"john", get_models=True))
search_result = list(DummyContact1.search_query.search(u"john", get_models=True))
assert len(search_result) == 1
assert contact.id == int(search_result[0]['id'])
assert contact == search_result[0].model
Expand Down

0 comments on commit ecc5ec9

Please sign in to comment.