mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-30 08:53:05 +00:00
add unit test import + fixture
This commit is contained in:
parent
140819dbb5
commit
f443485ee0
2 changed files with 73 additions and 46 deletions
19
test/fixtures.yml
Normal file
19
test/fixtures.yml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
add:
|
||||||
|
name: 'test_name'
|
||||||
|
group: 'test_group'
|
||||||
|
host: 'test_host'
|
||||||
|
protocol: 'test_protocol'
|
||||||
|
login: 'test_login'
|
||||||
|
password: 'test_password'
|
||||||
|
port: '42'
|
||||||
|
comment: 'test_comment'
|
||||||
|
update:
|
||||||
|
name: 'test_name_update'
|
||||||
|
group: 'test_group_update'
|
||||||
|
host: 'test_host_update'
|
||||||
|
protocol: 'test_protocol_update'
|
||||||
|
login: 'test_login_update'
|
||||||
|
password: 'test_password_update'
|
||||||
|
port: '43'
|
||||||
|
comment: 'test_comment_update'
|
||||||
|
|
100
test/test_mpw.rb
100
test/test_mpw.rb
|
@ -1,20 +1,23 @@
|
||||||
# File: tc_simple_number.rb
|
# File: tc_simple_number.rb
|
||||||
|
|
||||||
require_relative "../lib/MPW"
|
require_relative '../lib/MPW'
|
||||||
require "test/unit"
|
require 'test/unit'
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
class TestMPW < Test::Unit::TestCase
|
class TestMPW < Test::Unit::TestCase
|
||||||
|
|
||||||
|
#@@mpw = MPW::MPW.new('test.gpg', 'a.waksberg@yaegashi.fr')
|
||||||
def setup
|
def setup
|
||||||
@file_gpg = 'test.gpg'
|
file_gpg = 'test.gpg'
|
||||||
@key = 'test-mpw@test-mpw.local'
|
key = 'test-mpw@test-mpw.local'
|
||||||
|
|
||||||
if defined?(I18n.enforce_available_locales)
|
if defined?(I18n.enforce_available_locales)
|
||||||
I18n.enforce_available_locales = false
|
I18n.enforce_available_locales = false
|
||||||
end
|
end
|
||||||
|
|
||||||
File.delete(@file_gpg) if File.exist?(@file_gpg)
|
File.delete(file_gpg) if File.exist?(file_gpg)
|
||||||
@mpw = MPW::MPW.new(@file_gpg, @key)
|
@mpw = MPW::MPW.new(file_gpg, key)
|
||||||
|
@fixtures = YAML.load_file('fixtures.yml')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_load_empty_file
|
def test_load_empty_file
|
||||||
|
@ -23,16 +26,14 @@ class TestMPW < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_add
|
def test_add
|
||||||
name = 'test_name'
|
assert(@mpw.update(@fixtures['add']['name'],
|
||||||
group = 'test_group'
|
@fixtures['add']['group'],
|
||||||
host = 'test_host'
|
@fixtures['add']['host'],
|
||||||
protocol = 'test_protocol'
|
@fixtures['add']['protocol'],
|
||||||
login = 'test_login'
|
@fixtures['add']['login'],
|
||||||
password = 'test_password'
|
@fixtures['add']['password'],
|
||||||
port = '42'
|
@fixtures['add']['port'],
|
||||||
comment = 'test_comment'
|
@fixtures['add']['comment']))
|
||||||
|
|
||||||
assert(@mpw.update(name, group, host, protocol, login, password, port, comment))
|
|
||||||
|
|
||||||
assert_equal(1, @mpw.search.length)
|
assert_equal(1, @mpw.search.length)
|
||||||
|
|
||||||
|
@ -46,49 +47,54 @@ class TestMPW < Test::Unit::TestCase
|
||||||
assert_equal(42, result['port'])
|
assert_equal(42, result['port'])
|
||||||
assert_equal('test_comment', result['comment'])
|
assert_equal('test_comment', result['comment'])
|
||||||
|
|
||||||
assert(@mpw.update(name, group, host, protocol, login, password, port, comment))
|
assert(@mpw.update(@fixtures['add']['name'],
|
||||||
|
@fixtures['add']['group'],
|
||||||
|
@fixtures['add']['host'],
|
||||||
|
@fixtures['add']['protocol'],
|
||||||
|
@fixtures['add']['login'],
|
||||||
|
@fixtures['add']['password'],
|
||||||
|
@fixtures['add']['port'],
|
||||||
|
@fixtures['add']['comment']))
|
||||||
|
|
||||||
|
|
||||||
assert_equal(2, @mpw.search.length)
|
assert_equal(2, @mpw.search.length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_add_empty_name
|
def test_add_empty_name
|
||||||
name = ''
|
assert(!@mpw.update('',
|
||||||
group = 'test_group'
|
@fixtures['add']['group'],
|
||||||
host = 'test_host'
|
@fixtures['add']['host'],
|
||||||
protocol = 'test_protocol'
|
@fixtures['add']['protocol'],
|
||||||
login = 'test_login'
|
@fixtures['add']['login'],
|
||||||
password = 'test_password'
|
@fixtures['add']['password'],
|
||||||
port = '42'
|
@fixtures['add']['port'],
|
||||||
comment = 'test_comment'
|
@fixtures['add']['comment']))
|
||||||
|
|
||||||
assert(!@mpw.update(name, group, host, protocol, login, password, port, comment))
|
|
||||||
|
|
||||||
assert_equal(0, @mpw.search.length)
|
assert_equal(0, @mpw.search.length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update
|
def test_update
|
||||||
name = 'test_name'
|
assert(@mpw.update(@fixtures['add']['name'],
|
||||||
group = 'test_group'
|
@fixtures['add']['group'],
|
||||||
host = 'test_host'
|
@fixtures['add']['host'],
|
||||||
protocol = 'test_protocol'
|
@fixtures['add']['protocol'],
|
||||||
login = 'test_login'
|
@fixtures['add']['login'],
|
||||||
password = 'test_password'
|
@fixtures['add']['password'],
|
||||||
port = '42'
|
@fixtures['add']['port'],
|
||||||
comment = 'test_comment'
|
@fixtures['add']['comment']))
|
||||||
|
|
||||||
assert(@mpw.update(name, group, host, protocol, login, password, port, comment))
|
id = @mpw.search[0]['id']
|
||||||
|
|
||||||
id = @mpw.search[0]['id']
|
assert(@mpw.update(@fixtures['update']['name'],
|
||||||
name = 'test_name_update'
|
@fixtures['update']['group'],
|
||||||
group = 'test_group_update'
|
@fixtures['update']['host'],
|
||||||
host = 'test_host_update'
|
@fixtures['update']['protocol'],
|
||||||
protocol = 'test_protocol_update'
|
@fixtures['update']['login'],
|
||||||
login = 'test_login_update'
|
@fixtures['update']['password'],
|
||||||
password = 'test_password_update'
|
@fixtures['update']['port'],
|
||||||
port = '43'
|
@fixtures['update']['comment'],
|
||||||
comment = 'test_comment_update'
|
id))
|
||||||
|
|
||||||
assert(@mpw.update(name, group, host, protocol, login, password, port, comment, id))
|
|
||||||
assert_equal(1, @mpw.search.length)
|
assert_equal(1, @mpw.search.length)
|
||||||
|
|
||||||
result = @mpw.search_by_id(id)
|
result = @mpw.search_by_id(id)
|
||||||
|
@ -102,4 +108,6 @@ class TestMPW < Test::Unit::TestCase
|
||||||
assert_equal('test_comment_update', result['comment'])
|
assert_equal('test_comment_update', result['comment'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_import
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue