test_entries.py :  » Blog » PyBlosxom » pyblosxom-1.5-rc1 » Pyblosxom » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Blog » PyBlosxom 
PyBlosxom » pyblosxom 1.5 rc1 » Pyblosxom » tests » test_entries.py
import time
from StringIO import StringIO

from Pyblosxom.tests.helpers import req_,UnitTestBase

from Pyblosxom.tools import STANDARD_FILTERS
from Pyblosxom.pyblosxom import Request
from Pyblosxom.entries.base import EntryBase,generate_entry

TIME1 = (2008, 7, 21, 12, 51, 47, 0, 203, 1)

class TestEntryBase(UnitTestBase):
    def test_data(self):
        e = EntryBase(req_())
        self.eq_(e.get_data(), "")

        s1 = "la la la la la"
        e.set_data(s1)
        self.eq_(e.get_data(), s1)
        self.eq_(type(e.get_data()), str)

        s2 = u"foo foo foo foo foo"
        e.set_data(s2)
        self.eq_(e.get_data(), s2)
        self.eq_(type(e.get_data()), str)

        s3 = "foo bar"
        e.set_data(s3)
        self.eq_(e.get_data(), s3)

    def test_metadata(self):
        e = EntryBase(req_())
        self.eq_(e.get_metadata_keys(), STANDARD_FILTERS.keys())
        self.eq_(e.get_metadata("foo"), None)
        self.eq_(e.get_metadata("foo", "bar"), "bar")
        e.set_metadata("foo", "bar")
        self.eq_(e.get_metadata("foo"), "bar")

    def test_time(self):
        # FIXME - these tests are locale dependent
        e = EntryBase(req_())
        e.set_time(TIME1)
        for mem in (("timetuple", TIME1),
                    ("mtime", 1216659107.0),
                    ("ti", "12:51"),
                    ("mo", "Jul"),
                    ("mo_num", "07"),
                    ("da", "21"),
                    ("dw", "Monday"),
                    ("yr", "2008"),
                    ("fulltime", "20080721125147"),
                    ("date", "Mon, 21 Jul 2008"),
                    ("w3cdate", "2008-07-21T16:51:47Z"),
                    ("rfc822date", "Mon, 21 Jul 2008 16:51 GMT")):
            self.eq_(e[mem[0]], mem[1], \
                  "%s != %s (note: this is a locale dependent test)" % (mem[0], mem[1]))

    def test_dictlike(self):
        e = EntryBase(req_())
        e["foo"] = "bar"
        e["body"] = "entry body"

        def sortlist(l):
            l.sort()
            return l

        self.eq_(sortlist(e.keys()), sortlist(STANDARD_FILTERS.keys() + ["foo", "body"]))

        self.eq_(e["foo"], "bar")
        self.eq_(e.get("foo"), "bar")
        self.eq_(e.get("foo", "fickle"), "bar")
        self.eq_(e.get_metadata("foo"), "bar")
        self.eq_(e.get_metadata("foo", "fickle"), "bar")

        self.eq_(e["body"], "entry body", "e[\"body\"]")
        self.eq_(e.get("body"), "entry body", "e.get(\"body\")")
        self.eq_(e.getData(), "entry body", "e.getData()")

        self.eq_(e.get("missing_key", "default"), "default")
        self.eq_(e.get("missing_key"), None)

        # e.set("faz", "baz")
        # yield eq_, e.get("faz"), "baz"

        self.eq_(e.has_key("foo"), True)
        self.eq_(e.has_key("foo2"), False)
        self.eq_(e.has_key("body"), True)
        # yield eq_, "foo" in e, True
        # yield eq_, "foo2" in e, False
        # yield eq_, "foo2" not in e, True
        # yield eq_, "body" in e, True

        e.update({"foo": "bah", "faux": "pearls"})
        self.eq_(e["foo"], "bah")
        self.eq_(e["faux"], "pearls")

        e.update({"body": "new body data"})
        self.eq_(e["body"], "new body data")
        self.eq_(e.get_data(), "new body data")

        # del e["foo"]
        # yield eq_, e.get("foo"), None

    # @raises(KeyError)
    # def test_delitem_keyerror(self):
    #     e = EntryBase(req_())
    #     del e["missing_key"]

    # @raises(ValueError)
    # def test_delitem_valueerror(self):
    #     e = EntryBase(req_())
    #     del e["body"]

    def test_generate_entry(self):
        e = generate_entry(req_(), {"foo": "bar"}, "entry body", TIME1)

        self.eq_(e["foo"], "bar")
        self.eq_(e["body"], "entry body")
        self.eq_(e["rfc822date"], "Mon, 21 Jul 2008 16:51 GMT")

        e = generate_entry(req_(), {"foo": "bar"}, "entry body")

    def test_repr(self):
        # it doesn't really matter what __repr__ sends back--it's only used
        # for logging/debugging.  so this test adds coverage for that line to
        # make sure it doesn't error out.
        e = EntryBase(req_())
        repr(e)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.