Skip to content

Commit

Permalink
Cleanup code and refactor tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Jul 31, 2017
1 parent 29fdec8 commit 125b1b9
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 155 deletions.
12 changes: 6 additions & 6 deletions abilian/services/activity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class ActivityEntry(db.Model):
target = relationship(Entity, foreign_keys=_fk_target_id)

def __repr__(self):
return ('<{}.ActivityEntry id={} actor={} verb={} object={} '
'target={}>'.format(self.__class__.__module__, self.id,
repr(text_type(self.actor)),
repr(self.verb),
repr(text_type(self.object)),
repr(text_type(self.target))))
tpl = '<{}.ActivityEntry id={} actor={} verb={} object={} target={}>'
return tpl.format(self.__class__.__module__, self.id,
repr(text_type(self.actor)),
repr(self.verb),
repr(text_type(self.object)),
repr(text_type(self.target)))
2 changes: 1 addition & 1 deletion abilian/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _toggle_running(self, run_state, ignore_state=False):

@property
def app_state(self):
""" Current service state in current application.
"""Current service state in current application.
:raise:RuntimeError if working outside application context.
"""
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
97 changes: 97 additions & 0 deletions abilian/services/conversion/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# coding=utf-8
from __future__ import absolute_import, print_function, unicode_literals

import tempfile
from os.path import dirname, join
from warnings import warn

import pytest
from magic import Magic, os

BASEDIR = join(dirname(__file__), "dummy_files")
BASEDIR2 = join(dirname(__file__), "dummy_files2")

mime_sniffer = Magic(mime=True)
encoding_sniffer = Magic(mime_encoding=True)


# FIXME: tests that rely on OOo are disabled until we fix stability issues.


@pytest.yield_fixture
def converter():
from abilian.services.conversion import converter as c

cache_dir = tempfile.mkdtemp(suffix='unittest')
tmp_dir = tempfile.mkdtemp(suffix='unittest')
c.init_work_dirs(cache_dir, tmp_dir)
yield c

c.clear()


def read_file(fn, mode='rb'):
try:
return open(join(BASEDIR, fn), mode).read()
except IOError as e:
return open(join(BASEDIR2, fn), mode).read()


# To text
def test_pdf_to_text(converter):
if not os.popen("which pdftotex").read().strip():
warn("pdftotext not found, skipping test")
return
blob = read_file("onepage.pdf")
text = converter.to_text("", blob, "application/pdf")


def XXXtest_word_to_text(converter):
blob = read_file("test.doc")
text = converter.to_text("", blob, "application/msword")


def XXXtest_wordx_to_text(converter):
blob = read_file("test.docx")
text = converter.to_text("", blob, "application/msword")


def XXXtest_excel_to_text(converter):
blob = read_file("test.xls")
text = converter.to_text("", blob, "application/excel")


# To PDF
def XXXtest_odt_to_pdf(converter):
blob = read_file("test.odt")
pdf = converter.to_pdf("", blob,
"application/vnd.oasis.opendocument.text")
assert b"application/pdf" == mime_sniffer.from_buffer(pdf)


def XXXtest_word_to_pdf(converter):
blob = read_file("test.doc")
pdf = converter.to_pdf("", blob, "application/msword")
assert b"application/pdf" == mime_sniffer.from_buffer(pdf)


def test_image_to_pdf(converter):
blob = read_file("picture.jpg")
pdf = converter.to_pdf("", blob, "image/jpeg")
assert "application/pdf" == mime_sniffer.from_buffer(pdf)


# To images
def test_pdf_to_images(converter):
if not os.popen("which pdftoppm").read().strip():
warn("pdftoppm not found, skipping test")
return
blob = read_file("onepage.pdf")
image = converter.to_image("", blob, "application/pdf", 0)
assert "image/jpeg" == mime_sniffer.from_buffer(image)


def XXXtest_word_to_images(converter):
blob = read_file("test.doc")
image = converter.to_image("", blob, "application/msword", 0)
assert b"image/jpeg" == mime_sniffer.from_buffer(image)
File renamed without changes.
6 changes: 3 additions & 3 deletions abilian/services/sandbox/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

class Activity(object):
"""
Persistent object that represents an activity entry.
"""
Persistent object that represents an activity entry.
"""


class ActivityService(object):

def post(self, activity):
"""Post an activity to the service.
"""
"""

# Now we need some methods to query the stream
9 changes: 5 additions & 4 deletions abilian/services/sandbox/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ class PrivateMessage(object):
class PrivateMessageService(object):

def messages(self, user=None, page=0, per_page=50, filter=None):
"""Return the list of messages received by the given user (or current
user if user=None).
"""
"""
Return the list of messages received by the given user (or current
user if user=None).
"""

def send(self, dest_user, subject, body, url=None):
"""Send a message to the destination user.
"""
"""


class MessageService(object):
Expand Down
1 change: 0 additions & 1 deletion abilian/services/tests/__init__.py

This file was deleted.

Binary file removed abilian/services/tests/cat.jpg
Binary file not shown.
43 changes: 0 additions & 43 deletions abilian/services/tests/test_image.py

This file was deleted.

89 changes: 0 additions & 89 deletions tests/integration/test_conversion.py

This file was deleted.

10 changes: 5 additions & 5 deletions tests/integration/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ class Contact(Entity):


class ContactEditForm(Form):
_groups = [[u'Main', ['email', 'first_name', 'last_name']]]
_groups = [['Main', ['email', 'first_name', 'last_name']]]


class Contacts(Module):
managed_class = Contact

list_view_columns = [
dict(name='_name', width=35),
dict(name='first_name', width=25),
dict(name='last_name', width=14),
dict(name='email', width=20),
{'name': '_name', 'width': 35},
{'name': 'first_name', 'width': 25},
{'name': 'last_name', 'width': 14},
{'name': 'email', 'width': 20},
]

edit_form_class = ContactEditForm
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

def gen_name(ctx):
params = ctx.current_parameters
return u'{} {}'.format(
params.get('first_name') or u'', params.get('last_name') or u'').strip()
return '{} {}'.format(
params.get('first_name') or '', params.get('last_name') or '').strip()


class DummyContact1(Entity):
Expand Down Expand Up @@ -49,8 +49,9 @@ def test_contacts_are_indexed(self):
self.session.add(contact)
self.session.commit()

search_result = index_service.search(u'john')
search_result = index_service.search('john')
assert len(search_result) == 1

found = search_result[0]
assert contact.id == found['id']
assert contact.name == found['name']
Expand Down

0 comments on commit 125b1b9

Please sign in to comment.