Exemplo n.º 1
0
 def test_list(self):
     user = factory.make_User()
     handler = DiscoveryHandler(user, {}, None)
     factory.make_Discovery()
     factory.make_Discovery()
     expected_discoveries = [
         self.dehydrate_discovery(discovery, for_list=True)
         for discovery in Discovery.objects.all()
     ]
     self.assertItemsEqual(expected_discoveries, handler.list({}))
Exemplo n.º 2
0
 def test_list_orders_by_creation_date(self):
     user = factory.make_User()
     handler = DiscoveryHandler(user, {}, None)
     now = datetime.now()
     d0 = factory.make_Discovery(created=now)
     d4 = factory.make_Discovery(created=(now + timedelta(days=4)))
     d3 = factory.make_Discovery(created=(now + timedelta(days=3)))
     d1 = factory.make_Discovery(created=(now + timedelta(days=1)))
     d2 = factory.make_Discovery(created=(now + timedelta(days=2)))
     # Test for the expected order independent of how the database
     # decided to sort.
     expected_discoveries = [
         self.dehydrate_discovery(discovery, for_list=True)
         for discovery in [d0, d1, d2, d3, d4]
     ]
     self.assertEquals(expected_discoveries, handler.list({}))
Exemplo n.º 3
0
 def test_list_starts_after_first_seen(self):
     user = factory.make_User()
     handler = DiscoveryHandler(user, {}, None)
     now = datetime.now()
     factory.make_Discovery(created=now)
     d4 = factory.make_Discovery(created=(now + timedelta(days=4)))
     d3 = factory.make_Discovery(created=(now + timedelta(days=3)))
     factory.make_Discovery(created=(now + timedelta(days=1)))
     factory.make_Discovery(created=(now + timedelta(days=2)))
     first_seen = now + timedelta(days=2)
     first_seen = str(
         time.mktime(first_seen.timetuple()) + first_seen.microsecond / 1e6)
     # Test for the expected order independent of how the database
     # decided to sort.
     expected_discoveries = [
         self.dehydrate_discovery(discovery, for_list=True)
         for discovery in [d3, d4]
     ]
     self.assertEquals(expected_discoveries,
                       handler.list({"start": first_seen}))