Exemplo n.º 1
0
def test_long_run_in_stack_returns_rundata():
    data = mock.mockdata['VALID_RUN'][0]
    stack = hdlr.DataValidHandler(
        hdlr.RunTypeHandler(
            hdlr.TreadmillHandler(
                hdlr.GarminDateHandler(
                    hdlr.ShortDistanceHandler(
                        hdlr.DefaultHandler(None))))))

    assert stack.handle(rundata=data) 
Exemplo n.º 2
0
def test_post_garmin_runs_through_chain_of_command():
    data = mock.mockdata['POST_GARMIN_RUN'][0]

    stack = hdlr.DataValidHandler(
        hdlr.RunTypeHandler(
            hdlr.DateConverter(
                hdlr.TreadmillHandler(
                    hdlr.GarminDateHandler(
                        hdlr.DefaultHandler(None))))))

    assert stack.handle(rundata=data) == data
Exemplo n.º 3
0
 def __init__(self):
     self.handler = hdlr.DataValidHandler(
         hdlr.RunTypeHandler(
             hdlr.DateConverter(
                 hdlr.TreadmillHandler(
                     hdlr.GarminDateHandler(
                         hdlr.ShortDistanceHandler(
                             hdlr.HouseMoveHandler(
                                 hdlr.FiveKMDateHandler(
                                     hdlr.LockdownHandler(
                                         hdlr.LongRunHandler(
                                             hdlr.DefaultHandler(
                                                 None)))))))))))
Exemplo n.º 4
0
def test_pvalid_run_in_stack_returns_adjusted_distance():
    data = mock.mockdata['VALID_RUN'][0]
    stack = hdlr.DataValidHandler(
        hdlr.RunTypeHandler(
            hdlr.TreadmillHandler(
                hdlr.GarminDateHandler(
                    hdlr.ShortDistanceHandler(
                        hdlr.HouseMoveHandler(
                            hdlr.LockdownHandler(
                                hdlr.LongRunHandler(
                                    hdlr.DefaultHandler(None)))))))))

    assert stack.handle(
        rundata=data)['distance'] == settings.SHORT_RUN_DISTANCE
    assert 'original_distance' in stack.handle(rundata=data).keys()
    assert stack.handle(
        rundata=data)['original_distance'] == data['distance']
Exemplo n.º 5
0
def test_pre_five_km_run_in_stack_returns_rundata():
    data = mock.mockdata['PRE_FIVEKM_RUN'][0]
    runmonth, runday, runyear = data['date'].split('/')
    run_date = datetime.datetime(int(runyear), int(runmonth), int(runday))
    data['adjusted_date'] = run_date

    stack = hdlr.DataValidHandler(
        hdlr.RunTypeHandler(
            hdlr.DateConverter(
                hdlr.TreadmillHandler(
                    hdlr.GarminDateHandler(
                        hdlr.ShortDistanceHandler(
                            hdlr.HouseMoveHandler(
                                hdlr.FiveKMDateHandler(
                                    hdlr.DefaultHandler(None)))))))))

    assert stack.handle(rundata=data)['distance'] == data['distance']
Exemplo n.º 6
0
def test_dateconverter_adds_adjusted_date_key(dateconverter):
    data = mock.mockdata['VALID_RUN'][0]

    stack = hdlr.DataValidHandler(
        hdlr.RunTypeHandler(
            hdlr.DateConverter(
                hdlr.TreadmillHandler(
                    hdlr.GarminDateHandler(
                        hdlr.ShortDistanceHandler(
                            hdlr.HouseMoveHandler(
                                hdlr.LockdownHandler(
                                    hdlr.LongRunHandler(
                                        hdlr.DefaultHandler(None))))))))))

    processed_data = stack.handle(rundata=data)
    assert 'adjusted_date' in processed_data.keys()
    assert processed_data['adjusted_date'] == datetime.datetime(2020, 2, 18, 0, 0)
Exemplo n.º 7
0
def test_pre_move_run_in_stack_returns_adjusted_distance():
    data = mock.mockdata['PRE_MOVE_RUN'][0]
    runmonth, runday, runyear = data['date'].split('/')
    run_date = datetime.datetime(int(runyear), int(runmonth), int(runday))
    data['adjusted_date'] = run_date
    
    stack = hdlr.DataValidHandler(
        hdlr.RunTypeHandler(
            hdlr.DateConverter(
                hdlr.TreadmillHandler(
                    hdlr.GarminDateHandler(
                        hdlr.ShortDistanceHandler(
                            hdlr.HouseMoveHandler(
                                hdlr.DefaultHandler(None))))))))

    assert stack.handle(
        rundata=data)['distance'] == settings.HOUSEMOVE_DISTANCE
    assert 'original_distance' in stack.handle(rundata=data).keys()
    assert stack.handle(
        rundata=data)['original_distance'] == data['distance']
Exemplo n.º 8
0
def defaulthandler():
    defaulthandler = hdlr.DefaultHandler(successor=None)
    
    return defaulthandler
Exemplo n.º 9
0
def test_giving_treadmil_to_data_valid_handler_passes_to_runtype_returns_true():
    data = mock.mockdata['TREADMILL_RUN'][0]
    handler = hdlr.DataValidHandler(
        successor=hdlr.RunTypeHandler(
            successor=hdlr.DefaultHandler(None)))
    assert handler.handle(rundata=data) == data