Ejemplo n.º 1
0
    def test_none_location(self):
        # TODO this isn't about Syria, move it somewhere else
        counts = get_filter_counts(self.session, location_ids=['NULL'])
        self.assertGreater(len(counts), 1000)

        self.assertEqual(
            counts, get_filter_counts(self.session, location_ids=['null']))
        self.assertEqual(counts,
                         get_filter_counts(self.session, location_ids=[None]))

        counts2 = get_filter_counts(self.session, location_ids=['NULL', 1])
        self.assertGreater(len(counts2), len(counts))
Ejemplo n.º 2
0
 def test_filter_counts(self):
     f_c = get_filter_counts(self.session,
                             fromdate=self.start_date,
                             todate=self.plus_1_yr,
                             location_ids=self.syria_location_ids)
     # print(f_c)
     self.assertGreater(len(f_c), 1000)
Ejemplo n.º 3
0
    def test_none_specific_reported_figure_1(self):
        # TODO this isn't about Syria, move it somewhere else
        counts = get_filter_counts(self.session,
                                   specific_reported_figures=['NULL'])
        srf_counts = [
            c for c in counts if c['filter_type'] == 'specific_reported_figure'
        ]
        self.assertEqual(len(srf_counts), 1)
        self.assertTrue([c for c in srf_counts if c['value'] is None])

        self.assertEqual(
            counts,
            get_filter_counts(self.session,
                              specific_reported_figures=['null']))
        self.assertEqual(
            counts,
            get_filter_counts(self.session, specific_reported_figures=[None]))
Ejemplo n.º 4
0
 def test_specific_reported_figure(self):
     # TODO this isn't about Syria, move it somewhere else
     counts = get_filter_counts(self.session,
                                specific_reported_figures=[1, 1000])
     srf_counts = [
         c for c in counts if c['filter_type'] == 'specific_reported_figure'
     ]
     self.assertGreater(len(srf_counts), 2)
     self.assertFalse([c for c in srf_counts if c['value'] is None])
     self.assertTrue([c for c in srf_counts if c['value'] == 1])
Ejemplo n.º 5
0
def filters():
    session = Session()
    try:
        data = request.get_json(silent=True) or request.form
        filters = filter_params(data)
        result = get_filter_counts(session, **filters)
        resp = jsonify(result)
        resp.status_code = 200
        return resp
    finally:
        session.close()
Ejemplo n.º 6
0
 def test_filter_counts_speed(self):
     for end_date in (self.plus_1_mo, self.plus_3_mo, self.plus_6_mo):
         # Adding this usually fails: , self.plus_1_yr):
         t0 = time.time()
         f_c = get_filter_counts(self.session,
                                 fromdate=self.start_date,
                                 todate=end_date,
                                 location_ids=self.syria_location_ids)
         t1 = time.time()
         print('{} - {}: {}s'.format(self.start_date, end_date, t1 - t0))
         self.assertLess(
             t1 - t0, 1.0,
             'Calculating filter counts {} - {} took too long'.format(
                 self.start_date, end_date))