Skip to content

Commit

Permalink
Merge a8b3120 into 8d0a446
Browse files Browse the repository at this point in the history
  • Loading branch information
lundberg committed Nov 22, 2016
2 parents 8d0a446 + a8b3120 commit ac8505c
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ develop:
python setup.py develop

coverage:
coverage run --source cio setup.py test
coverage run --source cio setup.py test && \
coverage report

clean:
rm -rf .tox/ dist/ *.egg *.egg-info .coverage
10 changes: 5 additions & 5 deletions cio/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ def _scope(self):
return self.__class__.__name__.rstrip('Manager').lower()

def _get_backend_config(self):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _is_valid_backend(self, backend):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _clean_get_uri(self, uri):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _clean_set_uri(self, uri):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _clean_delete_uri(self, uri):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _clean_get_uris(self, uris):
return tuple(self._clean_get_uri(uri) for uri in uris)
Expand Down
38 changes: 19 additions & 19 deletions cio/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def clear(self):
"""
Removes all nodes from cache
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _build_cache_key(self, uri):
"""
Expand All @@ -99,22 +99,22 @@ def _build_cache_key(self, uri):
return sha1(key).hexdigest()

def _get(self, key):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _get_many(self, keys):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _set(self, key, value):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _set_many(self, data):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _delete(self, key):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _delete_many(self, keys):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _encode_content(self, uri, content):
"""
Expand Down Expand Up @@ -155,57 +155,57 @@ def get(self, uri):
Return node for uri or raise NodeDoesNotExist:
{uri: x, content: y, meta: {}}
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def get_many(self, uris):
"""
Return request uri map of found nodes as dicts:
{requested_uri: {uri: x, content: y, meta: {}}}
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def set(self, uri, content, **meta):
"""
Persist node data and meta for uri.
Return tuple of node dict and True if created and False if updated:
{uri: x, content: y, meta: {}}, True|False
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def delete(self, uri):
"""
Delete node for uri and return node dict or None if not exists:
{uri: x, content: y, meta: {}}
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def delete_many(self, uris):
"""
Delete node for uri and return request uri map of deleted nodes as dicts:
{requested_uri: {uri: x, content: y, meta: {}}}
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def publish(self, uri, **meta):
"""
Return published node as dict or raise NodeDoesNotExist:
{uri: x, content: y, meta: {}}
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def get_revisions(self, uri):
"""
Return list of tuples with uri and published state:
[('i18n://sv-se@page/title.txt#1', False), ('i18n://sv-se@page/title.md#2', True)]
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def search(self, uri):
"""
Return list of non-versioned uri matches based on uri query pattern:
['i18n://sv-se@page/title.txt', ...]
"""
raise NotImplementedError
raise NotImplementedError # pragma: no cover


class DatabaseBackend(StorageBackend):
Expand Down Expand Up @@ -269,16 +269,16 @@ def delete_many(self, uris):
return deleted_nodes

def _get(self, uri):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _create(self, uri, content, **meta):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _update(self, uri, content, **meta):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _delete(self, node):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def _build_key(self, uri):
"""
Expand Down
4 changes: 2 additions & 2 deletions cio/backends/locmem/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ def _delete(self, key):

def _delete_many(self, keys):
for key in keys:
if key in self._cache:
del self._cache[key]
self._delete(key)
self.calls -= 1 # Revert individual _delete call count
self.calls += 1
9 changes: 9 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cio
import six
from cio.backends import cache
from cio.conf.exceptions import ImproperlyConfigured
from cio.pipeline import pipeline
from cio.backends import storage
from cio.backends.exceptions import NodeDoesNotExist
Expand Down Expand Up @@ -81,6 +82,10 @@ def test_set(self):
self.assertEqual(node.uri.ext, 'txt')
self.assertEqual(len(node.meta.keys()), 0)

# Try publish non-existing node/uri
node = cio.publish('i18n://sv-se@foo/bar.txt#draft')
self.assertIsNone(node)

def test_delete(self):
with self.assertRaises(URI.Invalid):
cio.delete('foo/bar')
Expand Down Expand Up @@ -335,3 +340,7 @@ def test_forced_empty_content(self):
def test_load_pipeline(self):
with self.assertRaises(ImportError):
pipeline.add_pipe('foo.Bar')

def test_unknown_plugin(self):
with self.assertRaises(ImproperlyConfigured):
cio.set('i18n://sv-se@foo/bar.baz#draft', 'raise')
17 changes: 17 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cio
from cio.conf import settings
from cio.plugins import plugins
from cio.plugins import md as md_module
from cio.backends import storage
from cio.plugins.exceptions import UnknownPlugin
from cio.plugins.txt import TextPlugin
Expand Down Expand Up @@ -51,3 +52,19 @@ def test_plugin(self):
self.assertEqual(node.uri.ext, 'up')

self.assertSetEqual(set(p for p in plugins), set(('txt', 'md', 'up')))

def test_settings(self):
settings.configure(TXT={
'foo': 'bar'
})

plugin = plugins.get('txt')
self.assertEqual(plugin.settings['foo'], 'bar')

def test_markdown(self):
markdown = plugins.get('md')
self.assertEqual(markdown.render('# Title'), '<h1>Title</h1>')

md_module.PY26 = True
self.assertEqual(markdown.render('# Title'), '# Title')
md_module.PY26 = cio.PY26
13 changes: 13 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# coding=utf-8
from cio import lazy_shortcut
from cio.utils.formatters import ContentFormatter
from cio.utils.uri import URI
from cio.utils.imports import import_class
from tests import BaseTest


Expand Down Expand Up @@ -59,3 +61,14 @@ def test_formatter(self):

for template, context, value in tests:
self.assertEqual(formatter.format(template, **context), value or template)

def test_import_class(self):
CF = import_class('cio.utils.formatters', 'ContentFormatter')
self.assertEqual(CF, ContentFormatter)

with self.assertRaises(ImportError):
import_class('cio.utils.formatters', 'FooBar')

def test_lazy_shortcut(self):
uri_module = lazy_shortcut('cio.utils', 'uri')
self.assertEqual(uri_module.URI, URI)

0 comments on commit ac8505c

Please sign in to comment.