<s> from unittest import TestCase <EOL> import tempfile <EOL> import os <EOL> import shutil <EOL> from biicode . client . store . localdb import LocalDB , DEP_TABLES <EOL> from biicode . common . test . conf import BII_TEST_FOLDER <EOL> from biicode . common . model . symbolic . reference import References , ReferencedResources <EOL> from biicode . common . model . brl . cell_name import CellName <EOL> from biicode . common . model . resource import Resource <EOL> from nose . plugins . attrib import attr <EOL> from biicode . common . model . symbolic . block_version_table import BlockVersionTable <EOL> from biicode . common . model . brl . brl_block import BRLBlock <EOL> from biicode . common . model . cells import SimpleCell , VirtualCell <EOL> from biicode . common . model . blob import Blob <EOL> from biicode . common . model . content import Content <EOL> from biicode . common . model . id import ID <EOL> from biicode . common . model . symbolic . block_version import BlockVersion <EOL> from biicode . client . store . sqlite import encode_serialized_value <EOL> from biicode . common . exception import NotInStoreException <EOL> @ attr ( '<STR_LIT>' ) <EOL> class LocalDBTest ( TestCase ) : <EOL> _suites = [ '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> self . hiveFolder = tempfile . mkdtemp ( suffix = '<STR_LIT>' , dir = BII_TEST_FOLDER ) <EOL> self . db = LocalDB ( os . path . join ( self . hiveFolder , '<STR_LIT>' ) ) <EOL> def tearDown ( self ) : <EOL> if os . path . isdir ( self . hiveFolder ) : <EOL> self . db . disconnect ( ) <EOL> shutil . rmtree ( self . hiveFolder ) <EOL> def test_not_logged_in ( self ) : <EOL> user = self . db . get_login ( ) <EOL> self . assertEquals ( user , ( None , None ) ) <EOL> def test_logged_in ( self ) : <EOL> user = "<STR_LIT>" , "<STR_LIT>" <EOL> self . db . set_login ( user ) <EOL> user2 = self . db . get_login ( ) <EOL> self . assertEquals ( user , user2 ) <EOL> def test_store_published_resources ( self ) : <EOL> s = References ( ) <EOL> brl_block = BRLBlock ( '<STR_LIT>' ) <EOL> block_version = BlockVersion ( brl_block , <NUM_LIT:0> ) <EOL> s [ block_version ] = [ CellName ( "<STR_LIT>" ) , CellName ( "<STR_LIT>" ) , <EOL> CellName ( '<STR_LIT>' ) , CellName ( '<STR_LIT>' ) , CellName ( '<STR_LIT>' ) ] <EOL> alf = Resource ( SimpleCell ( "<STR_LIT>" ) , <EOL> Content ( ID ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) ) , Blob ( "<STR_LIT>" ) ) ) <EOL> alf . cell . ID = ID ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> willy = Resource ( SimpleCell ( "<STR_LIT>" ) , <EOL> Content ( ID ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ) ) , Blob ( "<STR_LIT>" ) ) ) <EOL> willy . cell . ID = ID ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> maya_v = Resource ( VirtualCell ( "<STR_LIT>" ) , None ) <EOL> maya_v . cell . ID = ID ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> maya_win = Resource ( SimpleCell ( "<STR_LIT>" ) , <EOL> Content ( ID ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> ) ) , Blob ( "<STR_LIT>" ) ) ) <EOL> maya_win . cell . ID = ID ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> ) ) <EOL> maya_nix = Resource ( SimpleCell ( "<STR_LIT>" ) , <EOL> Content ( ID ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:5> ) ) , Blob ( "<STR_LIT>" ) ) ) <EOL> maya_nix . cell . ID = ID ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:5> ) ) <EOL> referenced_resources = ReferencedResources ( ) <EOL> referenced_resources [ block_version ] . update ( { CellName ( "<STR_LIT>" ) : alf , <EOL> CellName ( "<STR_LIT>" ) : willy , <EOL> CellName ( '<STR_LIT>' ) : maya_v , <EOL> CellName ( '<STR_LIT>' ) : maya_win , <EOL> CellName ( '<STR_LIT>' ) : maya_nix , <EOL> } ) <EOL> self . db . create_published_resources ( referenced_resources ) <EOL> retrieved = self . db . get_published_resources ( s ) <EOL> self . assertEquals ( referenced_resources , retrieved ) <EOL> def test_store_snapshot ( self ) : <EOL> original_snap = [ CellName ( "<STR_LIT>" ) , CellName ( "<STR_LIT>" ) ] <EOL> brl_block = BRLBlock ( '<STR_LIT>' ) <EOL> block_version = BlockVersion ( brl_block , <NUM_LIT:0> ) <EOL> self . db . create_cells_snapshot ( block_version , original_snap ) <EOL> retrieved_snap = self . db . get_cells_snapshot ( block_version ) <EOL> self . assertEquals ( original_snap , retrieved_snap ) <EOL> def test_store_dep_table ( self ) : <EOL> original_deptable = BlockVersionTable ( ) <EOL> brl_block = BRLBlock ( '<STR_LIT>' ) <EOL> block_version = BlockVersion ( brl_block , <NUM_LIT:0> ) <EOL> self . db . set_dep_table ( block_version , original_deptable ) <EOL> retrieved_snap = self . db . get_dep_table ( block_version ) <EOL> self . assertEquals ( original_deptable , retrieved_snap ) <EOL> def test_delete_dep_table ( self ) : <EOL> original_deptable = BlockVersionTable ( ) <EOL> brl_block = BRLBlock ( '<STR_LIT>' ) <EOL> block_version = BlockVersion ( brl_block , <NUM_LIT:0> ) <EOL> self . db . set_dep_table ( block_version , original_deptable ) <EOL> ID = encode_serialized_value ( block_version . serialize ( ) ) <EOL> self . db . delete ( ID , DEP_TABLES ) <EOL> self . assertRaises ( NotInStoreException , self . db . get_dep_table , block_version ) </s>
