def test_sign_up(self): RoomFactory(is_default=False) room = RoomFactory(is_default=True) res = self.post( '/api/auth/sign-up', { 'display': 'display', 'email': '*****@*****.**', 'rank': '3k', 'password': '******', 'recaptcha': 'PASS' }) self.assertEqual(res.code, 200) user = session.query(User).one() self.assertFalse(user.is_active) self.assertEqual(user.display, 'display') self.assertEqual(user.email, '*****@*****.**') self.assertEqual(user.rating, min_rating('3k')) self.assertTrue(user.check_password('pw')) self.assertIsNotNone(user.rating_data) self.assertEqual(user.rating_data.rating, min_rating('3k')) self.assertEqual(len(user.rooms), 1) self.assertEqual(user.rooms[0].room_id, room.id)
def _sign_up_rating(self, user, rank): rating = min_rating(rank) if rating < min_rating('20k') or rating > min_rating('3d'): raise HTTPError(400, 'invalid rank') user.rating = rating user.rating_data = Player(rating)
def test_rating_range(): tests = [[min_rating('5k'), 0, min_rating('5k'), max_rating('5k')], [min_rating('1d'), 2, min_rating('2k'), max_rating('3d')], [100, 0, 100, 199], [200, 2, -9999, 499], [2900, 3, 2600, 9999]] for t in tests: assert rating_range(t[0], t[1]) == (t[2], t[3])
def test_min_rating(): def test_in_order(start, ranks): for i, r in enumerate(ranks): assert min_rating(r) == start + i*RATING_PER_RANK test_in_order(100, ["20k", "19k", "18k", "17k", "16k", "15k", "14k", "13k", "12k", "11k", "10k", "9k", "8k", "7k", "6k", "5k", "4k", "3k", "2k", "1k"]) test_in_order(2100, ["1d", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d"]) assert min_rating("21k") == 100 assert min_rating("22k") == 100 assert min_rating("10d") == 2900 assert min_rating("11d") == 2900
def test_rank_diff(): tests = [ [-200, 100, 0], [-100, 100, 0], [0, 100, 0], [50, 100, 0], [90, 100, 0], [0, 0, 0], [0, 100, 0], [-200, 200, 1], [110, 200, 1], [150, 200, 1], [190, 200, 1], [200, 200, 0], [650, 350, 3], [min_rating("2k"), min_rating("3d"), 4], [2800, 3100, 1], ] for t in tests: assert rank_diff(t[0], t[1]) == t[2]
def test_in_order(start, ranks): for i, r in enumerate(ranks): assert min_rating(r) == start + i*RATING_PER_RANK