-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccbd927
commit a2a0015
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from attackmate.variablestore import VariableStore | ||
|
||
|
||
class TestVariableStore: | ||
|
||
def test_set_and_get_variable(self): | ||
var_store = VariableStore() | ||
old_len = len(var_store.variables) | ||
var_store.set_variable('foo', 'bar') | ||
assert len(var_store.variables) == old_len + 1 | ||
assert var_store.get_variable('foo') == 'bar' | ||
|
||
def test_substitute_variable(self): | ||
var_store = VariableStore() | ||
var_store.set_variable('foo', 'bar') | ||
assert var_store.substitute('hello foo $foo') == 'hello foo bar' | ||
assert var_store.substitute('hello foo $foo', True) == 'hello foo bar' | ||
assert var_store.substitute('hello foo $bar') == 'hello foo $bar' | ||
assert var_store.substitute('hello foo $$foo') == 'hello foo $foo' | ||
assert var_store.substitute('hello foo $bar', True) == '' | ||
assert var_store.substitute(None) is None | ||
assert var_store.substitute(None, True) is None | ||
assert var_store.substitute(list['a', 'b']) == list['a', 'b'] | ||
|
||
def test_remove_sign(self): | ||
var_store = VariableStore() | ||
assert var_store.remove_sign('$foo', '$') == 'foo' | ||
assert var_store.remove_sign('$$foo', '$') == '$foo' | ||
assert var_store.remove_sign('@foo', '$') == '@foo' | ||
|
||
def test_from_dict(self): | ||
var_store = VariableStore() | ||
var_store.set_variable('hello', 'world') | ||
var_blah = {'a': 'foo', 'b': 'bar'} | ||
var_store.from_dict(var_blah) | ||
assert var_store.get_variable('hello') == 'world' | ||
assert var_store.get_variable('a') == 'foo' | ||
assert var_store.get_variable('b') == 'bar' | ||
assert len(var_store.variables) == 3 | ||
var_store.from_dict(['a']) | ||
assert len(var_store.variables) == 3 | ||
var_store.from_dict(None) | ||
assert len(var_store.variables) == 3 | ||
|
||
def test_clear(self): | ||
var_store = VariableStore() | ||
var_store.set_variable('hello', 'world') | ||
assert len(var_store.variables) == 1 | ||
var_store.clear() | ||
assert len(var_store.variables) == 0 |