def test_square_order(): """ Tests that squares are generated as expected. Squares aren't in numeric order—the order needs to match the order they're displayed on the board. The ordering is as follows: 100 99 … 92 91 (reversed) 81 82 … 89 90 80 79 … 72 71 (reversed) … 21 22 … 29 30 20 19 … 12 11 (reversed) 01 02 … 09 10 """ the_board = board.Board() squares = list(the_board.squares) assert len(squares) == 100 for i, expected_number, expected_row_reversed in ( (0, 100, True), (1, 99, True), (9, 91, True), (10, 81, False), (11, 82, False), (19, 90, False), (20, 80, True), (80, 20, True), (89, 11, True), (90, 1, False), (99, 10, False)): assert squares[i].number == expected_number assert squares[i].row_reversed == expected_row_reversed
def get_context_data(self, **kwargs): last_roll = models.Roll.objects.order_by('-embargo').first() return super().get_context_data( **kwargs, last_roll=last_roll, board=board.Board(now=last_roll.embargo), special_square_types=models.SpecialSquareType.objects.all())
def public_board(request): """ Board for the public. Does not take embargoed rolls into account. """ special_square_types = models.SpecialSquareType.objects.all() return render(request, 'will_of_the_prophets/public_board.html', { 'board': board.Board(), 'special_square_types': special_square_types })
def test_position(rolls): """Test that the current position is correctly set.""" the_board = board.Board() assert the_board.get_current_position() == 11 squares = list(the_board.squares) assert squares[89].number == 11 assert squares[89].is_current_position for i in range(0, 99): if i == 89: continue assert not squares[i].is_current_position
def test_explicit_date(rolls): """Test that the current position is set with an explicit date.""" the_board = board.Board(now=datetime(year=2369, month=7, day=8, hour=20, tzinfo=pytz.utc)) assert the_board.get_current_position() == 37 squares = list(the_board.squares) assert squares[63].number == 37 assert squares[63].is_current_position for i in range(0, 99): if i == 63: continue assert not squares[i].is_current_position
def public_board(request): """ Board for the public. Does not take embargoed rolls into account. """ now = timezone.now() special_squares = board.get_special_squares(now) special_square_types = set(special_squares.values()) response = render( request, "will_of_the_prophets/public_board.html", {"board": board.Board(now), "special_square_types": special_square_types}, ) canonical_url = settings.PUBLIC_BOARD_CANONICAL_URL if canonical_url: response["Link"] = f'<{canonical_url}>; rel="canonical"' return response
def test_query_count(django_assert_max_num_queries): """Test that rendering the board does not issue an excessive number of queries.""" board.clear_caches() call_command("loaddata", "live") with django_assert_max_num_queries(10): str(board.Board())