1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-23 13:57:52 +00:00
mpw/test/test_item.rb

166 lines
4.7 KiB
Ruby
Raw Normal View History

2016-11-10 22:57:16 +00:00
require 'mpw/item'
2015-02-12 17:01:58 +00:00
require 'test/unit'
require 'yaml'
2015-02-12 17:01:58 +00:00
class TestItem < Test::Unit::TestCase
def setup
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = false
end
I18n.load_path = Dir['./i18n/cli/*.yml']
I18n.default_locale = :en
2017-05-11 20:24:05 +00:00
@fixtures = YAML.load_file('./test/files/fixtures.yml')
end
def test_00_add_without_name
2017-05-11 20:24:05 +00:00
assert_raise(RuntimeError) { MPW::Item.new }
end
2017-05-13 10:28:42 +00:00
def test_01_add
2017-05-11 20:24:05 +00:00
data = {
2017-05-13 10:28:42 +00:00
group: @fixtures['add']['group'],
user: @fixtures['add']['user'],
2017-09-05 20:16:37 +00:00
url: @fixtures['add']['url'],
2017-05-13 10:28:42 +00:00
comment: @fixtures['add']['comment']
2017-05-11 20:24:05 +00:00
}
item = MPW::Item.new(data)
assert(!item.nil?)
assert(!item.empty?)
2017-09-05 20:16:37 +00:00
assert_equal(@fixtures['add']['url'], item.url)
2017-05-13 10:28:42 +00:00
assert_equal(@fixtures['add']['group'], item.group)
assert_equal(@fixtures['add']['host'], item.host)
assert_equal(@fixtures['add']['protocol'], item.protocol)
assert_equal(@fixtures['add']['user'], item.user)
assert_equal(@fixtures['add']['port'].to_i, item.port)
assert_equal(@fixtures['add']['comment'], item.comment)
end
2017-05-13 10:28:42 +00:00
def test_02_import
2017-05-11 20:24:05 +00:00
data = {
2017-05-13 10:28:42 +00:00
id: @fixtures['import']['id'],
group: @fixtures['import']['group'],
user: @fixtures['import']['user'],
2017-09-05 20:16:37 +00:00
url: @fixtures['import']['url'],
2017-05-13 10:28:42 +00:00
comment: @fixtures['import']['comment'],
created: @fixtures['import']['created']
2017-05-11 20:24:05 +00:00
}
item = MPW::Item.new(data)
assert(!item.nil?)
assert(!item.empty?)
2017-05-13 10:28:42 +00:00
assert_equal(@fixtures['import']['id'], item.id)
2017-09-05 20:16:37 +00:00
assert_equal(@fixtures['import']['url'], item.url)
2017-05-13 10:28:42 +00:00
assert_equal(@fixtures['import']['group'], item.group)
assert_equal(@fixtures['import']['host'], item.host)
assert_equal(@fixtures['import']['protocol'], item.protocol)
assert_equal(@fixtures['import']['user'], item.user)
assert_equal(@fixtures['import']['port'].to_i, item.port)
assert_equal(@fixtures['import']['comment'], item.comment)
assert_equal(@fixtures['import']['created'], item.created)
end
def test_03_update
2017-05-11 20:24:05 +00:00
data = {
2017-05-13 10:28:42 +00:00
group: @fixtures['add']['group'],
user: @fixtures['add']['user'],
2017-09-05 20:16:37 +00:00
url: @fixtures['add']['url'],
2017-05-13 10:28:42 +00:00
comment: @fixtures['add']['comment']
2017-05-11 20:24:05 +00:00
}
item = MPW::Item.new(data)
assert(!item.nil?)
assert(!item.empty?)
created = item.created
last_edit = item.last_edit
2017-05-11 20:24:05 +00:00
data = {
group: @fixtures['update']['group'],
user: @fixtures['update']['user'],
2017-09-05 20:16:37 +00:00
url: @fixtures['update']['url'],
2017-05-11 20:24:05 +00:00
comment: @fixtures['update']['comment']
}
sleep(1)
assert(item.update(data))
assert(!item.empty?)
2017-09-05 20:16:37 +00:00
assert_equal(@fixtures['update']['url'], item.url)
assert_equal(@fixtures['update']['group'], item.group)
assert_equal(@fixtures['update']['host'], item.host)
assert_equal(@fixtures['update']['protocol'], item.protocol)
assert_equal(@fixtures['update']['user'], item.user)
assert_equal(@fixtures['update']['port'].to_i, item.port)
assert_equal(@fixtures['update']['comment'], item.comment)
assert_equal(created, item.created)
assert_not_equal(last_edit, item.last_edit)
end
def test_05_update_one_element
2017-05-11 20:24:05 +00:00
data = {
2017-05-13 10:28:42 +00:00
group: @fixtures['add']['group'],
user: @fixtures['add']['user'],
2017-09-05 20:16:37 +00:00
url: @fixtures['add']['url'],
2017-05-13 10:28:42 +00:00
comment: @fixtures['add']['comment']
2017-05-11 20:24:05 +00:00
}
item = MPW::Item.new(data)
assert(!item.nil?)
assert(!item.empty?)
last_edit = item.last_edit
sleep(1)
2017-09-05 20:16:37 +00:00
item.update(comment: @fixtures['update']['comment'])
2017-09-05 20:16:37 +00:00
assert_equal(@fixtures['add']['url'], item.url)
2017-05-13 10:28:42 +00:00
assert_equal(@fixtures['add']['group'], item.group)
assert_equal(@fixtures['add']['host'], item.host)
assert_equal(@fixtures['add']['protocol'], item.protocol)
assert_equal(@fixtures['add']['user'], item.user)
assert_equal(@fixtures['add']['port'].to_i, item.port)
assert_equal(@fixtures['update']['comment'], item.comment)
assert_not_equal(last_edit, item.last_edit)
end
def test_05_delete
2017-05-11 20:24:05 +00:00
data = {
2017-05-13 10:28:42 +00:00
group: @fixtures['add']['group'],
user: @fixtures['add']['user'],
2017-09-05 20:16:37 +00:00
url: @fixtures['add']['url'],
2017-05-13 10:28:42 +00:00
comment: @fixtures['add']['comment']
2017-05-11 20:24:05 +00:00
}
item = MPW::Item.new(data)
assert(!item.nil?)
assert(!item.empty?)
item.delete
assert(!item.nil?)
assert(item.empty?)
assert_equal(nil, item.id)
2017-09-05 20:16:37 +00:00
assert_equal(nil, item.url)
assert_equal(nil, item.group)
assert_equal(nil, item.host)
assert_equal(nil, item.protocol)
assert_equal(nil, item.user)
assert_equal(nil, item.port)
assert_equal(nil, item.comment)
assert_equal(nil, item.created)
end
end