Example #1
0
def get_tile(x, y, z):
    if z < 7 or z > 16:
        return Response(status=404)

    tile = Tile(x, y, z)
    if not cache.tile_already_in_cache(tile):
        fetcher.fetch([tile])
    content = cache.read(tile)

    response = make_response(content)
    response.headers.set('Content-Type', 'image/png')
    response.headers.set('Content-Disposition',
                         'inline',
                         filename='%s.png' % y)
    response.headers.set('Content-Length', len(content))
    response.headers.set('Cache-Control', 'max-age=%d' % (60 * 60 * 24 * 30))
    return response
Example #2
0
class TestTile(unittest.TestCase):
    def setUp(self):
        self.tile = Tile(1, ["..#.", "##.#", "....", "#.#."])

    def test_upside(self):
        self.assertEqual(self.tile.upside, "..#.")

    def test_right_side(self):
        self.assertEqual(self.tile.right_side, ".#..")

    def test_downside(self):
        self.assertEqual(self.tile.downside, "#.#.")

    def test_left_side(self):
        self.assertEqual(self.tile.left_side, ".#.#")

    def test_flip(self):
        upside, right_side, downside, left_side = self.tile.sides()
        self.tile.flip()
        self.assertEqual(self.tile.upside, downside)
        self.assertEqual(self.tile.right_side, "".join(reversed(right_side)))
        self.assertEqual(self.tile.downside, upside)
        self.assertEqual(self.tile.left_side, "".join(reversed(left_side)))

    def test_rotate_sides(self):
        upside, right_side, downside, left_side = self.tile.sides()
        self.tile.rotate()
        self.assertEqual(self.tile.upside, right_side)
        self.assertEqual(self.tile.right_side, "".join(reversed(downside)))
        self.assertEqual(self.tile.downside, left_side)
        self.assertEqual(self.tile.left_side, "".join(reversed(upside)))

    def test_rotate_changes_matches(self):
        self.tile.matches = {UP: 1, RIGHT: 2, DOWN: 3, LEFT: 4}
        self.tile.rotate()
        self.assertEqual(self.tile.matches[UP], 2)
        self.assertEqual(self.tile.matches[RIGHT], 3)
        self.assertEqual(self.tile.matches[DOWN], 4)
        self.assertEqual(self.tile.matches[LEFT], 1)

    def test_flip_changes_matches(self):
        self.tile.matches = {UP: 1, RIGHT: 2, DOWN: 3, LEFT: 4}
        self.tile.flip()
        self.assertEqual(self.tile.matches[UP], 3)
        self.assertEqual(self.tile.matches[RIGHT], 2)
        self.assertEqual(self.tile.matches[DOWN], 1)
        self.assertEqual(self.tile.matches[LEFT], 4)

    def test_sides(self):
        self.assertEqual(self.tile.sides(), ('..#.', '.#..', '#.#.', '.#.#'))

    def test_reversed_sides(self):
        self.assertEqual(self.tile.reversed_sides(),
                         ('.#..', '..#.', '.#.#', '#.#.'))

    def test_all_sides(self):
        self.assertEqual(
            self.tile.all_sides(),
            ('..#.', '.#..', '#.#.', '.#.#', '.#..', '..#.', '.#.#', '#.#.'))

    def test_sides_match(self):
        other = Tile(2, ["....", "....", "....", "..#."])
        other2 = Tile(3, ["....", "....", "....", ".#.."])
        self.assertTrue(self.tile.sides_match(other, "upside"))
        self.assertFalse(self.tile.sides_match(other2, "upside"))

    def test_image_data(self):
        expected = [["#", "."], [".", "."]]
        data = self.tile.image_data()
        for x in range(2):
            for y in range(2):
                self.assertEqual(data[x][y], expected[x][y])
Example #3
0
 def test_sides_match(self):
     other = Tile(2, ["....", "....", "....", "..#."])
     other2 = Tile(3, ["....", "....", "....", ".#.."])
     self.assertTrue(self.tile.sides_match(other, "upside"))
     self.assertFalse(self.tile.sides_match(other2, "upside"))
Example #4
0
 def _create_test_tile():
     data = numpy.array([list(row) for row in IMAGE.splitlines()])
     return Tile(1, data)
Example #5
0
 def setUp(self):
     self.tile = Tile(1, ["..#.", "##.#", "....", "#.#."])
Example #6
0
 def test_h(self):
     tile = Tile(1, 0, 0, 3)
     self.assertEqual(tile.h(), 0)
     tile = Tile(9, 0, 0, 3)
     self.assertEqual(tile.h(), 8)
Example #7
0
 def test_set(self):
     tile = Tile(1, 0, 0, 3)
     tile.set(9, 8, 7)
     self.assertEqual(tile.label, 9)
     self.assertEqual(tile.row, 8)
     self.assertEqual(tile.column, 7)
Example #8
0
 def test_move_to(self):
     tile = Tile(1, 0, 0, 3)
     tile.move_to(1, 0)
     self.assertEqual(tile.row, 1)
     self.assertEqual(tile.column, 0)