Permalink
Browse files

Fetch a user's events from the DB

  • Loading branch information...
1 parent 89b4548 commit 7aff8be5e3735d606f13010b427e20f75cb0c617 @fidothe fidothe committed May 24, 2012
Showing with 43 additions and 5 deletions.
  1. +12 −4 make_mozilla/events/models.py
  2. +31 −1 make_mozilla/events/tests/test_models.py
@@ -99,13 +99,21 @@ def verify_ownership(self, user):
return user.email == self.organiser_email
@classmethod
- def upcoming(self, sort='start', include_private=False):
- return _upcoming(self.objects, sort, include_private)
+ def upcoming(cls, sort='start', include_private=False):
+ return _upcoming(cls.objects, sort, include_private)
@classmethod
- def near(self, latitude, longitude, sort='start', include_private=False):
+ def near(cls, latitude, longitude, sort='start', include_private=False):
point = geos.Point(float(longitude), float(latitude))
- return _upcoming(self.objects, sort, include_private).filter(venue__location__distance_lte=(point, measure.D(mi=20)))
+ return _upcoming(cls.objects, sort, include_private).filter(venue__location__distance_lte=(point, measure.D(mi=20)))
+
+ @classmethod
+ def all_user_non_bsd(cls, user):
+ return cls.objects.filter(organiser_email = user.email).exclude(source_id__startswith = 'bsd').order_by('start')
+
+ @classmethod
+ def all_user_bsd(cls, user):
+ return cls.objects.filter(organiser_email = user.email, source_id__startswith = 'bsd').order_by('start')
class EventAndVenueUpdater(object):
@classmethod
@@ -40,7 +40,7 @@ def test_lat_lng_can_be_set_on_instantiation(self):
eq_(venue.location, geos.Point(4.0, 51.0))
-class EventTest(django.test.TestCase):
+class EventTestHelperMixin(object):
def add_event(self, name, venue, offset, public = True, verified = True):
start = datetime.datetime.now() + datetime.timedelta(days = offset)
end = start + datetime.timedelta(hours = 3)
@@ -49,6 +49,12 @@ def add_event(self, name, venue, offset, public = True, verified = True):
e.save()
return e
+ def add_bsd_event(self, name, venue, offset, bsd_id):
+ e = self.add_event(name, venue, offset)
+ e.source_id = 'bsd:%s' % bsd_id
+ e.save()
+ return e
+
def setup_events(self):
london = models.Venue(name = "Test Venue", street_address = "0 Somewhere St",
country = "GB")
@@ -70,6 +76,9 @@ def setup_events(self):
return (e1, e2, e3, ep)
+
+
+class EventTest(django.test.TestCase, EventTestHelperMixin):
def test_upcoming_public_events_can_be_retrieved(self):
(e1, e2, e3, ep) = self.setup_events()
actual = models.Event.upcoming()
@@ -102,6 +111,27 @@ def test_that_an_event_can_verify_a_user_is_not_its_creator(self):
user = auth_models.User(email = 'boz@example.com')
assert not e.verify_ownership(user)
+class UserEventListTest(django.test.TestCase, EventTestHelperMixin):
+ def setUp(self):
+ berlin = models.Venue(name = "Berlin test Venue", street_address = "Somewhere Str. 0",
+ country = "DE")
+ berlin.latitude = 52.50693980
+ berlin.longitude = 13.42415920
+ berlin.save()
+ self.user = Mock()
+ self.user.email = 'moz@example.com'
+ self.e1 = self.add_event("E1", berlin, 3)
+ self.e2 = self.add_event("E2", berlin, 2)
+ self.e3 = self.add_bsd_event("E3", berlin, 1, 'jjj')
+
+ def test_that_all_a_users_non_bsd_events_can_be_fetched(self):
+ actual = models.Event.all_user_non_bsd(self.user)
+ eq_([x.name for x in actual], ["E2", "E1"])
+
+ def test_that_all_a_users_bsd_events_can_be_fetched(self):
+ actual = models.Event.all_user_bsd(self.user)
+ eq_([x.name for x in actual], ["E3"])
+
class TestEventAndVenueUpdater(unittest.TestCase):
def test_that_identical_model_instances_can_be_compared_properly(self):
e1 = models.Event(id = 1, name = "Hallo")

0 comments on commit 7aff8be

Please sign in to comment.