예제 #1
0
    def test_query(self):
        doc = {
            "key": "/books/OL1M",
            "type": {"key": "/type/edition"},
            "title": "The Test Book",
            "subjects": ["love", "san_francisco"]
        }
        timestamp = datetime.datetime(2010, 1, 2, 3, 4, 5)

        site = MockSite()
        site.save(doc, timestamp=timestamp)
        
        for i in site.index:
            print dict(i)
            
        assert site.things({"type": "/type/edition"}) == ["/books/OL1M"]
        assert site.things({"type": "/type/work"}) == []
        
        assert site.things({"type": "/type/edition", "subjects": "love"}) == ["/books/OL1M"]
        assert site.things({"type": "/type/edition", "subjects": "hate"}) == []

        assert site.things({"key~": "/books/*"}) == ["/books/OL1M"]
        assert site.things({"key~": "/works/*"}) == []
        
        assert site.things({"last_modified>": "2010-01-01"}) == ["/books/OL1M"]
        assert site.things({"last_modified>": "2010-01-03"}) == []
        
        
예제 #2
0
    def test_process_edition(self):
        site = MockSite()
        s = SeedEngine(site)
        
        # process_edition returns a iterator with each entry containig:
        # (seed, work_key, edition_key, ebook)
        
        def f(edition):
            result = sorted(s.process_edition(edition))
            print result
            return result
            
        # edition with no works
        edition = {
            "key": "/books/OL1M"
        }
        assert f(edition) == [
            {"key": "/books/OL1M"},
        ]
        
        # edition with no works and ebook
        edition = {
            "key": "/books/OL1M",
            "ocaid": "foo"
        }
        assert f(edition) == [
            {"key": "/books/OL1M"},
        ]
        
        # edition with one work
        edition = {
            "key": "/books/OL1M",
            "works": [{"key": "/works/OL1W"}]
        }
        
        site.save({
            "key": "/works/OL1W",
            "authors": [{
                "author": {"key": "/authors/OL1A"}
            }],
            "subjects": ["foo"]
        })

        assert f(edition) == [
            {"key": "/authors/OL1A"},
            {"key": "/books/OL1M"},
            {"key": "/works/OL1W"},
            "subject:foo"
        ]
예제 #3
0
 def test_get(self):
     doc = {
         "key": "/books/OL1M",
         "type": {"key": "/type/edition"},
         "title": "The Test Book"
     }
     timestamp = datetime.datetime(2010, 1, 2, 3, 4, 5)
     
     site = MockSite()
     site.save(doc, timestamp=timestamp)
     
     assert site.get("/books/OL1M").dict() == {
         "key": "/books/OL1M",
         "type": {"key": "/type/edition"},
         "title": "The Test Book",
         "revision": 1,
         "last_modified": {
             "type": "/type/datetime",
             "value": "2010-01-02T03:04:05"
         }
     }