|
@@ -89,6 +89,50 @@ class TestContribPrivacy(TestCase):
|
|
|
self.assertEqual(c.get_public_field('name'), None)
|
|
|
|
|
|
|
|
|
+class TestContribQuerySet(TestCase):
|
|
|
+ def test_expired(self):
|
|
|
+ with freeze_time('12-11-2100', tz_offset=0):
|
|
|
+ Contrib.objects.create(
|
|
|
+ name='foo', orientations=['S'],
|
|
|
+ contrib_type=Contrib.CONTRIB_CONNECT,
|
|
|
+ latitude=0.5, longitude=0.5)
|
|
|
+ # one year and one month later
|
|
|
+ with freeze_time('12-12-2101', tz_offset=0):
|
|
|
+ Contrib.objects.create(
|
|
|
+ name='bar', orientations=['S'],
|
|
|
+ contrib_type=Contrib.CONTRIB_CONNECT,
|
|
|
+ latitude=0.5, longitude=0.5)
|
|
|
+
|
|
|
+ expired = Contrib.objects.expired()
|
|
|
+ self.assertEqual(expired.count(), 1)
|
|
|
+ self.assertEqual(expired.first().name, 'foo')
|
|
|
+
|
|
|
+ def test_expired_in_days(self):
|
|
|
+ Contrib.objects.create(
|
|
|
+ name='foo', orientations=['S'],
|
|
|
+ contrib_type=Contrib.CONTRIB_CONNECT,
|
|
|
+ latitude=0.5, longitude=0.5)
|
|
|
+
|
|
|
+ self.assertEqual(Contrib.objects.expired_in_days(0).count(), 0)
|
|
|
+ self.assertEqual(Contrib.objects.expired_in_days(366).count(), 1)
|
|
|
+
|
|
|
+ def test_expires_in_days(self):
|
|
|
+ with freeze_time('12-11-2101 12:00', tz_offset=0):
|
|
|
+ Contrib.objects.create(
|
|
|
+ name='foo', orientations=['S'],
|
|
|
+ contrib_type=Contrib.CONTRIB_CONNECT,
|
|
|
+ latitude=0.5, longitude=0.5)
|
|
|
+ self.assertEqual(Contrib.objects.expires_in_days(364).count(), 0)
|
|
|
+ self.assertEqual(Contrib.objects.expires_in_days(365).count(), 1)
|
|
|
+ self.assertEqual(Contrib.objects.expires_in_days(366).count(), 0)
|
|
|
+
|
|
|
+ # One year, one hour and two minutes later
|
|
|
+ # (check that minutes/hours are ignored)
|
|
|
+ with freeze_time('12-11-2101 13:02', tz_offset=0):
|
|
|
+ self.assertEqual(Contrib.objects.expires_in_days(365).count(), 1)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
class TestViews(APITestCase):
|
|
|
def mk_contrib_post_data(self, *args, **kwargs):
|
|
|
post_data = {
|