4 changed files with 239 additions and 0 deletions
@ -0,0 +1,18 @@
|
||||
# coding=utf8 |
||||
# |
||||
# __init__.py: vowel unittest base modules |
||||
# Copyright (C) 2016 Sam Black <samwwwblack@lapwing.org> |
||||
# |
||||
# This program is free software: you can redistribute it and/or modify |
||||
# it under the terms of the GNU Affero General Public License as published by |
||||
# the Free Software Foundation, either version 3 of the License, or |
||||
# (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU Affero General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU Affero General Public License |
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
# |
@ -0,0 +1,18 @@
|
||||
# coding=utf8 |
||||
# |
||||
# __init__.py: vowel unittest base modules |
||||
# Copyright (C) 2016 Sam Black <samwwwblack@lapwing.org> |
||||
# |
||||
# This program is free software: you can redistribute it and/or modify |
||||
# it under the terms of the GNU Affero General Public License as published by |
||||
# the Free Software Foundation, either version 3 of the License, or |
||||
# (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU Affero General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU Affero General Public License |
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
# |
@ -0,0 +1,202 @@
|
||||
# coding=utf8 |
||||
# |
||||
# mock.py: Wrapped converter classes to test PPT/PDF->reveal.js converters. |
||||
# |
||||
# Copyright (C) 2016 Sam Black <samwwwblack@lapwing.org> |
||||
# |
||||
# This program is free software: you can redistribute it and/or modify |
||||
# it under the terms of the GNU Affero General Public License as published by |
||||
# the Free Software Foundation, either version 3 of the License, or |
||||
# (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU Affero General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU Affero General Public License |
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
# |
||||
import os.path |
||||
|
||||
from bs4 import BeautifulSoup |
||||
from unotools.unohelper import convert_path_to_url |
||||
|
||||
from vowel.utils.presentation import PDFConverter |
||||
from vowel.utils.presentation import PPTConverter |
||||
|
||||
|
||||
class MockPDFConverter(PDFConverter): |
||||
""" |
||||
Wrapped converter to remove DB and socketio connections. |
||||
|
||||
This overrides everything in the `ConverterBase` class. |
||||
""" |
||||
def __init__(self, document_path): |
||||
""" |
||||
Wrapped init to remove unneeded arguments. |
||||
|
||||
:param document_path: path to the test document. |
||||
:type document_path: str |
||||
""" |
||||
# None of these are important, just that they are set |
||||
self.document = None |
||||
self.organisation_id = 0 |
||||
self.lesson_id = 0 |
||||
self.document_name = None |
||||
self.presentation_path = convert_path_to_url( |
||||
os.path.abspath(document_path)) |
||||
|
||||
self.slide_content = None |
||||
|
||||
def sio_message(self, message): |
||||
""" |
||||
Send a message via socketio. |
||||
|
||||
:param message: message to send |
||||
:type message: str |
||||
""" |
||||
print(message) |
||||
|
||||
def sio_percentage(self, percentage): |
||||
""" |
||||
Send a percentage value via socketio. |
||||
|
||||
:param percentage: percentage value |
||||
:type percentage: int |
||||
""" |
||||
print(percentage) |
||||
|
||||
def redirect(self, presentation_id): |
||||
""" |
||||
Send a redirect message via socketio. |
||||
|
||||
:param presentation_id: URL to redirect to |
||||
:type presentation_id: int |
||||
""" |
||||
print(presentation_id) |
||||
|
||||
def presentation_create(self, filename, slide_content, linked_resources): |
||||
""" |
||||
Create new presentation resource database entries. |
||||
|
||||
:param filename: presentation name |
||||
:type filename: str |
||||
:param slide_content: presentation HTML |
||||
:type slide_content: str |
||||
:param linked_resources: list of associated resources, eg images |
||||
:type linked_resources: list |
||||
:return: presentation ID |
||||
:rtype: int |
||||
""" |
||||
print("-" * 80) |
||||
print("Create presentation") |
||||
self.slide_content = slide_content |
||||
html = BeautifulSoup(slide_content, "html.parser") |
||||
print(html.prettify()) |
||||
print(linked_resources) |
||||
print("-" * 80) |
||||
|
||||
def document_create(self, filename, filepath, purpose): |
||||
""" |
||||
Create new resource and document entries. |
||||
|
||||
:param filename: filename |
||||
:type filename: str |
||||
:param filepath: absolute path to stored file |
||||
:type filepath: str |
||||
:param purpose: purpose of the file |
||||
:type purpose: str |
||||
:return: new Resource model ID |
||||
:rtype: int |
||||
""" |
||||
print("Create document") |
||||
print(filename) |
||||
|
||||
|
||||
class MockPPTConverter(PPTConverter): |
||||
""" |
||||
Wrapped converter to remove DB and socketio connections. |
||||
|
||||
This overrides everything in the `ConverterBase` class. |
||||
""" |
||||
def __init__(self, document_path): |
||||
""" |
||||
Wrapped init to remove unneeded arguments. |
||||
|
||||
:param document_path: path to the test document. |
||||
:type document_path: str |
||||
""" |
||||
# None of these are important, just that they are set |
||||
self.document = None |
||||
self.organisation_id = 0 |
||||
self.lesson_id = 0 |
||||
self.document_name = None |
||||
self.presentation_path = convert_path_to_url( |
||||
os.path.abspath(document_path)) |
||||
|
||||
self.slide_content = None |
||||
|
||||
def sio_message(self, message): |
||||
""" |
||||
Send a message via socketio. |
||||
|
||||
:param message: message to send |
||||
:type message: str |
||||
""" |
||||
print(message) |
||||
|
||||
def sio_percentage(self, percentage): |
||||
""" |
||||
Send a percentage value via socketio. |
||||
|
||||
:param percentage: percentage value |
||||
:type percentage: int |
||||
""" |
||||
print(percentage) |
||||
|
||||
def redirect(self, presentation_id): |
||||
""" |
||||
Send a redirect message via socketio. |
||||
|
||||
:param presentation_id: URL to redirect to |
||||
:type presentation_id: int |
||||
""" |
||||
print(presentation_id) |
||||
|
||||
def presentation_create(self, filename, slide_content, linked_resources): |
||||
""" |
||||
Create new presentation resource database entries. |
||||
|
||||
:param filename: presentation name |
||||
:type filename: str |
||||
:param slide_content: presentation HTML |
||||
:type slide_content: str |
||||
:param linked_resources: list of associated resources, eg images |
||||
:type linked_resources: list |
||||
:return: presentation ID |
||||
:rtype: int |
||||
""" |
||||
print("-" * 80) |
||||
print("Create presentation") |
||||
self.slide_content = slide_content |
||||
html = BeautifulSoup(slide_content, "html.parser") |
||||
print(html.prettify()) |
||||
print(linked_resources) |
||||
print("-" * 80) |
||||
|
||||
def document_create(self, filename, filepath, purpose): |
||||
""" |
||||
Create new resource and document entries. |
||||
|
||||
:param filename: filename |
||||
:type filename: str |
||||
:param filepath: absolute path to stored file |
||||
:type filepath: str |
||||
:param purpose: purpose of the file |
||||
:type purpose: str |
||||
:return: new Resource model ID |
||||
:rtype: int |
||||
""" |
||||
print("Create document") |
||||
print(filename) |
Loading…
Reference in new issue