2015-02-12 17:01:58 +00:00
|
|
|
#!/usr/bin/ruby
|
2017-03-27 20:18:17 +00:00
|
|
|
|
2016-11-10 22:57:16 +00:00
|
|
|
require 'mpw/item'
|
2015-02-12 17:01:58 +00:00
|
|
|
require 'test/unit'
|
|
|
|
require 'yaml'
|
2017-03-27 20:18:17 +00:00
|
|
|
|
2015-02-12 17:01:58 +00:00
|
|
|
class TestItem < Test::Unit::TestCase
|
2017-03-27 20:18:17 +00:00
|
|
|
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')
|
2017-03-27 20:18:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_00_add_without_name
|
2017-05-11 20:24:05 +00:00
|
|
|
assert_raise(RuntimeError) { MPW::Item.new }
|
2017-03-27 20:18:17 +00:00
|
|
|
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
|
|
|
}
|
2017-03-27 20:18:17 +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)
|
2017-03-27 20:18:17 +00:00
|
|
|
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
|
|
|
}
|
2017-03-27 20:18:17 +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)
|
2017-03-27 20:18:17 +00:00
|
|
|
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
|
|
|
}
|
2017-03-27 20:18:17 +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']
|
|
|
|
}
|
2017-03-27 20:18:17 +00:00
|
|
|
|
|
|
|
sleep(1)
|
|
|
|
assert(item.update(data))
|
|
|
|
|
|
|
|
assert(!item.empty?)
|
|
|
|
|
2017-09-05 20:16:37 +00:00
|
|
|
assert_equal(@fixtures['update']['url'], item.url)
|
2017-03-27 20:18:17 +00:00
|
|
|
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
|
|
|
}
|
2017-03-27 20:18:17 +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-03-27 20:18:17 +00:00
|
|
|
|
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)
|
2017-03-27 20:18:17 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2017-03-27 20:18:17 +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)
|
2017-03-27 20:18:17 +00:00
|
|
|
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
|