def test_constructValidTrafficReading_directionRLeft_directionLeftToRightFalse( self): test_data = ["2020-05-25", "17:34:12", "35.87", "R-Left", "class-2-1"] result = constructValidatedTrafficReading( test_data, STATION_A_ROAD_POSITION_STRING, TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-05-25,17:34:12,35.87,R-Left,class-2-1") self.assertEqual(result.validationLevel, ValidationLevel.FULL) self.assertEqual(result.directionLeftToRight, False)
def test_constructValidTrafficReading_subclassInvalidForClass_constructReadingWithInvalidDataValidationLevel( self): test_data = ["2020-05-25", "17:34:12", "35.87", "L-Right", "class-3-4"] result = constructValidatedTrafficReading( test_data, STATION_A_ROAD_POSITION_STRING, TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-05-25,17:34:12,35.87,L-Right,class-3-4") self.assertEqual(result.validationLevel, ValidationLevel.INVALID_DATA) #As the data has a valid format, it should still be populated, even if its value is invalid. self.assertEqual(result.vehicleClass, VehicleClass(main=3, sub=4))
def test_constructValidTrafficReading_stationNotInDatabase_constructReadingWithInvalidDataValidationLevel( self): test_data = ["2020-05-25", "17:34:12", "35.87", "L-Right", "class-2-1"] result = constructValidatedTrafficReading( test_data, STATION_C_ROAD_POSITION_STRING, TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-05-25,17:34:12,35.87,L-Right,class-2-1") self.assertEqual(result.validationLevel, ValidationLevel.INVALID_DATA) #As the data has a valid format, it should still be populated, even if its value is invalid. self.assertEqual(result.sourceRoadPosition, STATION_C_ROAD_POSITION)
def test_constructValidTrafficReading_roadPositionHasNoSideSuffix_dataStillValid( self): test_data = [ "2020-05-25", "17:34:12", "35.87", "Right-to-Left", "class-2-1" ] result = constructValidatedTrafficReading( test_data, STATION_B_ROAD_POSITION_STRING, TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-05-25,17:34:12,35.87,Right-to-Left,class-2-1") self.assertEqual(result.validationLevel, ValidationLevel.FULL) self.assertEqual(result.sourceRoadPosition, STATION_B_ROAD_POSITION)
def test_constructValidTrafficReading_speedIsNaN_constructReadingWithInvalidDataValidationLevel( self): test_data = ["2020-05-25", "17:34:12", "NaN", "L-Right", "class-2-1"] result = constructValidatedTrafficReading( test_data, STATION_A_ROAD_POSITION_STRING, TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-05-25,17:34:12,NaN,L-Right,class-2-1") self.assertEqual(result.validationLevel, ValidationLevel.INVALID_DATA) #As the data has a valid format, it should still be populated, even if its value is invalid. self.assertTrue( math.isnan(result.speed), "result.speed should be nan, but is " + str(result.speed) + ".")
def test_constructValidTrafficReading_dateAfterValidationDate_constructReadingWithInvalidDataValidationLevel( self): test_data = ["2020-11-25", "17:34:12", "35.87", "L-Right", "class-2-1"] result = constructValidatedTrafficReading( test_data, STATION_A_ROAD_POSITION_STRING, TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-11-25,17:34:12,35.87,L-Right,class-2-1") self.assertEqual(result.validationLevel, ValidationLevel.INVALID_DATA) #As the data has a valid format, it should still be populated, even if its value is invalid. self.assertEqual( result.dateTime, datetime.strptime("2020-11-25 17:34:12", "%Y-%m-%d %H:%M:%S"))
def test_constructValidTrafficReading_speedExceedsMax_constructReadingWithInvalidDataValidationLevel( self): test_data = [ "2020-05-25", "17:34:12", "229.17", "L-Right", "class-2-1", "sdkfjb.nsdkjf.stationA" ] result = constructValidatedTrafficReading( test_data, STATION_A_ROAD_POSITION_STRING, TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-05-25,17:34:12,229.17,L-Right,class-2-1") self.assertEqual(result.validationLevel, ValidationLevel.INVALID_DATA) #As the data has a valid format, it should still be populated, even if its value is invalid. self.assertEqual(result.speed, 229.17)
def test_constructValidatedTrafficReading_allDataValid_constructCorrectReadingWithFullValidationLevel( self): test_data = ["2020-05-25", "17:34:12", "35.87", "L-Right", "class-2-1"] result = constructValidatedTrafficReading( test_data, STATION_A_ROAD_POSITION_STRING, TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-05-25,17:34:12,35.87,L-Right,class-2-1") self.assertEqual(result.validationLevel, ValidationLevel.FULL) self.assertEqual( result.dateTime, datetime.strptime("2020-05-25 17:34:12", "%Y-%m-%d %H:%M:%S")) self.assertEqual(result.speed, 35.87) self.assertEqual(result.directionLeftToRight, True) self.assertEqual(result.vehicleClass, VehicleClass(main=2, sub=1)) self.assertEqual(result.sourceRoadPosition, STATION_A_ROAD_POSITION)
def test_constructValidTrafficReading_invalidTimeFormat_constructReadingWithInvalidFormatValidationLevel( self): test_data = ["2020-05-25", "17:34:70", "35.87", "L-Right", "class-2-1"] result = constructValidatedTrafficReading( test_data, STATION_A_ROAD_POSITION_STRING, TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-05-25,17:34:70,35.87,L-Right,class-2-1") self.assertEqual(result.validationLevel, ValidationLevel.INVALID_FORMAT) self.assertIsNone(result.dateTime) #The other, valid, fields should still be populated. self.assertEqual(result.speed, 35.87) self.assertEqual(result.directionLeftToRight, True) self.assertEqual(result.vehicleClass, VehicleClass(main=2, sub=1)) self.assertEqual(result.sourceRoadPosition, STATION_A_ROAD_POSITION)
def test_constructValidTrafficReading_invalidSourceRoadPosition_constructReadingWithInvalidFormatValidationLevel( self): test_data = ["2020-05-25", "17:34:12", "35.87", "L-Right", "class-2-1"] result = constructValidatedTrafficReading( test_data, "completely and utterly invalid", TEST_VALIDATION_DATE_TIMESTAMP) self.assertEqual(result.rawSourceData, "2020-05-25,17:34:12,35.87,L-Right,class-2-1") self.assertEqual(result.validationLevel, ValidationLevel.INVALID_FORMAT) self.assertIsNone(result.sourceRoadPosition) #The other, valid, fields should still be populated. self.assertEqual( result.dateTime, datetime.strptime("2020-05-25 17:34:12", "%Y-%m-%d %H:%M:%S")) self.assertEqual(result.speed, 35.87) self.assertEqual(result.directionLeftToRight, True) self.assertEqual(result.vehicleClass, VehicleClass(main=2, sub=1))