Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-07-13 03:03:19 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-07-13 03:03:19 (GMT)
commitc5ea9bd1f81baa2c367811ae38ff558d1c3eef0e (patch)
tree589131e550ed2463d7f43cb52c32bd230bc3e5a2 /tests
parentb58ff0c10ce8246d8d62a09d0aa6622c059e4d28 (diff)
more passing tests
Diffstat (limited to 'tests')
-rwxr-xr-xtests/cleaner.py3
-rw-r--r--tests/milestone_2.txt2
-rw-r--r--tests/mountpoints.txt18
-rw-r--r--tests/properties.txt2
-rw-r--r--tests/query.txt275
-rw-r--r--tests/test_model.py2
-rw-r--r--tests/xapianindex.txt2
7 files changed, 16 insertions, 288 deletions
diff --git a/tests/cleaner.py b/tests/cleaner.py
index 8cc795b..cfa15bf 100755
--- a/tests/cleaner.py
+++ b/tests/cleaner.py
@@ -5,10 +5,11 @@ from ore.main import Application
filepattern = re.compile("(\w{8})\-(\w{4})\-(\w{4})\-(\w{4})\-(\w{12})")
tmppattern = re.compile("tmp\S{6}")
+onepattern = re.compile("one.*\.txt")
staticdirs = re.compile('test_ds|store\d')
-filepatterns = [filepattern, tmppattern]
+filepatterns = [filepattern, tmppattern, onepattern]
dirpatterns = [staticdirs]
class Cleaner(Application):
diff --git a/tests/milestone_2.txt b/tests/milestone_2.txt
index 35ad9ec..73fd43a 100644
--- a/tests/milestone_2.txt
+++ b/tests/milestone_2.txt
@@ -10,7 +10,7 @@ First clean up from any other tests.
>>> from olpc.datastore import backingstore, model
>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)
->>> dm = model.defaultModel.addField('year', 'int').addField('month', 'string')
+>>> dm = model.defaultModel.copy().addField('year', 'int').addField('month', 'string')
>>> assert ds.mount("/tmp/test_ds", {'indexmanager.model' : dm})
diff --git a/tests/mountpoints.txt b/tests/mountpoints.txt
index 1066da0..eebad9b 100644
--- a/tests/mountpoints.txt
+++ b/tests/mountpoints.txt
@@ -12,7 +12,7 @@ mounting a backingstore on the datastore.
>>> from olpc.datastore import DataStore
>>> from olpc.datastore import backingstore
->>> from testutils import tmpData, waitforindex
+>>> from testutils import tmpData
>>> import dbus
@@ -20,7 +20,7 @@ Here we create a datastore, and mount a backingstore on tmp. By
default this will create a new directory in /tmp which will then be
used for storage.
->>> ds = DataStore(sync_index=True)
+>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)
>>> mp1 = ds.mount("/tmp/store1", dict(title="Primary Storage"))
@@ -36,12 +36,12 @@ can be used to control the storage target or to filter results.
Now lets create some content
>>> u1 = ds.create(dict(title="Document 1", filename="one.txt"), tmpData("""document one"""))
->>> u2 = ds.create(dict(title="Document 2", mime_type="text/plain"), tmpData("""document two"""))
+>>> u2 = ds.create(dict(title="Document 2", mimetype="text/plain"), tmpData("""document two"""))
We can now, if we wish verify which mount point this content came
from.
->>> waitforindex(ds)
+>>> ds.complete_indexing()
>>> c1 = ds.get(u1)
>>> assert c1.backingstore.id == mountpoint
@@ -62,7 +62,7 @@ Now lets add another mount point.
Now lets create a new content item.
>>> u3 = ds.create(dict(title="Document 3", mountpoint=mp2), tmpData("""document three"""))
->>> waitforindex(ds)
+>>> ds.complete_indexing()
We explictly passed a mount point here. Lets examine the properties of
the object and verify this.
@@ -105,7 +105,7 @@ Register the filesystem type
If that worked it should have imported content on load().
->>> waitforindex(ds)
+>>> ds.complete_indexing()
>>> result, count = ds.find(dict(fulltext="four"))
>>> assert count == 1
@@ -117,9 +117,11 @@ as DBus data.
>>> ds.unmount(mp3)
->>> mp3 = ds.mount("inplace:/tmp/store3", dict(title=dbus.String("Fake USB again")))
+>>> mp3 = ds.mount("inplace:/tmp/store3", dict(title=dbus.String("Fake USB again"),
+... sync_mount=True))
+
+>>> ds.complete_indexing()
->>> waitforindex(ds)
>>> result, count = ds.find(dict(fulltext="four"))
>>> assert count == 1
diff --git a/tests/properties.txt b/tests/properties.txt
index 6067aac..fe34782 100644
--- a/tests/properties.txt
+++ b/tests/properties.txt
@@ -19,7 +19,7 @@ Set up two mount points.
Extend the model to retain a 'year' property used below.
->>> dm = model.defaultModel.addField('year', "int")
+>>> dm = model.defaultModel.copy().addField('year', "int")
Mount a couple of stores.
diff --git a/tests/query.txt b/tests/query.txt
deleted file mode 100644
index 1e7624e..0000000
--- a/tests/query.txt
+++ /dev/null
@@ -1,275 +0,0 @@
-This document outlines the basic usage of the olpc.datastore.query and
-olpc.datastore.model modules. Not that these are not use independ of
-the olpc.datastore.backend which in turn is only accessed through the
-olpc.datastore module. This is intended only to document the innards
-of those modules.
-
->>> import os
->>> assert os.system('rm -rf /tmp/_test_index') == 0
->>> assert os.system('rm -rf /tmp/_test_fulltext') == 0
-
-
-First lets create a query manager
-
->>> from olpc.datastore.query import DefaultQueryManager
->>> from olpc.datastore.model import Property
->>> qm = DefaultQueryManager("/tmp/_test_index", fulltext_repo='/tmp/_test_fulltext')
->>> qm.prepare()
-True
-
-That will create the memory backed database which will be used in this
-documentation. The call to prepare() is normally invoked by the higher
-level datastore for you.
-
-Because this is a new database there should be nothing in it. We can
-verify this with the call to the find() method.
-
->>> qm.find()
-([], 0)
-
-
-The simplest way to add an entry to the datastore is by passing a
-dictionary of properties to the create method.
-
->>> a = qm.create(dict(title="New Content"))
-
-Find will now return this object.
-
->>> qm.find()
-([<Content id:...>], 1)
-
-We can examine the Properties of this object.
-
->>> a.properties
-[... <TextProperty title:'New Content'>, ...]
-
-This returned a list of all properties on the Content object in which
-case we can find the property by enumeration. The other option is
-using the get_properties call on Content
-
->>> a.get_properties(dict(key='title'))
-[<TextProperty title:'New Content'>]
-
-Using the query manager API we are able to update the
-properties. Using this form automatically synchronizes with the
-database and the property is immediately available. To demonstrate
-that this works lets attach another property.
->>> qm.update(a, dict(author='Benjamin'))
-
-A request for title still returns only the title property.
->>> a.get_properties(dict(key='title'))
-[<TextProperty title:'New Content'>]
-
-And a request for author works as expected.
->>> a.get_properties(dict(key='author'))
-[<Property author:'Benjamin'>]
-
->>> qm.update(a, dict(foo='bar'))
->>> set([p.key for p in a.properties]) == set(['title', 'mtime', 'ctime', 'language', 'mime_type', 'author', 'foo'])
-True
-
-We could have also passed an id for the content object rather than the
-object itself. A list of properties would have been acceptable in
-place of a dictionary. One thing that is shown here is that a number
-of default properties were added when the Content object was
-created. This is done by default and can be controlled by the
-include_defaults flag to the create() method.
-
-Some of the default Property objects have values which are not of the
-'string' type. 'ctime' and 'mtime' are examples of these
-
->>> a.get_property('ctime')
-datetime.datetime(...)
-
-We can see that ctime has been mapped to a standard Python
-datetime.datetime instance. olpc.datastore.model includes support for
-'number' and 'datetime' Property types by default. To add support for
-new property types see the oplc.datastore.model.Model.addPropertyType
-method.
-
-Here we want to show that certain types of Properties map to
-specialized implemenations automatically based on their type. 'ctime'
-is a DateTime Property and we can verify that it is returned properly
-from the mapping layer with the following.
->>> ctimeProp = a.get_properties(dict(key='ctime'))[0]
->>> ctimeProp.kind == "date"
-True
-
-Special support is needed to make dates easily addressable within the
-datastore. The properties 'ctime', creation time, and 'mtime',
-modification time are supported. To query on these properties two
-methods are available.
-
->>> qm.find(ctime="2007-01-01 00:00")
-([], 0)
-
-Which matches nothing. And the other form is to pass a dict with
-'start' and 'end' range boundries.
->>> import datetime
->>> now = datetime.datetime.now().isoformat()
-
->>> qm.find(ctime=dict(end=now))
-([<Content id:...>], 1)
-
-
-Property keys are unique per Content item. This means that adding a
-Property with an existing key should update the value rather than add
-another Property with the same key.
-
->>> qm.update(a.id, [Property('another', 'property')])
->>> a.get_property('another')
-'property'
-
->>> l1 = len(a.properties)
->>> qm.update(a, dict(another="test"))
->>> a.get_property('another')
-'test'
->>> len(a.properties) == l1
-True
-
-Both forms of passing properties work.
-
->>> l1 = len(a.properties)
->>> qm.update(a, [Property('another', 'value')])
->>> a.get_property('another')
-'value'
->>> len(a.properties) == l1
-True
-
-
-We can also navigate from a Property object to the content to which it
-refers. This is available through the 'content' attrbiute of
-properties. Only properties bound to content and synchronized with the
-database have this property.
-
->>> p = a.get_properties(dict(key='author'))[0]
->>> p.content
-<Content id:...>
-
-Let's create additional content.
-
->>> b = qm.create(dict(title="My Picture", author="Sarah", mime_type="image/png"))
->>> c = qm.create(dict(title="My Song", author="Sarah", mime_type="audio/mp3"))
-
-At this point the find() method should be able to provide us with more
-interesting results. Note at this point that find() has multiple
-responsibilities. First it must search the Properties of objects,
-secondly it provides access to the full-text index associated with
-content in the datastore.
-
-For now we are only interested in the properties.
-
->>> qm.find(mime_type="image/png") == ([b], 1)
-True
-
->>> qm.find(author="Benjamin") == ([a],1)
-True
-
->>> qm.find(author="Sarah") == ([b, c],2)
-True
-
->>> qm.find(author="Sarah", mime_type="audio/mp3") == ([c], 1)
-True
-
-Passing the special value, 'content' to find will pass an expression
-to the full text index engine. The query manager maintains a full-text
-index in parallel to the normal metadata storeage. The full text index
-is updated on every create, update and delete call to the query
-manager provided the mime_type Property of the Content is one
-understood by the index.
-
->>> from StringIO import StringIO
->>> qm.update(a, {}, StringIO("this is my content, hear it roar"))
->>> qm.find(fulltext="roar") == ([a], 1)
-True
-
-Combining this with properties also works.
->>> qm.find(fulltext="roar", author="Benjamin") == ([a], 1)
-True
-
-And we can verify the negitive as well.
->>> qm.find(fulltext="roar", author="Sarah")
-([], 0)
-
-Calls to update() and create() both take an optional file argument
-which will update the fulltext indexed content with the new value of
-file.
-
->>> qm.update(a, filelike=StringIO("different text"))
-
-The new content will be found
->>> qm.find(fulltext="different", author="Benjamin") == ([a], 1)
-True
-
-And the old content is not.
->>> qm.find(fulltext="roar", author="Benjamin")
-([], 0)
-
-
-Passing a filename for file works as well. Files can be in a variety
-of binary formats include PDF.
->>> qm.update(a, filelike="test.doc")
->>> qm.find(fulltext="roar", author="Benjamin")
-([], 0)
->>> qm.find(fulltext="amazed", author="Benjamin") == ([a], 1)
-True
-
-We have converters for DOC, PDF and ODT by default
-
->>> qm.update(a, filelike="test.pdf")
->>> qm.find(fulltext="peek", author="Benjamin") == ([a], 1)
-True
-
-
->>> qm.update(a, filelike="test.odt")
->>> qm.find(fulltext="amazed", author="Benjamin") == ([a], 1)
-True
-
->>> qm.update(a, dict(title="titled indeed"), filelike="test.doc")
->>> qm.find(fulltext="amazed", author="Benjamin") == ([a], 1)
-True
-
-For the last example we can see that we also updated the title. Here
-we show that because title is a 'text' property, rather than a simple
-string its contents will be available to the text indexing engine as
-well.
-
-Searching for a direct match on the property works.
->>> qm.find(title="titled indeed") == ([a], 1)
-True
-
-Doing a search for text internal to the title doesn't however.
-
->>> qm.find(title="indeed") == ([a], 1)
-False
-
-Searching for it in the fulltext index does return a result.
->>> qm.find(fulltext="indeed") == ([a], 1)
-True
-
-Searching for only title in fulltext index does return a result as well.
->>> qm.find(fulltext="title:indeed") == ([a], 1)
-True
-
-
-Here we show off the get_uniquevaluesfor call examining all the values
-used in the 'author' field.
-
->>> assert set(qm.get_uniquevaluesfor('author')) == set(['Benjamin', 'Sarah'])
-
-Now that we can see a set of possible values it might be nice to
-select any content with properties from a known set. For example
-
->>> r, c = qm.find(author=['Benjamin', 'Sarah'])
->>> assert c == 3
-
-By putting the request value in a list we can ask that the value be
-'IN' this collection. All participating values are included in this
-way.
-
-
-Now for politeness we shut everything down
->>> qm.stop()
->>> import shutil, os
->>> shutil.rmtree('/tmp/_test_fulltext')
->>> os.unlink('/tmp/_test_index.db')
diff --git a/tests/test_model.py b/tests/test_model.py
index 2f44b41..2ac2fb2 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -30,7 +30,7 @@ class Test(unittest.TestCase):
ds.registerBackend(backingstore.FileBackingStore)
#add a custom field to the model
- dm = model.defaultModel.addField('thumbnail', 'binary')
+ dm = model.defaultModel.copy().addField('thumbnail', 'binary')
ds.mount(DEFAULT_STORE, {'indexmanager.model' : dm})
diff --git a/tests/xapianindex.txt b/tests/xapianindex.txt
index 5ef1d5c..354d7a8 100644
--- a/tests/xapianindex.txt
+++ b/tests/xapianindex.txt
@@ -28,7 +28,7 @@ Now add the file to the index.
Let the async indexer do its thing. We ask the indexer if it has work
left, when it has none we expect our content to be indexed and searchable.
->>> while im.working: time.sleep(0.5)
+>>> im.complete_indexing()
Searching on an property of the content works.