Commits

Tim Freund  committed 5181844

Starting to build out some timezone offset tests

  • Participants
  • Parent commits 80bdfc7

Comments (0)

Files changed (2)

File ironblogger/models.py

 DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
 Base = declarative_base()
 
+# TODO - I'd rather see this as a method to the Base class
+def set_instance_defaults(instance):
+    for name in [c.name for c in instance.__table__.columns]:
+        column = instance.__table__.columns[name]
+        if column.default is not None:
+            setattr(instance, name, column.default.execute())
+
 class Feed(object):
     def __init__(self, feed_url=None, html_url=None, 
                  entries=[], updated_at=None):
     weeks = relationship("Week", backref="ironblogger")
 
     def __init__(self, **kw):
+        set_instance_defaults(self)
         for key, value in kw.items():
             setattr(self, key, value)
 
     posts = relationship("Post", backref="blog")
     
     def __init__(self, **kw):
+        set_instance_defaults(self)
         for key, value in kw.items():
             setattr(self, key, value)
 

File ironblogger/tests/unit_tests.py

         self.session.add(ib)
         transaction.commit()
 
+class TestTimeZones(unittest.TestCase):
+    def offset_helper(self, to_test):
+        self.assertIsInstance(to_test.gmt_offset, int)
+        for value in [-12, 0, 12]:
+            to_test.gmt_offset = value
+            self.assertEquals(to_test.gmt_offset, value)
+
+        for value in [-13, 13]:
+            try:
+                to_test.gmt_offset = value
+            except ValueError, e:
+                self.assertEquals(e.message, "GMT Offset value is out of range")
+
+    def test_offset_ironblogger(self):
+        from ironblogger.models import IronBlogger
+        ironblogger = IronBlogger()
+        self.offset_helper(ironblogger)
+
+    def test_offset_blog(self):
+        from ironblogger.models import Blog
+        blog = Blog()
+        self.offset_helper(blog)
+
     # def _makeOne(self):
     #     from ironblogger.models import MyRoot
     #     return MyRoot()