diff --git a/solar/dblayer/test/conftest.py b/solar/dblayer/test/conftest.py index 7d259091..c5a5c8a4 100644 --- a/solar/dblayer/test/conftest.py +++ b/solar/dblayer/test/conftest.py @@ -79,4 +79,15 @@ def pytest_runtest_call(item): ModelMeta.session_start() +def dicts_to_hashable(list_of_dics): + rst = [] + for item in list_of_dics: + rst.append(tuple(item.items())) + return tuple(rst) + + +def pytest_namespace(): + return {'dicts_to_hashable': dicts_to_hashable} + + Model.get_bucket_name = classmethod(patched_get_bucket_name) diff --git a/solar/dblayer/test/test_real.py b/solar/dblayer/test/test_real.py index dc45581e..7cf58f0c 100644 --- a/solar/dblayer/test/test_real.py +++ b/solar/dblayer/test/test_real.py @@ -373,11 +373,13 @@ def test_simple_to_listdict_inputs(rk): r3.save() r4.save() - assert r2.inputs['input'] == [{u'input2': 1115, - u'input1': 110}, {u'input2': 115, - u'input1': 1110}, - {u'input2': 15, - u'input1': 10}] + inputs = set(pytest.dicts_to_hashable(r2.inputs['input'])) + expected_inputs = set(pytest.dicts_to_hashable( + [{u'input2': 1115, u'input1': 110}, + {u'input2': 115, u'input1': 1110}, + {u'input2': 15, u'input1': 10}])) + + assert inputs == expected_inputs def test_dict_to_list_inputs(rk): diff --git a/solar/test/test_diff_generation.py b/solar/test/test_diff_generation.py index cb8c710a..51cb48a1 100644 --- a/solar/test/test_diff_generation.py +++ b/solar/test/test_diff_generation.py @@ -21,27 +21,14 @@ @fixture def staged(): - return {'id': 'res.1', - 'tags': ['res', 'node.1'], - 'input': {'ip': {'value': '10.0.0.2'}, - 'list_val': {'value': [1, 2]}}, - 'metadata': {}, - 'connections': [ - ['node.1', 'res.1', ['ip', 'ip']], - ['node.1', 'res.1', ['key', 'key']] - ]} + return {'ip': {'value': '10.0.0.2'}, + 'list_val': {'value': [1, 2]}} @fixture def commited(): - return {'id': 'res.1', - 'tags': ['res', 'node.1'], - 'input': {'ip': '10.0.0.2', - 'list_val': [1]}, - 'metadata': {}, - 'connections': [ - ['node.1', 'res.1', ['ip', 'ip']] - ]} + return {'ip': '10.0.0.2', + 'list_val': [1]} @fixture @@ -55,25 +42,30 @@ def diff_for_update(staged, commited): def test_create_diff_with_empty_commited(full_diff): - # add will be executed - expected = [('add', '', - [('connections', [['node.1', 'res.1', ['ip', 'ip']], - ['node.1', 'res.1', ['key', 'key']]]), - ('input', { - 'ip': {'value': '10.0.0.2'}, - 'list_val': {'value': [1, 2]} - }), ('metadata', {}), ('id', 'res.1'), - ('tags', ['res', 'node.1'])])] - assert full_diff == expected + operations = set() + vals = {} + for item in full_diff: + operations.add(item[0]) + for val in item[2]: + vals[val[0]] = val[1] + + assert len(full_diff) == 1 + assert set(['add']) == operations + assert vals['ip'] == {'value': '10.0.0.2'} + assert vals['list_val'] == {'value': [1, 2]} def test_create_diff_modified(diff_for_update): - assert diff_for_update == [ - ('add', 'connections', [(1, ['node.1', 'res.1', ['key', 'key']])]), - ('change', 'input.ip', - ('10.0.0.2', {'value': '10.0.0.2'})), ('change', 'input.list_val', - ([1], {'value': [1, 2]})) - ] + operations = set() + vals = {} + for item in diff_for_update: + operations.add(item[0]) + vals[item[1]] = item[2] + + assert len(diff_for_update) == 2 + assert set(['change']) == operations + assert vals['ip'] == ('10.0.0.2', {'value': '10.0.0.2'}) + assert vals['list_val'] == ([1], {'value': [1, 2]}) def test_verify_patch_creates_expected(staged, diff_for_update, commited): @@ -84,21 +76,3 @@ def test_verify_patch_creates_expected(staged, diff_for_update, commited): def test_revert_update(staged, diff_for_update, commited): expected = revert(diff_for_update, staged) assert expected == commited - - -@fixture -def resources(): - r = {'n.1': {'uid': 'n.1', - 'args': {'ip': '10.20.0.2'}, - 'connections': [], - 'tags': []}, - 'r.1': {'uid': 'r.1', - 'args': {'ip': '10.20.0.2'}, - 'connections': [['n.1', 'r.1', ['ip', 'ip']]], - 'tags': []}, - 'h.1': {'uid': 'h.1', - 'args': {'ip': '10.20.0.2', - 'ips': ['10.20.0.2']}, - 'connections': [['n.1', 'h.1', ['ip', 'ip']]], - 'tags': []}} - return r diff --git a/tox.ini b/tox.ini index f20f61d6..f2478e3b 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,6 @@ envlist = pep8,py27 usedevelop = True install_command = pip install -U {opts} {packages} setenv = VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 deps = -r{toxinidir}/test-requirements.txt commands = ostestr