Finished writing cacheing tests
Cacheing tests now make sure that logged in users don't cause pages to cache. Also fixed creating a logged in session automatically in the mock environment.
This commit is contained in:
parent
68561443a5
commit
16054156a1
|
@ -34,7 +34,23 @@ describe("smr cacheing",function()
|
||||||
local cache = require("cache")
|
local cache = require("cache")
|
||||||
renderspy = spy.on(cache,"render")
|
renderspy = spy.on(cache,"render")
|
||||||
configure()
|
configure()
|
||||||
pending("TODO: complete")
|
for row in cache.cache:rows("SELECT COUNT(*) FROM cache") do
|
||||||
|
assert(row[1] == 0, string.format(
|
||||||
|
"Cache should not have any rows before " ..
|
||||||
|
"request have been made."
|
||||||
|
))
|
||||||
|
end
|
||||||
|
local req = mock_env.session()
|
||||||
|
req.method = "GET"
|
||||||
|
req.path = "/a"
|
||||||
|
req.args = {}
|
||||||
|
read_get(req)
|
||||||
|
for row in cache.cache:rows("SELECT COUNT(*) FROM cache") do
|
||||||
|
assert(row[1] == 0, string.format(
|
||||||
|
"Cache should not cache requests made by " ..
|
||||||
|
"logged in users."
|
||||||
|
))
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
it("caches one page for domain/id and author.domain/id",function()
|
it("caches one page for domain/id and author.domain/id",function()
|
||||||
local read_get = require("endpoints.read_get")
|
local read_get = require("endpoints.read_get")
|
||||||
|
@ -68,7 +84,37 @@ describe("smr cacheing",function()
|
||||||
end)
|
end)
|
||||||
describe("author home page",function()
|
describe("author home page",function()
|
||||||
it("lists all stories by that author",function()
|
it("lists all stories by that author",function()
|
||||||
pending("TODO")
|
local read_get = require("endpoints.index_get")
|
||||||
|
local cache = require("cache")
|
||||||
|
configure()
|
||||||
|
local req_m = {__index = {
|
||||||
|
method = "GET",
|
||||||
|
path = "/a",
|
||||||
|
args = {}
|
||||||
|
}}
|
||||||
|
local base_host = {host="user.test.host"}
|
||||||
|
for row in cache.cache:rows("SELECT COUNT(*) FROM cache") do
|
||||||
|
assert(row[1] == 0, string.format(
|
||||||
|
"Before requesting user homepage " ..
|
||||||
|
"there should not be any pages in the " ..
|
||||||
|
"cache."
|
||||||
|
))
|
||||||
|
end
|
||||||
|
local base_req = setmetatable({host="user.test.host"},req_m)
|
||||||
|
read_get(base_req)
|
||||||
|
for row in cache.cache:rows("SELECT COUNT(*) FROM cache") do
|
||||||
|
assert(row[1] == 1, string.format(
|
||||||
|
"After reading the autor home page, " ..
|
||||||
|
" only that page should be cached."
|
||||||
|
))
|
||||||
|
end
|
||||||
|
read_get(base_req)
|
||||||
|
for row in cache.cache:rows("SELECT COUNT(*) FROM cache") do
|
||||||
|
assert(row[1] == 1, string.format(
|
||||||
|
"After reading the autor home page " ..
|
||||||
|
" twice only that page should be cached."
|
||||||
|
))
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -7,6 +7,11 @@ mock.env = env
|
||||||
--Mirror print prior to lua 5.4
|
--Mirror print prior to lua 5.4
|
||||||
--local oldprint = print
|
--local oldprint = print
|
||||||
local ntostring
|
local ntostring
|
||||||
|
|
||||||
|
-- Modules that get required lazily
|
||||||
|
local login_post
|
||||||
|
local fuzzy
|
||||||
|
local claim_post
|
||||||
print_table= function(...)
|
print_table= function(...)
|
||||||
print("Print called")
|
print("Print called")
|
||||||
local args = {...}
|
local args = {...}
|
||||||
|
@ -190,7 +195,7 @@ local session_m = {__index = {
|
||||||
print("After requireing login_post edpoint, self.args is " .. tostring(self.args))
|
print("After requireing login_post edpoint, self.args is " .. tostring(self.args))
|
||||||
self.args.user = who
|
self.args.user = who
|
||||||
self.args.pass = pass
|
self.args.pass = pass
|
||||||
post_login(self)
|
login_post(self)
|
||||||
error("TODO")
|
error("TODO")
|
||||||
end,
|
end,
|
||||||
logout = function(self)
|
logout = function(self)
|
||||||
|
@ -202,16 +207,43 @@ local session_m = {__index = {
|
||||||
}}
|
}}
|
||||||
|
|
||||||
function mock.session(tbl)
|
function mock.session(tbl)
|
||||||
if not post_login_required then
|
if post_login == nil then
|
||||||
post_login = require("endpoints.login_post")
|
login_post = require("endpoints.login_post")
|
||||||
post_login_required = true
|
fuzzy = require("spec.fuzzgen")
|
||||||
|
claim_post = require("endpoints.claim_post")
|
||||||
|
configure()
|
||||||
end
|
end
|
||||||
tbl = tbl or {}
|
local username = fuzzy.subdomain()
|
||||||
tbl.args = tbl.args or {}
|
local claim_req = {
|
||||||
local req = tbl or {
|
method = "POST",
|
||||||
host = "test.host",
|
host = "test.host",
|
||||||
|
path = "/_claim",
|
||||||
|
args = {
|
||||||
|
user = username
|
||||||
}
|
}
|
||||||
return setmetatable(req,session_m)
|
}
|
||||||
|
claim_post(claim_req)
|
||||||
|
local login_req = {
|
||||||
|
method = "POST",
|
||||||
|
host = "test.host",
|
||||||
|
path = "/_login",
|
||||||
|
args = {
|
||||||
|
user = username
|
||||||
|
},
|
||||||
|
file = {
|
||||||
|
pass = claim_req.response
|
||||||
|
}
|
||||||
|
}
|
||||||
|
login_post(login_req)
|
||||||
|
local cookie = login_req.response_headers["set-cookie"]
|
||||||
|
local sessionid = cookie:match("session=([^;]+)")
|
||||||
|
local req = {
|
||||||
|
host = "test.host",
|
||||||
|
cookies = {
|
||||||
|
session = sessionid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return req, username
|
||||||
end
|
end
|
||||||
|
|
||||||
return mock
|
return mock
|
||||||
|
|
Loading…
Reference in New Issue