Пример #1
0
    def testWrite_SingleCountBadDataFails(self):
        def test_db_empty():
            query = SessionFactory.for_schema_base(JailsBase).query(
                SingleCountAggregate)
            self.assertEqual(query.all(), [])

        with self.assertRaises(ValueError):
            store_single_count(SingleCount(count=311), '1001001')
        test_db_empty()

        with self.assertRaises(EnumParsingError):
            store_single_count(
                SingleCount(count=311, ethnicity='Not an Ethnicity'),
                '01001001')
        test_db_empty()

        with self.assertRaises(EnumParsingError):
            store_single_count(SingleCount(count=311, gender='Not a Gender'),
                               '01001001')
        test_db_empty()

        with self.assertRaises(EnumParsingError):
            store_single_count(SingleCount(count=311, race='Not a Race'),
                               '01001001')
        test_db_empty()

        with self.assertRaises(ValueError):
            store_single_count(SingleCount(count=311, date='Not a date'),
                               '01001001')
        test_db_empty()
Пример #2
0
    def testWrite_SingleCountBadDataFails(self):
        def test_db_empty():
            with SessionFactory.using_database(self.database_key,
                                               autocommit=False) as session:
                query = session.query(SingleCountAggregate)
                self.assertEqual(query.all(), [])

        with self.assertRaises(ValueError):
            store_single_count(SingleCount(count=311), "1001001")
        test_db_empty()

        with self.assertRaises(EnumParsingError):
            store_single_count(
                SingleCount(count=311, ethnicity="Not an Ethnicity"),
                "01001001")
        test_db_empty()

        with self.assertRaises(EnumParsingError):
            store_single_count(SingleCount(count=311, gender="Not a Gender"),
                               "01001001")
        test_db_empty()

        with self.assertRaises(EnumParsingError):
            store_single_count(SingleCount(count=311, race="Not a Race"),
                               "01001001")
        test_db_empty()

        with self.assertRaises(ValueError):
            store_single_count(SingleCount(count=311, date="Not a date"),
                               "01001001")
        test_db_empty()
Пример #3
0
def store_single_count_endpoint():
    """Endpoint to store a single count"""

    jid = get_str_param_value('jid', request.args)
    ethnicity = get_str_param_value('ethnicity', request.args)
    gender = get_str_param_value('gender', request.args)
    race = get_str_param_value('race', request.args)
    count = get_str_param_value('count', request.args)
    date = get_str_param_value('date', request.args)
    sc = SingleCount(
        count=count,
        ethnicity=ethnicity,
        gender=gender,
        race=race,
        date=date,
    )
    stored = store_single_count(sc, jid)

    if stored:
        logging.info("Stored [%d] as [%s] for [%s]", count,
                     ' '.join(filter(None, (race, gender, ethnicity))), jid)
        return '', HTTPStatus.OK

    logging.error("Failed to store single count for [%s]", jid)
    return '', HTTPStatus.INTERNAL_SERVER_ERROR
Пример #4
0
    def testWrite_SingleCountWithDate(self):
        store_single_count(SingleCount(count=_COUNT, date=_TODAY), '01001001')

        query = SessionFactory.for_schema_base(JailsBase).query(
            SingleCountAggregate)
        result = one(query.all())

        self.assertEqual(result.jid, _JID)
        self.assertEqual(result.count, _COUNT)
        self.assertEqual(result.date, _TODAY)
Пример #5
0
    def testWrite_SingleCountWithRace(self):
        store_single_count(SingleCount(count=_COUNT, race=Race.ASIAN),
                           '01001001')

        query = SessionFactory.for_schema_base(JailsBase).query(
            SingleCountAggregate)
        result = one(query.all())

        self.assertEqual(result.jid, _JID)
        self.assertEqual(result.count, _COUNT)
        self.assertEqual(Race(result.race), Race.ASIAN)
Пример #6
0
    def testWrite_SingleCountWithGender(self):
        store_single_count(SingleCount(count=_COUNT, gender=Gender.FEMALE),
                           '01001001')

        query = SessionFactory.for_schema_base(JailsBase).query(
            SingleCountAggregate)
        result = one(query.all())

        self.assertEqual(result.jid, _JID)
        self.assertEqual(result.count, _COUNT)
        self.assertEqual(Gender(result.gender), Gender.FEMALE)
Пример #7
0
    def testWrite_SingleCountWithDate(self):
        store_single_count(SingleCount(count=_COUNT, date=_TODAY), "01001001")

        with SessionFactory.using_database(self.database_key,
                                           autocommit=False) as session:
            query = session.query(SingleCountAggregate)
            result = one(query.all())

        self.assertEqual(result.jid, _JID)
        self.assertEqual(result.count, _COUNT)
        self.assertEqual(result.date, _TODAY)
Пример #8
0
    def testWrite_SingleCountWithEthnicity(self):
        store_single_count(
            SingleCount(count=_COUNT, ethnicity=Ethnicity.HISPANIC),
            '01001001')

        query = SessionFactory.for_schema_base(JailsBase).query(
            SingleCountAggregate)
        result = one(query.all())

        self.assertEqual(result.jid, _JID)
        self.assertEqual(result.count, _COUNT)
        self.assertEqual(Ethnicity(result.ethnicity), Ethnicity.HISPANIC)
Пример #9
0
    def testWrite_SingleCountWithGender(self):
        store_single_count(SingleCount(count=_COUNT, gender=Gender.FEMALE),
                           "01001001")

        with SessionFactory.using_database(self.database_key,
                                           autocommit=False) as session:
            query = session.query(SingleCountAggregate)
            result = one(query.all())

        self.assertEqual(result.jid, _JID)
        self.assertEqual(result.count, _COUNT)
        self.assertEqual(Gender(result.gender), Gender.FEMALE)
Пример #10
0
    def testWrite_SingleCountWithEthnicity(self):
        store_single_count(
            SingleCount(count=_COUNT, ethnicity=Ethnicity.HISPANIC),
            "01001001")

        with SessionFactory.using_database(self.database_key,
                                           autocommit=False) as session:
            query = session.query(SingleCountAggregate)
            result = one(query.all())

        self.assertEqual(result.jid, _JID)
        self.assertEqual(result.count, _COUNT)
        self.assertEqual(Ethnicity(result.ethnicity), Ethnicity.HISPANIC)