Commits

Jesper Nøhr  committed 86556a0

adding a test to test the validation of add_event

  • Participants
  • Parent commits bd14e6c

Comments (0)

Files changed (2)

File src/rewsfeed/models.py

     # --
 
     def __repr__(self):
-        return '<'+', '.join([ '%s=%s' % (k, v) for k, v in self.kw.iteritems() ])+'>'
+        return '<'+', '.join([ '%s=%s' % (k, v[0:255]) for k, v in self.kw.iteritems() ])+'>'
     
 class User(DictAbstracted):    
     def follow(self, other_user):
         if not isinstance(who, User):
             raise ValueError("A User must've done it. You gave me '%r'" % who)
 
+        if not kwargs.has_key('timestamp'):
+            raise ValueError("Events need to have timestamps to be ordered.")
+        
         event = cls(network, **kwargs).save()
 
         who.did(event)

File tests/tests.py

 
         self.assertEquals(len(list(self.u1.newsfeed(0, num_events))), num_events)
         self.assertEquals(len(list(self.u2.newsfeed(0, num_events))), num_events)
+
+class TestEventsFail(unittest.TestCase):
+    def setUp(self):
+        self.n = Network('events')
+        self.n.conn.flushdb()
+
+        self.u1 = User(self.n, username='user1')
+        self.u2 = User(self.n, username='user2')        
+
+        self.u2.follow(self.u1)
+        
+        self.u1.save()
+        self.u2.save()
+
+    def test_these_should_fail(self):
+        self.assertRaises(ValueError, Event.add_event, (self.n, 'failme'), { 'timestamp': 12345 })
+        self.assertRaises(ValueError, Event.add_event, (self.n, self.u1), { 'lol_timestamp': 12345 })
+        self.assertRaises(ValueError, Event.add_event, (), { 'lol_timestamp': 12345 })
         
 if __name__ == "__main__":
     unittest.main()