def setUp(self): chores.client = TrelloClient(None, None, mock.MagicMock()) inigo = Member('Inigo Montoya') wesley = Member('Wesley') buttercup = Member('Buttercup') members = [inigo, wesley, buttercup] list_inigo = List('Inigo - To Do') list_wesley = List('Wesley - To Do') list_buttercup = List('Buttercup - To Do') list_done = List('Done') lists = [list_inigo, list_wesley, list_buttercup, list_done] cards = [ Card(labels=[Label('Daily')]), Card(labels=[Label('Daily')]), Card(labels=[Label('Daily')]), Card(labels=[Label('Weekly')]), Card(labels=[Label('Weekly')]), Card([inigo.id], [Label('Daily')], 'Inigo\'s'), Card([wesley.id], [Label('Daily')]), Card([inigo.id, wesley.id], [Label('Twice Weekly')], 'Shared') ] for card in cards: card.list_id = list_done.id left_over = Card(labels=[Label('Weekly')]) left_over.list_id = list_inigo.id cards.append(left_over) self.board = Board(lists, cards, members)
class UpdateChoresTest(unittest.TestCase): def setUp(self): chores.client = TrelloClient(None, None, mock.MagicMock()) inigo = Member('Inigo Montoya') wesley = Member('Wesley') buttercup = Member('Buttercup') members = [inigo, wesley, buttercup] list_inigo = List('Inigo - To Do') list_wesley = List('Wesley - To Do') list_buttercup = List('Buttercup - To Do') list_done = List('Done') lists = [list_inigo, list_wesley, list_buttercup, list_done] cards = [ Card(labels=[Label('Daily')]), Card(labels=[Label('Daily')]), Card(labels=[Label('Daily')]), Card(labels=[Label('Weekly')]), Card(labels=[Label('Weekly')]), Card([inigo.id], [Label('Daily')], 'Inigo\'s'), Card([wesley.id], [Label('Daily')]), Card([inigo.id, wesley.id], [Label('Twice Weekly')], 'Shared') ] for card in cards: card.list_id = list_done.id left_over = Card(labels=[Label('Weekly')]) left_over.list_id = list_inigo.id cards.append(left_over) self.board = Board(lists, cards, members) @mock.patch('chorebot.chores.get_localzone') def test_daily_assigned(self, mock_get_localzone): """Daily chores are assigned each day, due by end of day.""" mock_get_localzone.return_value = pytz.utc now = datetime(2015, 7, 21, 3).replace(tzinfo=pytz.utc) # a Tuesday update_chores(self.board, now) list_done = self.board.obj_by_name('lists', 'Done') for card in self.board.cards: if has_label(card, 'Daily'): self.assertNotEqual(card.list_id, list_done.id) self.assertEqual(card.due.day, 21) @mock.patch('chorebot.chores.get_localzone') def test_bi_weekly_assigned(self, mock_get_localzone): """Bi-weekly chores are assigned Mon/Thu, due in 2 days.""" mock_get_localzone.return_value = pytz.utc now = datetime(2015, 7, 23, 3).replace(tzinfo=pytz.utc) # a Thursday update_chores(self.board, now) list_done = self.board.obj_by_name('lists', 'Done') for card in self.board.cards: if has_label(card, 'Twice Weekly'): self.assertNotEqual(card.list_id, list_done.id) self.assertEqual(card.due.day, 25) @mock.patch('chorebot.chores.get_localzone') def test_weekly_assigned(self, mock_get_localzone): """Weekly chores are assigned on Mon, due in 6 days.""" mock_get_localzone.return_value = pytz.utc now = datetime(2015, 7, 20, 3).replace(tzinfo=pytz.utc) # a Monday update_chores(self.board, now) list_done = self.board.obj_by_name('lists', 'Done') for card in self.board.cards: if has_label(card, 'Weekly'): self.assertNotEqual(card.list_id, list_done.id) self.assertEqual(card.due.day, 26) def test_single_member_assigned(self): now = datetime(2015, 7, 20, 3) # a Monday update_chores(self.board, now) card = self.board.obj_by_name('cards', 'Inigo\'s') list_inigo = self.board.obj_by_name('lists', 'Inigo - To Do') self.assertEqual(card.list_id, list_inigo.id) def test_multi_member_assigned(self): now = datetime(2015, 7, 20, 3) # a Monday update_chores(self.board, now) card = self.board.obj_by_name('cards', 'Shared') list_inigo = self.board.obj_by_name('lists', 'Inigo - To Do') list_wesley = self.board.obj_by_name('lists', 'Wesley - To Do') self.assertIn(card.list_id, [list_inigo.id, list_wesley.id])