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()
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()
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
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)
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)
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)
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)
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)
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)
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)