def test_getByID_block(self): # ki = KeyIter('testspace', 'tt', 'app.words.Words', 'fake-id', ['position']) SO = Words('so') b = SO.split().next() new_block = getByID(b.getID()) self.assertEqual(b.getID(), new_block.getID()) self.assertEqual(b, new_block)
def test_make_persistent(self): config.session.execute("DROP TABLE IF EXISTS my_app.t_make_words") nopars = Words() self.assertFalse(nopars._is_persistent) nopars.ciao = 1 nopars.ciao2 = "1" nopars.ciao3 = [1, 2, 3] nopars.ciao4 = (1, 2, 3) for i in range(10): nopars.words[i] = 'ciao' + str(i) count, = config.session.execute( "SELECT count(*) FROM system_schema.tables WHERE keyspace_name = 'my_app' and table_name = 't_make_words'" )[0] self.assertEqual(0, count) nopars.make_persistent("t_make") del nopars count, = config.session.execute( 'SELECT count(*) FROM my_app.t_make_words')[0] self.assertEqual(10, count)
def test_make_persistent(self): config.session.execute("DROP TABLE IF EXISTS hecuba_test.wordsso") config.session.execute("DROP TABLE IF EXISTS hecuba_test.nonames") config.session.execute("DROP TABLE IF EXISTS hecuba_test.words") config.session.execute("DROP TABLE IF EXISTS hecuba_test.wordsso_words") config.session.execute("DROP TABLE IF EXISTS hecuba_test.nonames_test3") nopars = Words() self.assertFalse(nopars._is_persistent) nopars.ciao = 1 nopars.ciao2 = "1" nopars.ciao3 = [1, 2, 3] nopars.ciao4 = (1, 2, 3) for i in range(10): nopars.words[i] = 'ciao' + str(i) count, = config.session.execute( "SELECT count(*) FROM system_schema.tables WHERE keyspace_name = 'hecuba_test' and table_name = 'words'")[0] self.assertEqual(0, count) nopars.make_persistent("hecuba_test.wordsso") count, = config.session.execute('SELECT count(*) FROM hecuba_test.wordsso_words')[0] self.assertEqual(10, count) nopars2 = Test6StorageObj("hecuba_test.nonames") nopars2.test3[0] = '1', '2' time.sleep(2) result = config.session.execute("SELECT val0, val1 FROM hecuba_test.nonames_test3 WHERE key0 = 0") rval0 = None rval1 = None for row in result: rval0 = row.val0 rval1 = row.val1 self.assertEqual('1', rval0) self.assertEqual('2', rval1)
def test_init(self): # still in development config.session.execute = Mock(return_value=None) nopars = Words() config.session.execute.assert_not_called()
def test_empty_persistent(self): config.session.execute("DROP TABLE IF EXISTS my_app.wordsso_words") config.session.execute("DROP TABLE IF EXISTS my_app.wordsso") from app.words import Words so = Words() so.make_persistent("wordsso") so.ciao = "an attribute" so.another = 123 config.batch_size = 1 config.cache_activated = False for i in range(10): so.words[i] = str.join(',', map(lambda a: "ciao", range(i))) del so count, = config.session.execute( 'SELECT count(*) FROM my_app.wordsso_words')[0] self.assertEqual(10, count) so = Words("wordsso") so.delete_persistent() so.words.delete_persistent() count, = config.session.execute( 'SELECT count(*) FROM my_app.wordsso_words')[0] self.assertEqual(0, count)
def test_getByID_storage_obj(self): b = Words('testspace.tt') new_block = getByID(b.getID()) self.assertEqual(b, new_block)