From 370e6ecf0fc5a493878fe4e0171254b632d72471 Mon Sep 17 00:00:00 2001 From: Siddharth Ravikumar Date: Tue, 31 Mar 2015 20:28:42 -0400 Subject: new methods in combox.silo.ComboxSilo -- node_get, node_set. noddicts. These methods will be used to manage the dictionaries in the db related to the zarking shards. modified: combox/silo.py modified: tests/silo_test.py --- tests/silo_test.py | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) (limited to 'tests') diff --git a/tests/silo_test.py b/tests/silo_test.py index 1a290b4..9c4fc8f 100644 --- a/tests/silo_test.py +++ b/tests/silo_test.py @@ -24,6 +24,8 @@ from os import path, remove from combox.silo import ComboxSilo from combox.file import read_file, write_file, hash_file +from nose.tools import * + from tests.utils import get_config, rm_nodedirs, rm_configdir class TestSilo(object): @@ -93,6 +95,114 @@ class TestSilo(object): assert not csilo.exists(self.LOREM_IPSUM) + def test_csilo_node_dicts(self): + """Tests ComboxSilo class, if the dictinaries need for housekeeping + node directories are created. + + """ + silo = ComboxSilo(self.config) + keys = silo.db.db.keys() + + node_dicts = ['shard_created', 'shard_modified', 'shard_moved', + 'shard_deleted'] + for ndict in node_dicts: + assert ndict in keys + + + def test_csilo_nodset_create(self): + """Tests node_set method, in ComboxSilo class, when type is 'shard_created'. + """ + + silo = ComboxSilo(self.config) + silo.node_set('shard_created', self.LOREM) + silo.node_set('shard_created', self.LOREM) + silo.node_set('shard_created', self.LOREM) + + silo.node_set('shard_created', self.IPSUM) + silo.node_set('shard_created', self.IPSUM) + silo.node_set('shard_created', self.IPSUM) + silo.node_set('shard_created', self.IPSUM) + + dict_shard_created = silo.db.get('shard_created') + assert_equal(3, dict_shard_created[self.LOREM]) + assert_equal(4, dict_shard_created[self.IPSUM]) + + + def test_csilo_nodset_modified(self): + """Tests node_set method, in ComboxSilo class, when type is 'shard_modified'. + """ + + silo = ComboxSilo(self.config) + silo.node_set('shard_modified', self.LOREM) + silo.node_set('shard_modified', self.LOREM) + silo.node_set('shard_modified', self.LOREM) + + silo.node_set('shard_modified', self.IPSUM) + silo.node_set('shard_modified', self.IPSUM) + silo.node_set('shard_modified', self.IPSUM) + silo.node_set('shard_modified', self.IPSUM) + + dict_shard_modified = silo.db.get('shard_modified') + assert_equal(3, dict_shard_modified[self.LOREM]) + assert_equal(4, dict_shard_modified[self.IPSUM]) + + + def test_csilo_nodset_moved(self): + """Tests node_set method, in ComboxSilo class, when type is 'shard_moved'. + """ + + silo = ComboxSilo(self.config) + silo.node_set('shard_moved', self.LOREM) + silo.node_set('shard_moved', self.LOREM) + silo.node_set('shard_moved', self.LOREM) + + silo.node_set('shard_moved', self.IPSUM) + silo.node_set('shard_moved', self.IPSUM) + silo.node_set('shard_moved', self.IPSUM) + silo.node_set('shard_moved', self.IPSUM) + + dict_shard_moved = silo.db.get('shard_moved') + assert_equal(3, dict_shard_moved[self.LOREM]) + assert_equal(4, dict_shard_moved[self.IPSUM]) + + + def test_csilo_nodset_shard_deleted(self): + """Tests node_set method in ComboxSilo class, when type is 'shard_deleted'. + """ + + silo = ComboxSilo(self.config) + silo.node_set('shard_deleted', self.LOREM) + silo.node_set('shard_deleted', self.LOREM) + silo.node_set('shard_deleted', self.LOREM) + + silo.node_set('shard_deleted', self.IPSUM) + silo.node_set('shard_deleted', self.IPSUM) + silo.node_set('shard_deleted', self.IPSUM) + silo.node_set('shard_deleted', self.IPSUM) + + dict_shard_deleted = silo.db.get('shard_deleted') + assert_equal(3, dict_shard_deleted[self.LOREM]) + assert_equal(4, dict_shard_deleted[self.IPSUM]) + + + def test_csilo_nodeget(self): + """Tests node_get method in ComboxSilo class + """ + silo = ComboxSilo(self.config) + assert_equal(None, silo.node_get('shard_created', self.LOREM)) + + silo.node_set('shard_created', self.LOREM) + silo.node_set('shard_created', self.LOREM) + assert_equal(2, silo.node_get('shard_created', self.LOREM)) + + + def teardown(self): + """Cleans up things after each test in this class""" + + silo = ComboxSilo(self.config) + silo.db.deldb() + + @classmethod def teardown_class(self): """Purge the mess created by this test""" -- cgit v1.2.3