def test_twoDates(self): """ Asserts if a page visit on two different dates get added as individual items to the returned dictionary """ # create test and validation data data = [ (mkTime("2020-11-01T11:00:00+01:00"), "1"), (mkTime("2020-11-01T11:05:00+01:00"), "1"), # day 1, 5 min for page 1 (mkTime("2020-11-02T11:00:00+01:00"), "1"), (mkTime("2020-11-02T11:05:00+01:00"), "1" ) # day 2, 5 min for page 1 ] assertDict = { "1": { dt.date(2020, 11, 1): (data[1][0] - data[0][0], 1), dt.date(2020, 11, 2): (data[3][0] - data[2][0], 1) } } # test function history = dict() history = analyseTimeOnPage.dataCrawler(data, history) self.assertEqual(history, assertDict)
def test_singleDateTwoVisits(self): """ Asserts if a page visit on the same date gets correclty summed in the returned dictionary """ # create test and validation data data = [ (mkTime("2020-11-01T11:00:00+01:00"), "1"), (mkTime("2020-11-01T11:05:00+01:00"), "1"), # day 1, 5 min for page 1 (mkTime("2020-11-01T16:00:00+01:00"), "1"), (mkTime("2020-11-01T16:05:00+01:00"), "1" ) # day 1, 5 min for page 1 in second visit ] assertDict = { "1": { dt.date(2020, 11, 1): ((data[1][0] - data[0][0]) + (data[3][0] - data[2][0]), 2) } } # test function history = dict() history = analyseTimeOnPage.dataCrawler(data, history) self.assertEqual(history, assertDict)
def test_singleDataEntry(self): """ Asserts that a single timestamp gets ignored, as at least 2 are nessecary to determine duration """ # create test and validation data data = [(mkTime("2020-11-01T11:00:00+01:00"), "1")] assertDict = {} # test function history = dict() history = analyseTimeOnPage.dataCrawler(data, history) self.assertEqual(history, assertDict)
def test_nonDestructiveOpsNone(self): """ Asserts that a non empty dictionary getting passed as the 2nd argument returns unaltered when 1st argument is empty """ # create test and validation data data = [] assertDict = {"1": {dt.date(2020, 11, 1): (dt.time(0, 30, 0), 1)}} # test function history = {"1": {dt.date(2020, 11, 1): (dt.time(0, 30, 0), 1)}} history = analyseTimeOnPage.dataCrawler(data, history) self.assertEqual(history, assertDict)
def test_maxTimeElapsed(self): """ Asserts that timestamps beyond max_time do not get added """ # create test and validation data data = [(mkTime("2020-11-01T11:00:00+01:00"), "1"), (mkTime("2020-11-01T12:30:00+01:00"), "1")] assertDict = {} # test function history = dict() history = analyseTimeOnPage.dataCrawler(data, history) self.assertEqual(history, assertDict)
def test_simpleTest(self): """ Asserts if a single visit gets properly added """ # create test and validation data data = [(mkTime("2020-11-01T11:00:00+01:00"), "1"), (mkTime("2020-11-01T11:05:00+01:00"), "1") ] # day 1, 5 min for page 1 assertDict = { "1": { dt.date(2020, 11, 1): (data[1][0] - data[0][0], 1) } } # test function history = dict() history = analyseTimeOnPage.dataCrawler(data, history) self.assertEqual(history, assertDict)
def test_nonDestructiveOpsAddition(self): """ Asserts that a non empty dictionary retains pre-existing data when additional data gets added: (duration, count) tuple should get increased """ # create test and validation data data = [(mkTime("2020-11-01T11:00:00+01:00"), "1"), (mkTime("2020-11-01T11:05:00+01:00"), "1")] assertDict = { "1": { dt.date(2020, 11, 1): (dt.timedelta(seconds=300) + (data[1][0] - data[0][0]), 2) } } # test function history = {"1": {dt.date(2020, 11, 1): (dt.timedelta(seconds=300), 1)}} history = analyseTimeOnPage.dataCrawler(data, history) self.assertEqual(history, assertDict)
def test_nonDestructiveOpsTwoCourses(self): """ Asserts that a non empty dictionary retains pre-existing data when additional data gets added: new pageID key and dict() entry should be added """ # create test and validation data data = [(mkTime("2020-11-02T11:00:00+01:00"), "2"), (mkTime("2020-11-02T11:05:00+01:00"), "2")] assertDict = { "1": { dt.date(2020, 11, 1): (dt.timedelta(seconds=300), 1) }, "2": { dt.date(2020, 11, 2): (data[1][0] - data[0][0], 1) } } # test function history = {"1": {dt.date(2020, 11, 1): (dt.timedelta(seconds=300), 1)}} history = analyseTimeOnPage.dataCrawler(data, history) self.assertEqual(history, assertDict)