diff options
author | Tiago Ferraz <tiago.ferraz@gmail.com> | 2015-02-11 12:37:58 -0200 |
---|---|---|
committer | Tiago Ferraz <tiago.ferraz@gmail.com> | 2015-02-11 12:37:58 -0200 |
commit | b73449aa87b1328c466a8c38894ed25b3298b724 (patch) | |
tree | 425e50804951ee518b0bc4406f4360390f70b7a1 /service | |
parent | a1d0142ef3cd0ad71f72a12572057f7d27974c0b (diff) |
General Refactoring
Refactored __init__ method on app_test_client to be succint, go to say what is doing and package.json to execute handlebars from the whole path.
Diffstat (limited to 'service')
-rwxr-xr-x | service/go | 13 | ||||
-rw-r--r-- | service/test/support/integration/app_test_client.py | 77 |
2 files changed, 59 insertions, 31 deletions
@@ -11,38 +11,49 @@ function resolveNumOfCores { } function setuppy { + echo "Installing Pixelated User Agent." pip install -r test_requirements.txt python setup.py develop $* pip uninstall -y scrypt; pip install scrypt pip uninstall -y gnupg; pip install gnupg==1.2.5 + echo "Done." } function setupjs { + echo "Installing node and bower libraries." cd ../web-ui npm install node_modules/bower/bin/bower install --config.interactive=false --allow-root LC_ALL=en_US.UTF-8 ./go build cd - + echo "Done." } function runIntegrationTests { + echo "Executing Integration Tests." resolveNumOfCores - echo $NUM_OF_CORES trial -j $NUM_OF_CORES --reporter=text $* test.integration + echo "Done." } function runUnitTests { + echo "Executing Unit Tests." trial --reporter=text $* test.unit + echo "Done." } function runPep8 { + echo "Verifying conformation to pep8." pep8 pixelated test --ignore=E501 + echo "Done." } function runJSHint { + echo "Executing JSHint." cd ../web-ui LC_ALL=en_US.UTF-8 ./go jshint cd - + echo "Done." } if [ "$1" == 'test' ]; then diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py index e275a286..0f6c5813 100644 --- a/service/test/support/integration/app_test_client.py +++ b/service/test/support/integration/app_test_client.py @@ -15,13 +15,21 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import json import multiprocessing +import os import shutil import time +import uuid from leap.mail.imap.account import SoledadBackedAccount from leap.soledad.client import Soledad from mock import MagicMock, Mock -import os +from twisted.internet import reactor +from twisted.internet.defer import succeed +from twisted.web.resource import getChildForRequest +from twisted.web.server import Site + +from pixelated.adapter.model.mail import PixelatedMail +from pixelated.adapter.search import SearchEngine from pixelated.adapter.services.draft_service import DraftService from pixelated.adapter.services.mail_service import MailService from pixelated.adapter.services.mailboxes import Mailboxes @@ -29,54 +37,39 @@ from pixelated.adapter.soledad.soledad_querier import SoledadQuerier from pixelated.adapter.services.tag_service import TagService from pixelated.config import App from pixelated.resources.root_resource import RootResource -from pixelated.adapter.model.mail import PixelatedMail -from pixelated.adapter.search import SearchEngine from test.support.integration.model import MailBuilder from test.support.test_helper import request_mock -from twisted.internet import reactor -from twisted.internet.defer import succeed -from twisted.web.resource import getChildForRequest -from twisted.web.server import Site -import uuid class AppTestClient: INDEX_KEY = '\xde3?\x87\xff\xd9\xd3\x14\xf0\xa7>\x1f%C{\x16.\\\xae\x8c\x13\xa7\xfb\x04\xd4]+\x8d_\xed\xd1\x8d\x0bI' \ '\x8a\x0e\xa4tm\xab\xbf\xb4\xa5\x99\x00d\xd5w\x9f\x18\xbc\x1d\xd4_W\xd2\xb6\xe8H\x83\x1b\xd8\x9d\xad' + ACCOUNT = 'test' + MAIL_ADDRESS = 'test@pixelated.org' - def __init__(self, soledad_test_folder='/tmp/soledad-test/test'): + def __init__(self): + soledad_test_folder = self._generate_soledad_test_folder_name() + SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder - soledad_test_folder = os.path.join(soledad_test_folder, str(uuid.uuid4())) - self.soledad = initialize_soledad(tempdir=soledad_test_folder) self.cleanup = lambda: shutil.rmtree(soledad_test_folder) - self.mail_address = "test@pixelated.org" - - # setup app - PixelatedMail.from_email_address = self.mail_address + PixelatedMail.from_email_address = self.MAIL_ADDRESS - SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder - - self.app = App() - - self.soledad_querier = SoledadQuerier(self.soledad) - self.soledad_querier.get_index_masterkey = lambda: self.INDEX_KEY + self.soledad = initialize_soledad(tempdir=soledad_test_folder) + self.soledad_querier = self._create_soledad_querier(self.soledad, self.INDEX_KEY) - self.account = SoledadBackedAccount('test', self.soledad, MagicMock()) self.search_engine = SearchEngine(self.soledad_querier, agent_home=soledad_test_folder) + self.mail_sender = self._create_mail_sender() + + self.account = SoledadBackedAccount(self.ACCOUNT, self.soledad, MagicMock()) self.mailboxes = Mailboxes(self.account, self.soledad_querier, self.search_engine) - self.mail_sender = Mock() - self.tag_service = TagService() self.draft_service = DraftService(self.mailboxes) - self.mail_service = MailService(self.mailboxes, self.mail_sender, self.tag_service, - self.soledad_querier, self.search_engine) + + self.mail_service = self._create_mail_service(self.mailboxes, self.mail_sender, self.soledad_querier, self.search_engine) self.search_engine.index_mails(self.mail_service.all_mails()) + self.app = App() self.app.resource = RootResource() - - # sending a mail is always successful - self.mail_sender.sendmail.side_effect = lambda mail: succeed(mail) - self.app.resource.initialize(self.soledad_querier, self.search_engine, self.mail_service, self.draft_service) def _render(self, request, as_json=True): @@ -143,6 +136,24 @@ class AppTestClient: self.search_engine.index_mail(mail) return mails + def _create_soledad_querier(self, soledad, index_key): + soledad_querier = SoledadQuerier(soledad) + soledad_querier.get_index_masterkey = lambda: index_key + return soledad_querier + + def _create_mail_sender(self): + mail_sender = Mock() + mail_sender.sendmail.side_effect = lambda mail: succeed(mail) + return mail_sender + + def _create_mail_service(self, mailboxes, mail_sender, soledad_querier, search_engine): + tag_service = TagService() + mail_service = MailService(mailboxes, mail_sender, tag_service, soledad_querier, search_engine) + return mail_service + + def _generate_soledad_test_folder_name(self, soledad_test_folder='/tmp/soledad-test/test'): + return os.path.join(soledad_test_folder, str(uuid.uuid4())) + def initialize_soledad(tempdir): if os.path.isdir(tempdir): @@ -176,3 +187,9 @@ def initialize_soledad(tempdir): cert_file, defer_encryption=False) return _soledad + + + + + + |