factor/extra/http/server/sessions/sessions-tests.factor

153 lines
4.1 KiB
Factor
Raw Normal View History

2008-03-03 03:19:36 -05:00
IN: http.server.sessions.tests
2008-03-15 07:22:47 -04:00
USING: tools.test http http.server.sessions
2008-04-26 02:44:45 -04:00
http.server.sessions.storage http.server.sessions.storage.db
2008-03-17 05:31:13 -04:00
http.server.actions http.server math namespaces kernel accessors
2008-04-26 02:44:45 -04:00
prettyprint io.streams.string io.files splitting destructors
2008-04-26 06:49:41 -04:00
sequences db db.sqlite continuations ;
2008-02-29 01:57:38 -05:00
2008-04-26 02:44:45 -04:00
: with-session
[
>r [ save-session-after ] [ \ session set ] bi r> call
] 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
"text/html" <content> [ "x" sget pprint ] >>body ;
: url-responder-mock-test
[
<request>
2008-03-17 05:31:13 -04:00
"GET" >>method
"id" get session-id-key set-query-param
"/" >>path
2008-03-15 07:22:47 -04:00
request set
2008-04-26 02:44:45 -04:00
{ } session-manager get call-responder
2008-03-15 07:22:47 -04:00
[ write-response-body drop ] with-string-writer
] with-destructors ;
: session-manager-mock-test
2008-03-15 07:22:47 -04:00
[
<request>
2008-03-17 05:31:13 -04:00
"GET" >>method
"cookies" get >>cookies
"/" >>path
2008-03-15 07:22:47 -04:00
request set
2008-04-26 02:44:45 -04:00
{ } session-manager 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-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 [
init-request
2008-04-26 06:49:41 -04:00
init-sessions-table
[ ] [
<foo> <session-manager>
sessions-in-db >>sessions
session-manager set
] unit-test
2008-04-26 02:44:45 -04:00
[
empty-session
123 >>id session set
[ ] [ 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 ] [
session-manager get begin-session id>>
session-manager get sessions>> get-session session?
] 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-26 02:44:45 -04:00
session-manager get begin-session
dup [ 5 "a" sset ] with-session
dup [ "a" sget , ] with-session
dup [ "x" sget , ] with-session
id>> session-manager get sessions>> delete-session
] { } make
] unit-test
[ 0 ] [
session-manager get begin-session id>>
session-manager get sessions>> get-session [ "x" sget ] with-session
] unit-test
[ { 5 0 } ] [
[
session-manager get begin-session id>>
dup session-manager get sessions>> get-session [ 5 "a" sset ] with-session
dup session-manager get sessions>> get-session [ "a" sget , ] with-session
dup session-manager get sessions>> get-session [ "x" sget , ] with-session
session-manager get sessions>> delete-session
] { } make
] unit-test
[ ] [
<foo> <session-manager>
2008-04-26 02:44:45 -04:00
sessions-in-db >>sessions
session-manager set
] unit-test
[
<request>
"GET" >>method
"/" >>path
request set
{ "etc" } session-manager get call-responder response set
[ "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
[ "2" ] [ session-manager-mock-test ] unit-test
[ "3" ] [ session-manager-mock-test ] unit-test
[ "4" ] [ session-manager-mock-test ] unit-test
2008-04-26 02:44:45 -04:00
[
[ ] [
<request>
"GET" >>method
"id" get session-id-key set-query-param
"/" >>path
request set
[
{ } <exiting-action> <session-manager>
2008-04-26 02:44:45 -04:00
sessions-in-db >>sessions
call-responder
] with-destructors response set
] unit-test
[ "text/plain" ] [ response get "content-type" header ] unit-test
[ f ] [ response get cookies>> empty? ] unit-test
] with-scope
] with-db