Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pytest-cov
pep8
pyflakes
WebTest==2.0.17
pytest-xdist
2 changes: 1 addition & 1 deletion bootstrap.yaml → springboard.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# List of content repositories to be working with
repositories:
- 'https://github.com/universalcore/unicore-cms-content-gem-tanzania'
unicore-cms-content-gem-tanzania: 'https://github.com/universalcore/unicore-cms-content-gem-tanzania'

# List of models to be loaded and their mappings, if any.
models:
Expand Down
2 changes: 1 addition & 1 deletion springboard/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SpringboardTestCase(TestCase):

destroy = 'KEEP_REPO' not in os.environ
bootstrap_file = pkg_resources.resource_filename(
'springboard', 'tests/test_bootstrap.yaml')
'springboard', 'tests/test_springboard.yaml')
working_dir = '.test_repos/'

def mk_workspace(self, working_dir=None,
Expand Down
154 changes: 93 additions & 61 deletions springboard/tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
from StringIO import StringIO

Expand All @@ -7,7 +8,21 @@
BootstrapTool)


class TestCloneRepoTool(SpringboardTestCase):
class SpringboardToolTestCase(SpringboardTestCase):

def mk_workspace_name(self, workspace):
return os.path.basename(workspace.working_dir)

def mk_workspace_config(self, workspace):
repo_name = self.mk_workspace_name(self.workspace)
return {
'repositories': {
repo_name: self.workspace.working_dir,
}
}


class TestCloneRepoTool(SpringboardToolTestCase):

def setUp(self):
self.workspace = self.mk_workspace()
Expand All @@ -17,32 +32,35 @@ def test_clone_repo(self):
tool = CloneRepoTool()
tool.stdout = StringIO()
tool.run(
config=self.mk_workspace_config(self.workspace),
verbose=True,
clobber=False,
repo_url=self.workspace.working_dir,
repo_dir='%s/test_clone_repo' % (self.working_dir,))
repo_dir='%s/test_clone_repo' % (self.working_dir,),
repo_name=self.mk_workspace_name(self.workspace))
output = tool.stdout.getvalue()
self.assertTrue(output.startswith('Cloning'))
self.assertTrue(output.endswith('test_clone_repo.\n'))

tool.run(
config=self.mk_workspace_config(self.workspace),
verbose=True,
clobber=False,
repo_url=self.workspace.working_dir,
repo_dir='%s/test_clone_repo' % (self.working_dir,))
repo_dir='%s/test_clone_repo' % (self.working_dir,),
repo_name=self.mk_workspace_name(self.workspace))
output = tool.stdout.getvalue()
self.assertTrue(output.endswith('already exists, skipping.\n'))

tool.run(
config=self.mk_workspace_config(self.workspace),
verbose=True,
clobber=True,
repo_url=self.workspace.working_dir,
repo_dir='%s/test_clone_repo' % (self.working_dir,))
repo_dir='%s/test_clone_repo' % (self.working_dir,),
repo_name=self.mk_workspace_name(self.workspace))
output = tool.stdout.getvalue()
self.assertTrue(output.endswith('Clobbering existing repository.\n'))


class TestCreateIndex(SpringboardTestCase):
class TestCreateIndex(SpringboardToolTestCase):

def setUp(self):
self.workspace = self.mk_workspace()
Expand All @@ -52,22 +70,26 @@ def test_create_index(self):
tool = CreateIndexTool()
tool.stdout = StringIO()
tool.run(
config=self.mk_workspace_config(self.workspace),
verbose=True,
clobber=False,
repo_dir=self.workspace.working_dir)
repo_dir=self.workspace.working_dir,
repo_name=self.mk_workspace_name(self.workspace))
output = tool.stdout.getvalue()
self.assertTrue(output.endswith('Index already exists, skipping.\n'))

tool.run(
config=self.mk_workspace_config(self.workspace),
verbose=True,
clobber=True,
repo_dir=self.workspace.working_dir)
repo_dir=self.workspace.working_dir,
repo_name=self.mk_workspace_name(self.workspace))
output = tool.stdout.getvalue()
self.assertTrue(
output.endswith('Clobbering existing index.\nIndex created.\n'))


class TestCreateMapping(SpringboardTestCase):
class TestCreateMapping(SpringboardToolTestCase):

def setUp(self):
self.workspace = self.mk_workspace()
Expand All @@ -76,28 +98,31 @@ def setUp(self):
def test_create_mapping(self):
tool = CreateMappingTool()
tool.stdout = StringIO()
tool.run(verbose=True,

config = self.mk_workspace_config(self.workspace)
config['models'] = {
'elasticgit.tests.base.TestPerson': {
'properties': {
'name': {
'index': 'not_analyzed',
'type': 'string',
}
}
}
}

tool.run(config=config,
verbose=True,
clobber=False,
config={
'models': {
'elasticgit.tests.base.TestPerson': {
'properties': {
'name': {
'index': 'not_analyzed',
'type': 'string',
}
}
}
}
},
repo_dir=self.workspace.working_dir)
repo_dir=self.workspace.working_dir,
repo_name=self.mk_workspace_name(self.workspace))
self.assertEqual(
tool.stdout.getvalue(),
'Creating mapping for elasticgit.tests.base.TestPerson.\n'
'Mapping created.\n')


class TestSyncData(SpringboardTestCase):
class TestSyncData(SpringboardToolTestCase):

def setUp(self):
self.workspace = self.mk_workspace()
Expand All @@ -106,54 +131,61 @@ def setUp(self):
def test_sync_data(self):
tool = SyncDataTool()
tool.stdout = StringIO()
tool.run(verbose=True,

config = self.mk_workspace_config(self.workspace)
config['models'] = {
'elasticgit.tests.base.TestPerson': {
'properties': {
'name': {
'index': 'not_analyzed',
'type': 'string',
}
}
}
}

tool.run(config=config,
verbose=True,
clobber=False,
config={
'models': {
'elasticgit.tests.base.TestPerson': {
'properties': {
'name': {
'index': 'not_analyzed',
'type': 'string',
}
}
}
}
},
repo_dir=self.workspace.working_dir)
repo_dir=self.workspace.working_dir,
repo_name=self.mk_workspace_name(self.workspace))
self.assertEqual(
tool.stdout.getvalue(),
'Syncing data for elasticgit.tests.base.TestPerson.\n'
'Data synced.\n')


class TestBootstrapTool(SpringboardTestCase):
class TestBootstrapTool(SpringboardToolTestCase):

def setUp(self):
self.workspace = self.mk_workspace()

def test_bootstrap(self):
tool = BootstrapTool()
tool.stdout = StringIO()
tool.run(verbose=True,

config = self.mk_workspace_config(self.workspace)
config['models'] = {
'elasticgit.tests.base.TestPerson': {
'properties': {
'name': {
'index': 'not_analyzed',
'type': 'string',
}
}
}
}

tool.run(config=config,
verbose=True,
clobber=False,
config={
'repositories': [self.workspace.working_dir],
'models': {
'elasticgit.tests.base.TestPerson': {
'properties': {
'name': {
'index': 'not_analyzed',
'type': 'string',
}
}
}
}
}, repo_dir=self.working_dir)
repo_dir=self.working_dir)

output = tool.stdout.getvalue()
self.assertTrue(output.startswith('Cloning'))
self.assertTrue(output.endswith(
'Destination already exists, skipping.\n'
'Creating index for master.\n'
'Index already exists, skipping.\n'))
lines = tool.stdout.getvalue().split('\n')
self.assertTrue(lines[0].startswith('Cloning'))
self.assertTrue(
lines[0].endswith(
'%s.' % (self.mk_workspace_name(self.workspace))))
self.assertEqual(lines[1], 'Destination already exists, skipping.')
self.assertEqual(lines[2], 'Creating index for master.')
self.assertEqual(lines[3], 'Index already exists, skipping.')
Loading