Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93005897
tequila_config_test.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 25, 13:03
Size
5 KB
Mime Type
text/x-ruby
Expires
Wed, Nov 27, 13:03 (2 d)
Engine
blob
Format
Raw Data
Handle
22556275
Attached To
R6833 Tequila Ruby client
tequila_config_test.rb
View Options
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'../../../../test/test_helper'
)
# require File.dirname(__FILE__) + '/../../test_helper'
require
'epfl/kt/tequila_authentication/tequila_config'
module
Lib
class
TequilaConfigTest
<
Test
::
Unit
::
TestCase
def
setup
end
# Test tequila_config creation without params (default values used).
def
test_tequila_default_config_creation
default_tequila_config
=
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
.
new
assert
default_tequila_config
assert_equal
\
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_SERVER
,
default_tequila_config
.
server
assert_equal
\
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_PORT
,
default_tequila_config
.
port
assert_equal
\
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_PATH
,
default_tequila_config
.
path
# logger.debug "+++ default_tequila_config.requested_infos='#{default_tequila_config.requested_infos.inspect}'"
assert_equal
\
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_REQUESTED_INFOS
.
size
,
default_tequila_config
.
requested_infos
.
size
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_REQUESTED_INFOS
.
keys
.
each
do
|
k
|
assert
default_tequila_config
.
requested_infos
[
k
]
assert_equal
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_REQUESTED_INFOS
[
k
]
,
default_tequila_config
.
requested_infos
[
k
]
end
end
# Test tequila_config creation nil given as params.
def
test_tequila_config_creation_with_nil
default_tequila_config
=
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
.
new
(
nil
)
assert
default_tequila_config
assert_equal
\
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_SERVER
,
default_tequila_config
.
server
assert_equal
\
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_PORT
,
default_tequila_config
.
port
assert_equal
\
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_PATH
,
default_tequila_config
.
path
# logger.debug "+++ default_tequila_config.requested_infos='#{default_tequila_config.requested_infos.inspect}'"
assert_equal
\
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_REQUESTED_INFOS
.
size
,
default_tequila_config
.
requested_infos
.
size
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_REQUESTED_INFOS
.
keys
.
each
do
|
k
|
assert
default_tequila_config
.
requested_infos
[
k
]
assert_equal
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_REQUESTED_INFOS
[
k
]
,
default_tequila_config
.
requested_infos
[
k
]
end
end
# Test tequila_config creation with some params provided.
def
test_tequila_config_creation
# First we test all the tequila_config params except ':requested_infos'
# 'to_test' is a hash with keys the params to test,
# and with values - an Array with a non-default value as first item,
# and the given default value as second one.
to_test
=
{
:server
=>
[
"tequila_test.epfl.ch"
,
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_SERVER
]
,
:port
=>
[
2222
,
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_PORT
]
,
:path
=>
[
"/cgi-bin/tequila_test"
,
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
::
DEFAULT_TEQUILA_PATH
]
,
# :requested_request_infos => [%w(key1 key2).join(","),
# Epfl::Kt::TequilaAuthentication::TequilaConfig::DEFAULT_TEQUILA_REQUESTED_REQUEST_INFOS]
}
# test_key = :server
to_test
.
keys
.
each
do
|
test_key
|
tequila_config
=
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
.
new
(
test_key
=>
to_test
[
test_key
][
0
]
)
assert
tequila_config
to_test
.
keys
.
each
do
|
k
|
logger
.
debug
"+++ k='
#{
k
.
inspect
}
', test_key='
#{
test_key
.
inspect
}
'"
if
k
==
test_key
assert_equal
to_test
[
k
][
0
]
,
tequila_config
.
send
(
k
)
else
assert_equal
to_test
[
k
][
1
]
,
tequila_config
.
send
(
k
)
end
end
end
# Test for a not-integer value give as port number.
assert_raise
(
ArgumentError
)
{
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
.
new
(
:port
=>
"NAN"
)
}
# Now test the ':requested_infos' param
assert_raise
(
ArgumentError
)
{
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
.
new
(
:requested_infos
=>
{
:badservice
=>
"S"
})
}
assert_raise
(
ArgumentError
)
{
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
.
new
(
:requested_infos
=>
{
:resource
=>
"R"
,
:service
=>
"S"
})
}
req_infos
=
{
:service
=>
"MyService"
,
:wish
=>
"MyWish"
}
tequila_config
=
Epfl
::
Kt
::
TequilaAuthentication
::
TequilaConfig
.
new
(
:requested_infos
=>
req_infos
)
assert
tequila_config
assert
tequila_config
.
requested_infos
assert_equal
req_infos
.
size
,
tequila_config
.
requested_infos
.
size
req_infos
.
keys
.
each
do
|
k
|
assert
tequila_config
.
requested_infos
[
k
]
assert_equal
req_infos
[
k
]
,
tequila_config
.
requested_infos
[
k
]
end
end
end
end
Event Timeline
Log In to Comment