def test_get_ladders_when_not_a_player_in_any_ladder(self): with patch.object(self.manager.dao, "get_ladders", return_value=[ fixtures.ladder(1, "Ladder 1", date.today(), date.today(), False), fixtures.ladder(2, "Ladder 2", date.today(), date.today(), False), ]): with patch.object(self.manager.dao, "get_users_ladder_ids", return_value=[]): ladders = self.manager.get_ladders() self.assertEqual(2, len(ladders)) self.assertEqual(1, ladders[0].ladder_id) self.assertFalse(ladders[0].logged_in_user_has_joined) self.assertEqual(2, ladders[1].ladder_id) self.assertFalse(ladders[1].logged_in_user_has_joined)
def test_get_ladders_when_not_logged_in_should_return_all_with_all_false_flags(self): with patch.object(self.manager.dao, "get_ladders", return_value=[ fixtures.ladder(1, "Ladder 1", date.today(), date.today(), False), fixtures.ladder(2, "Ladder 2", date.today(), date.today(), False), ]): self.manager.user = None ladders = self.manager.get_ladders() self.assertEqual(2, len(ladders)) self.assertEqual(1, ladders[0].ladder_id) self.assertFalse(ladders[0].logged_in_user_has_joined) self.assertEqual(2, ladders[1].ladder_id) self.assertFalse(ladders[1].logged_in_user_has_joined)
def test_get_ladders_when_in_a_ladder_should_put_your_ladder_at_the_top_and_have_true_flag(self): with patch.object(self.manager.dao, "get_ladders", return_value=[ fixtures.ladder(1, "Ladder 1", date.today(), date.today(), False), fixtures.ladder(2, "Ladder 2", date.today(), date.today(), False), ]): with patch.object(self.manager.dao, "get_users_ladder_ids", return_value=[2]): self.manager.user = User("TEST1", "User", "*****@*****.**", "555-555-5555", "user.jpg", "availability", False) ladders = self.manager.get_ladders() self.assertEqual(2, len(ladders)) self.assertEqual(2, ladders[0].ladder_id) self.assertTrue(ladders[0].logged_in_user_has_joined) self.assertEqual(1, ladders[1].ladder_id) self.assertFalse(ladders[1].logged_in_user_has_joined)
def test_add_player_to_ladder_with_a_code_when_no_code_is_required_should_create_player(self): with patch.object(self.manager.dao, "get_ladder", return_value=fixtures.ladder()): with patch.object(self.manager.dao, "get_ladder_code", return_value=None): with patch.object(self.manager.dao, "create_player") as create_player_mock: with patch.object(self.manager.dao, "get_players", return_value=[]): self.manager.add_player_to_ladder(2, "bad") create_player_mock.assert_called_once()
def test_add_player_to_ladder_with_a_valid_code_should_create_player_and_return_all_ladder_players(self): with patch.object(self.manager.dao, "get_ladder", return_value=fixtures.ladder()): with patch.object(self.manager.dao, "get_ladder_code", return_value="good"): with patch.object(self.manager.dao, "create_player") as create_player_mock: with patch.object(self.manager.dao, "get_players", return_value=[fixtures.player()]) as get_players_mock: players = self.manager.add_player_to_ladder(1, "good") create_player_mock.assert_called_once_with(1, self.manager.user.user_id) get_players_mock.assert_called_once_with(1) self.assertEqual(1, len(players))
def pre_open_ladder(weeks_for_borrowed_points=0): return fixtures.ladder(start_date=date.today() + timedelta(days=1), end_date=date.today() + timedelta(days=2), weeks_for_borrowed_points=weeks_for_borrowed_points)
def open_ladder(distance_penalty_on=False): return fixtures.ladder(start_date=date.today() - timedelta(days=1), end_date=date.today() + timedelta(days=1), distance_penalty_on=distance_penalty_on)
def test_report_match_after_the_ladder_is_closed(self): with patch.object(self.manager.dao, "get_ladder", return_value=fixtures.ladder(start_date=date.today() - timedelta(days=2), end_date=date.today() - timedelta(days=1))): self.assert_error(lambda: self.manager.report_match(1, create_match_dict("TEST0", "TEST0", 0, 0, 0, 0)), 400, "This ladder is not currently open. You can only report matches between the ladder's start and end dates")
def test_add_player_to_ladder_with_a_bad_code(self): with patch.object(self.manager.dao, "get_ladder", return_value=fixtures.ladder()): with patch.object(self.manager.dao, "get_ladder_code", return_value="good"): self.assert_error(lambda: self.manager.add_player_to_ladder(1, "bad"), 400, "The code provided does not match the code of the ladder. If you believe this in error, please contact the ladder's sponsor.")