view examples/blog/test.luan @ 1418:732b5de211fc

add Hosted.luan
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 18 Oct 2019 22:29:46 -0600
parents 7d4b5afb636f
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local to_string = Luan.to_string or error()
local Http = require "luan:http/Http.luan"
local Http_test = require "luan:http/Http_test.luan"
local init = Http_test.init or error()
local get_page = Http_test.get_page or error()
local Io = require "luan:Io.luan"
local print = Io.print or error()
local String = require "luan:String.luan"
local matches = String.matches or error()

local Db = require "site:/lib/Db.luan"
Db.db = Db.new("site:/private/local/lucene_test")
Db.db.delete_all()

local Post = require "site:/lib/Post.luan"
local page

print 'go'

init()
print '/'
get_page '/'

init()
print '/new.html'
get_page '/new.html'

init()
Http.request.parameters.subject = 'test'
Http.request.parameters.content = 'this is a test'
Http.request.parameters.save = 'whatever'
print '/new.html submit'
get_page '/new.html'
local posts = Post.get_all()
#posts == 1 or error()
local post_id = to_string(posts[1].id)

init()
Http.request.parameters.post = post_id
print '/edit.html'
get_page '/edit.html'

init()
Http.request.parameters.post = post_id
Http.request.parameters.subject = 'test'
Http.request.parameters.content = 'this is an edit'
Http.request.parameters.save = 'whatever'
print '/edit.html submit'
get_page '/edit.html'

init()
print '/ again'
page = get_page '/'
matches(page,'this is an edit') or error()

print 'done'