예제 #1
0
    def test_rsvp_routes(self):
        org = OrganizationFactory(name=u"Code for San Francisco")
        another_org = OrganizationFactory(type=u'Code for All')
        awesome_event = EventFactory(name=u'Awesome event')
        sad_event = EventFactory(name=u'Sad event', description=u'sad stuff will happen')

        awesome_event.organization = org
        sad_event.organization = another_org

        db.session.commit()

        # Make sure total number rsvps is 2468
        response = self.app.get('/api/events/rsvps')
        response = json.loads(response.data)
        self.assertEqual(response["total"], 2468)

        # Make sure org number rsvps is 1234
        response = self.app.get('/api/organizations/Code-for-San-Francisco/events/rsvps')
        response = json.loads(response.data)
        self.assertEqual(response["total"], 1234)
예제 #2
0
    def test_events_query_filter(self):
        org = OrganizationFactory(type=u'Brigade')
        another_org = OrganizationFactory(type=u'Code for All')
        awesome_event = EventFactory(name=u'Awesome event')
        sad_event = EventFactory(name=u'Sad event', description=u'sad stuff will happen')

        awesome_event.organization = org
        sad_event.organization = another_org

        db.session.commit()

        # Make sure total number of stories is 2
        response = self.app.get('/api/events')
        response = json.loads(response.data)
        self.assertEqual(response['total'], 2)

        # Filter by name should return only 1
        response = self.app.get('/api/events?name=awesome')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['name'], u'Awesome event')

        # Filter by description should return only 1
        response = self.app.get('/api/events?description=sad%20stuff')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['name'], u'Sad event')

        # Filter by deep searching organization type should return 1
        response = self.app.get('/api/events?organization_type=brigade')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['name'], u'Awesome event')