def get(self, page): """Cases per city list paginated""" response = city_services.get_city_cases(page) if not response.get('cases'): abort(404, "No cases found for this page") return response
def test_city_cases_paginated_return_cases_without_restrained_cities(self): City().save(self.db.session, id=1, city='NÃO ESPECIFICADA', ibge_id=1, country='Country1', state_id=1, totalcases=10, deaths=1) City().save(self.db.session, id=2, city='FORA DO ESTADO', ibge_id=2, country='Country1', state_id=1, totalcases=10, deaths=1) City().save(self.db.session, id=3, city='ESTRANGEIRO', ibge_id=3, country='Country1', state_id=1, totalcases=10, deaths=1) City().save(self.db.session, id=4, city='c1', ibge_id=4, country='Country1', state_id=1, totalcases=20, deaths=1) self.db.session.commit() response = city_services.get_city_cases(1) self.assertEqual(len(response.get('cases')), 1) self.assertEqual( response, { 'cases': [{ 'city': 'c1', 'ibge_id': 4, 'id': 4, 'country': 'Country1', 'deaths': 1, 'state_id': 1, 'totalcases': 20 }], 'pagination': { 'current_page': 1, 'has_next': False, 'has_previous': False, 'next_page': None, 'total_pages': 1 } })
def test_city_cases_return_cases_with_pagination(self): City().save(self.db.session, id=1, city='c1', ibge_id=1, country='Country1', state_id=1, totalcases=10, deaths=1) City().save(self.db.session, id=2, city='c2', ibge_id=2, country='Country1', state_id=1, totalcases=20, deaths=1) self.db.session.commit() response = city_services.get_city_cases(1) self.assertEqual(len(response.get('cases')), 2) self.assertEqual( response, { 'cases': [{ 'city': 'c1', 'ibge_id': 1, 'id': 1, 'country': 'Country1', 'deaths': 1, 'state_id': 1, 'totalcases': 10 }, { 'city': 'c2', 'ibge_id': 2, 'id': 2, 'country': 'Country1', 'deaths': 1, 'state_id': 1, 'totalcases': 20 }], 'pagination': { 'current_page': 1, 'has_next': False, 'has_previous': False, 'next_page': None, 'total_pages': 1 } })
def test_city_cases_return_all_cases_without_pagination(self): City().save(self.db.session, id=1, city='c1', ibge_id=1, country='Country1', state_id=1, totalcases=10, deaths=1) City().save(self.db.session, id=2, city='c2', ibge_id=2, country='Country1', state_id=1, totalcases=20, deaths=1) self.db.session.commit() response = city_services.get_city_cases(None) self.assertEqual(len(response.get('cases')), 2) self.assertEqual( response, { 'cases': [{ 'city': 'c1', 'ibge_id': 1, 'id': 1, 'country': 'Country1', 'deaths': 1, 'state_id': 1, 'totalcases': 10 }, { 'city': 'c2', 'ibge_id': 2, 'id': 2, 'country': 'Country1', 'state_id': 1, 'deaths': 1, 'totalcases': 20 }], 'pagination': {} })
def get(self): """Cases per city list""" response = city_services.get_city_cases(None) if not response.get('cases'): abort(404, "No cases found") return response