1 # -*- encoding: binary -*-
7 module TestRackReadWrite
10 def test_rack_read_write_suffix_mime
11 @app = Metropolis.new(@app_opts.merge(:encoding => :deflate,
12 :use => Metropolis::SuffixMime))
15 o = { :lint => true, :fatal => true }
16 req = Rack::MockRequest.new(@app)
17 r = req.put("/asdf.jpg", o.merge(:input => "ASDF"))
18 assert_equal 201, r.status
19 assert_equal "text/plain", r.headers["Content-Type"]
20 assert_equal "Created\n", r.body
22 r = req.get("/asdf.jpg")
23 assert_equal 200, r.status
24 assert_equal "image/jpeg", r.headers["Content-Type"]
25 assert_equal "ASDF", r.body
27 r = req.request("HEAD", "/asdf.jpg")
28 assert_equal 200, r.status
29 assert_equal "image/jpeg", r.headers["Content-Type"]
30 assert_equal "", r.body
33 def test_rack_read_write_deflated
34 @app = Metropolis.new(@app_opts.merge(:encoding => :deflate))
37 blob = "." * 1024 * 1024
38 o = { :lint => true, :fatal => true }
39 req = Rack::MockRequest.new(app)
41 r = req.put("/asdf", o.merge(:input => blob))
42 assert_equal 201, r.status
43 assert_equal "Created\n", r.body
45 r = req.get("/asdf", o.merge("HTTP_ACCEPT_ENCODING" => "deflate"))
46 assert_equal 200, r.status
47 assert_equal "deflate", r.headers['Content-Encoding']
48 assert r.body.size < blob.size
50 r = req.get("/asdf", o.merge("HTTP_ACCEPT_ENCODING" => "gzip"))
51 assert_equal 200, r.status
52 assert_nil r.headers['Content-Encoding']
53 assert_equal blob, r.body
56 def test_rack_read_write_gzipped
57 @app = Metropolis.new(@app_opts.merge(:encoding => :gzip))
60 blob = "." * 1024 * 1024
61 o = { :lint => true, :fatal => true }
62 req = Rack::MockRequest.new(app)
64 r = req.put("/asdf", o.merge(:input => blob))
65 assert_equal 201, r.status
66 assert_equal "Created\n", r.body
68 r = req.get("/asdf", o.merge("HTTP_ACCEPT_ENCODING" => "gzip"))
69 assert_equal 200, r.status
70 assert_equal "gzip", r.headers['Content-Encoding']
71 assert r.body.size < blob.size
73 r = req.get("/asdf", o.merge("HTTP_ACCEPT_ENCODING" => "deflate"))
74 assert_equal 200, r.status
75 assert_nil r.headers['Content-Encoding']
76 assert_equal blob, r.body
79 def test_rack_read_write
80 @app = Metropolis.new(@app_opts)
85 o = { :lint => true, :fatal => true }
86 req = Rack::MockRequest.new(app)
88 r = req.put("/asdf", o.merge(:input=>"ASDF"))
89 assert_equal 201, r.status
90 assert_equal "Created\n", r.body
93 assert_equal 200, r.status
94 assert_equal "ASDF", r.body
96 r = req.request("HEAD", "/asdf", {})
97 assert_equal 200, r.status
98 assert_equal "", r.body
100 r = req.delete("/asdf", {})
101 assert_equal 200, r.status
102 assert_equal "OK\n", r.body
105 assert_equal 404, r.status
106 assert_equal "Not Found\n", r.body
108 r = req.delete("/asdf", {})
109 assert_equal 404, r.status
110 assert_equal "Not Found\n", r.body
112 r = req.request("HEAD", "/asdf", {})
113 assert_equal 404, r.status
114 assert_equal "", r.body
117 def test_rack_readonly
118 tmp = Metropolis.new(@app_opts)
120 @app = Metropolis.new(@app_opts.merge(:readonly => true))
124 def basic_rest_readonly
125 o = { :lint => true, :fatal => true }
126 req = Rack::MockRequest.new(app)
128 r = req.put("/asdf", o.merge(:input=>"ASDF"))
129 assert_equal 403, r.status
132 assert_equal 404, r.status
134 r = req.request("HEAD", "/asdf", {})
135 assert_equal 404, r.status
137 r = req.delete("/asdf", {})
138 assert_equal 403, r.status