<s> import errno <EOL> import os <EOL> import unittest <EOL> import uuid <EOL> from mock import patch <EOL> from swift . common . container_sync_realms import ContainerSyncRealms <EOL> from test . unit import FakeLogger , temptree <EOL> class TestUtils ( unittest . TestCase ) : <EOL> def test_no_file_there ( self ) : <EOL> unique = uuid . uuid4 ( ) . hex <EOL> logger = FakeLogger ( ) <EOL> csr = ContainerSyncRealms ( unique , logger ) <EOL> self . assertEqual ( <EOL> logger . all_log_lines ( ) , <EOL> { '<STR_LIT>' : [ <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( unique , unique ) ] } ) <EOL> self . assertEqual ( csr . mtime_check_interval , <NUM_LIT> ) <EOL> self . assertEqual ( csr . realms ( ) , [ ] ) <EOL> def test_os_error ( self ) : <EOL> fname = '<STR_LIT>' <EOL> fcontents = '<STR_LIT>' <EOL> with temptree ( [ fname ] , [ fcontents ] ) as tempdir : <EOL> logger = FakeLogger ( ) <EOL> fpath = os . path . join ( tempdir , fname ) <EOL> def _mock_getmtime ( path ) : <EOL> raise OSError ( errno . EACCES , <EOL> os . strerror ( errno . EACCES ) + <EOL> "<STR_LIT>" % ( fpath ) ) <EOL> with patch ( '<STR_LIT>' , _mock_getmtime ) : <EOL> csr = ContainerSyncRealms ( fpath , logger ) <EOL> self . assertEqual ( <EOL> logger . all_log_lines ( ) , <EOL> { '<STR_LIT:error>' : [ <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( fpath , fpath ) ] } ) <EOL> self . assertEqual ( csr . mtime_check_interval , <NUM_LIT> ) <EOL> self . assertEqual ( csr . realms ( ) , [ ] ) <EOL> def test_empty ( self ) : <EOL> fname = '<STR_LIT>' <EOL> fcontents = '<STR_LIT>' <EOL> with temptree ( [ fname ] , [ fcontents ] ) as tempdir : <EOL> logger = FakeLogger ( ) <EOL> fpath = os . path . join ( tempdir , fname ) <EOL> csr = ContainerSyncRealms ( fpath , logger ) <EOL> self . assertEqual ( logger . all_log_lines ( ) , { } ) <EOL> self . assertEqual ( csr . mtime_check_interval , <NUM_LIT> ) <EOL> self . assertEqual ( csr . realms ( ) , [ ] ) <EOL> def test_error_parsing ( self ) : <EOL> fname = '<STR_LIT>' <EOL> fcontents = '<STR_LIT>' <EOL> with temptree ( [ fname ] , [ fcontents ] ) as tempdir : <EOL> logger = FakeLogger ( ) <EOL> fpath = os . path . join ( tempdir , fname ) <EOL> csr = ContainerSyncRealms ( fpath , logger ) <EOL> self . assertEqual ( <EOL> logger . all_log_lines ( ) , <EOL> { '<STR_LIT:error>' : [ <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( fpath , fpath ) ] } ) <EOL> self . assertEqual ( csr . mtime_check_interval , <NUM_LIT> ) <EOL> self . assertEqual ( csr . realms ( ) , [ ] ) <EOL> def test_one_realm ( self ) : <EOL> fname = '<STR_LIT>' <EOL> fcontents = '''<STR_LIT>''' <EOL> with temptree ( [ fname ] , [ fcontents ] ) as tempdir : <EOL> logger = FakeLogger ( ) <EOL> fpath = os . path . join ( tempdir , fname ) <EOL> csr = ContainerSyncRealms ( fpath , logger ) <EOL> self . assertEqual ( logger . all_log_lines ( ) , { } ) <EOL> self . assertEqual ( csr . mtime_check_interval , <NUM_LIT> ) <EOL> self . assertEqual ( csr . realms ( ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( csr . key ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( csr . key2 ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( csr . clusters ( '<STR_LIT>' ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> csr . endpoint ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_two_realms_and_change_a_default ( self ) : <EOL> fname = '<STR_LIT>' <EOL> fcontents = '''<STR_LIT>''' <EOL> with temptree ( [ fname ] , [ fcontents ] ) as tempdir : <EOL> logger = FakeLogger ( ) <EOL> fpath = os . path . join ( tempdir , fname ) <EOL> csr = ContainerSyncRealms ( fpath , logger ) <EOL> self . assertEqual ( logger . all_log_lines ( ) , { } ) <EOL> self . assertEqual ( csr . mtime_check_interval , <NUM_LIT> ) <EOL> self . assertEqual ( sorted ( csr . realms ( ) ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( csr . key ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( csr . key2 ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( csr . clusters ( '<STR_LIT>' ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> csr . endpoint ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( csr . key ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> csr . key2 ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( csr . clusters ( '<STR_LIT>' ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> csr . endpoint ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_empty_realm ( self ) : <EOL> fname = '<STR_LIT>' <EOL> fcontents = '''<STR_LIT>''' <EOL> with temptree ( [ fname ] , [ fcontents ] ) as tempdir : <EOL> logger = FakeLogger ( ) <EOL> fpath = os . path . join ( tempdir , fname ) <EOL> csr = ContainerSyncRealms ( fpath , logger ) <EOL> self . assertEqual ( logger . all_log_lines ( ) , { } ) <EOL> self . assertEqual ( csr . mtime_check_interval , <NUM_LIT> ) <EOL> self . assertEqual ( csr . realms ( ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( csr . key ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( csr . key2 ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( csr . clusters ( '<STR_LIT>' ) , [ ] ) <EOL> self . assertEqual ( csr . endpoint ( '<STR_LIT>' , '<STR_LIT>' ) , None ) <EOL> def test_bad_mtime_check_interval ( self ) : <EOL> fname = '<STR_LIT>' <EOL> fcontents = '''<STR_LIT>''' <EOL> with temptree ( [ fname ] , [ fcontents ] ) as tempdir : <EOL> logger = FakeLogger ( ) <EOL> fpath = os . path . join ( tempdir , fname ) <EOL> csr = ContainerSyncRealms ( fpath , logger ) <EOL> self . assertEqual ( <EOL> logger . all_log_lines ( ) , <EOL> { '<STR_LIT:error>' : [ <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % fpath ] } ) <EOL> self . assertEqual ( csr . mtime_check_interval , <NUM_LIT> ) <EOL> def test_get_sig ( self ) : <EOL> fname = '<STR_LIT>' <EOL> fcontents = '<STR_LIT>' <EOL> with temptree ( [ fname ] , [ fcontents ] ) as tempdir : <EOL> logger = FakeLogger ( ) <EOL> fpath = os . path . join ( tempdir , fname ) <EOL> csr = ContainerSyncRealms ( fpath , logger ) <EOL> self . assertEqual ( <EOL> csr . get_sig ( <EOL> '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
