factor/basis/furnace/sessions/sessions-tests.factor

155 lines
3.8 KiB
Factor
Raw Normal View History

IN: furnace.sessions.tests
USING: tools.test http furnace.sessions
2008-06-02 16:00:03 -04:00
furnace.actions http.server http.server.responses
2008-06-17 01:10:46 -04:00
math namespaces kernel accessors io.sockets io.servers.connection
2008-04-26 02:44:45 -04:00
prettyprint io.streams.string io.files splitting destructors
sequences db db.tuples db.sqlite continuations urls math.parser
2008-06-02 16:00:03 -04:00
furnace ;
2008-02-29 01:57:38 -05:00
2008-04-26 02:44:45 -04:00
: with-session
[
2008-05-26 01:47:27 -04:00
[ [ save-session-after ] [ session set ] bi ] dip call
2008-04-26 02:44:45 -04:00
] with-destructors ; inline
2008-03-03 03:19:36 -05:00
TUPLE: foo ;
C: <foo> foo
2008-03-11 04:39:09 -04:00
M: foo init-session* drop 0 "x" sset ;
M: foo call-responder*
2008-03-15 07:22:47 -04:00
2drop
"x" [ 1+ ] schange
"x" sget number>string "text/html" <content> ;
2008-03-15 07:22:47 -04:00
: url-responder-mock-test
[
<request>
2008-03-17 05:31:13 -04:00
"GET" >>method
dup url>>
"id" get session-id-key set-query-param
"/" >>path drop
init-request
2008-04-29 06:58:34 -04:00
{ } sessions get call-responder
2008-03-15 07:22:47 -04:00
[ write-response-body drop ] with-string-writer
] with-destructors ;
2008-04-29 06:58:34 -04:00
: sessions-mock-test
2008-03-15 07:22:47 -04:00
[
<request>
2008-03-17 05:31:13 -04:00
"GET" >>method
"cookies" get >>cookies
dup url>> "/" >>path drop
init-request
2008-04-29 06:58:34 -04:00
{ } sessions get call-responder
2008-03-15 07:22:47 -04:00
[ write-response-body drop ] with-string-writer
] with-destructors ;
2008-03-17 05:31:13 -04:00
: <exiting-action>
<action>
[ [ ] "text/plain" <content> exit-with ] >>display ;
2008-03-17 05:31:13 -04:00
2008-04-26 06:49:41 -04:00
[ "auth-test.db" temp-file sqlite-db delete-file ] ignore-errors
2008-04-26 02:44:45 -04:00
"auth-test.db" temp-file sqlite-db [
<request> init-request
session ensure-table
2008-04-26 06:49:41 -04:00
2008-06-14 00:00:48 -04:00
"127.0.0.1" 1234 <inet4> remote-address set
[ ] [
2008-04-29 06:58:34 -04:00
<foo> <sessions>
sessions set
] unit-test
2008-04-26 02:44:45 -04:00
[
2008-04-29 06:58:34 -04:00
[ ] [
2008-06-14 01:31:00 -04:00
empty-session
2008-04-29 06:58:34 -04:00
123 >>id session set
] unit-test
2008-04-26 02:44:45 -04:00
[ ] [ 3 "x" sset ] unit-test
[ 9 ] [ "x" sget sq ] unit-test
[ ] [ "x" [ 1- ] schange ] unit-test
[ 4 ] [ "x" sget sq ] unit-test
[ t ] [ session get changed?>> ] unit-test
2008-04-26 02:44:45 -04:00
] with-scope
[ t ] [
2008-04-29 06:58:34 -04:00
begin-session id>>
get-session session?
2008-04-26 02:44:45 -04:00
] unit-test
2008-03-17 05:31:13 -04:00
2008-04-26 02:44:45 -04:00
[ { 5 0 } ] [
2008-03-17 05:31:13 -04:00
[
2008-04-29 06:58:34 -04:00
begin-session
2008-04-26 02:44:45 -04:00
dup [ 5 "a" sset ] with-session
dup [ "a" sget , ] with-session
dup [ "x" sget , ] with-session
2008-04-29 06:58:34 -04:00
drop
2008-04-26 02:44:45 -04:00
] { } make
] unit-test
[ 0 ] [
2008-04-29 06:58:34 -04:00
begin-session id>>
get-session [ "x" sget ] with-session
2008-04-26 02:44:45 -04:00
] unit-test
[ { 5 0 } ] [
[
2008-04-29 06:58:34 -04:00
begin-session id>>
dup get-session [ 5 "a" sset ] with-session
dup get-session [ "a" sget , ] with-session
dup get-session [ "x" sget , ] with-session
drop
2008-04-26 02:44:45 -04:00
] { } make
] unit-test
[ ] [
2008-04-29 06:58:34 -04:00
<foo> <sessions>
sessions set
2008-04-26 02:44:45 -04:00
] unit-test
[
<request>
"GET" >>method
dup url>> "/" >>path drop
2008-04-26 02:44:45 -04:00
request set
2008-04-29 06:58:34 -04:00
{ "etc" } sessions get call-responder response set
2008-04-26 02:44:45 -04:00
[ "1" ] [ [ response get write-response-body drop ] with-string-writer ] unit-test
response get
] with-destructors
response set
[ ] [ response get cookies>> "cookies" set ] unit-test
2008-04-29 06:58:34 -04:00
[ "2" ] [ sessions-mock-test ] unit-test
[ "3" ] [ sessions-mock-test ] unit-test
[ "4" ] [ sessions-mock-test ] unit-test
2008-04-26 02:44:45 -04:00
[
[ ] [
<request>
"GET" >>method
dup url>>
"id" get session-id-key set-query-param
"/" >>path drop
2008-04-26 02:44:45 -04:00
request set
[
2008-04-29 06:58:34 -04:00
{ } <exiting-action> <sessions>
2008-04-26 02:44:45 -04:00
call-responder
] with-destructors response set
] unit-test
2008-05-01 17:24:50 -04:00
[ "text/plain" ] [ response get content-type>> ] unit-test
2008-04-26 02:44:45 -04:00
[ f ] [ response get cookies>> empty? ] unit-test
] with-scope
] with-db