Beispiel #1
0
def domain_stations():
    station1 = Station(code='MEX',
                       timezone=pytz.timezone('America/Mexico_City'))
    station2 = Station(code='GDL',
                       timezone=pytz.timezone('America/Mexico_City'))
    station3 = Station(code='JFK', timezone=pytz.timezone('America/New_York'))
    station4 = Station(code='MAD', timezone=pytz.timezone('Europe/Madrid'))
    return [station1, station2, station3, station4]
def test_serialize_domain_station():
    timezone = pytz.timezone('America/Mexico_City')
    station = Station(code='MEX', timezone=timezone, viaticum=None)
    expected_json = '{"__class__": "Station", "__args__": [], "__kw__": {"code": "MEX", "continent": ' \
                    '"America", "tz_city": "Mexico_City", "viaticum": null}} '
    json_station = json.dumps(station, cls=ser.StationJsonEncoder)
    assert json.loads(json_station) == json.loads(expected_json)
Beispiel #3
0
def test_station_model_from_dict():
    station_dict = {'code': 'station_mex', 'continent': 'America', 'tz_city': 'Mexico_City', 'viaticum': None}
    station = Station.from_dict(station_dict)
    assert station.code == 'station_mex'
    assert station.continent == 'America'
    assert station.tz_city == 'Mexico_City'
    assert station.viaticum is None
    assert station.timezone == pytz.timezone('America/Mexico_City')
Beispiel #4
0
    def list(self, filters: dict = None):
        result = [Station.from_dict(a) for a in self.data]

        if filters is None:
            return result
        if 'continent__eq' in filters:
            result = [
                station for station in result
                if station.continent == filters['continent__eq']
            ]
        if 'codes_list' in filters:
            result = [
                station for station in result
                if station.code in filters['codes_list']
            ]
        if 'tz_city__eq' in filters:
            result = [
                station for station in result
                if station.tz_city in filters['tz_city__eq']
            ]

        return result
Beispiel #5
0
def test_station_is_singleton(domain_stations):
    station_mex = domain_stations[0]
    station_dict = {'code': 'MEX', 'continent': 'America', 'tz_city': 'Mexico_City', 'viaticum': None}
    station = Station.from_dict(station_dict)
    assert station is station_mex
Beispiel #6
0
def test_station_model_to_dict(station_dicts):
    station_dict = station_dicts[0]
    station = Station.from_dict(station_dict)
    assert station.to_dict() == station_dict
Beispiel #7
0
def domain_stations(station_dicts):
    return [Station.from_dict(a_dict=a_dict) for a_dict in station_dicts]
Beispiel #8
0
def test_repository_list_without_parameters(station_dicts):
    repo = memrepo.MemRepo(station_dicts)

    stations = [Station.from_dict(a) for a in station_dicts]

    assert repo.list() == stations