def test_get_all_increases(self): # Set Up old_date = datetime.strptime("1996-03-15", CSVUtils.DATE_FORMAT) self.target.put_increase_for_candidate('test1', 1000, old_date) self.target.put_increase_for_candidate('test2', 2400, old_date) new_date = datetime.strptime("1901-05-25", CSVUtils.DATE_FORMAT) self.target.put_increase_for_candidate('test1', 3000, new_date) self.target.put_increase_for_candidate('test2', 4000, new_date) # New test increases = self.target.get_all_increases() assert len(increases) == 2 test1_increases = increases[0] assert len(test1_increases) == 3 assert test1_increases['date'] == DateUtils.date_to_timestamp(old_date.date()) assert test1_increases['test1'] == 1000 assert test1_increases['test2'] == 2400 test2_increases = increases[1] assert len(test2_increases) == 3 assert test2_increases['date'] == DateUtils.date_to_timestamp(new_date.date()) assert test2_increases['test1'] == 3000 assert test2_increases['test2'] == 4000
def __make_date_dict(key, value): """ Create a dictionary adding first entry {'date': key} and flatten value, which is a map. """ dictionary = {'date': DateUtils.date_to_timestamp(key)} for screen_name, count in value.items(): dictionary[screen_name] = count return dictionary