<s> import os <EOL> import json <EOL> from twisted . trial import unittest <EOL> from callsign . dns import RuntimeAuthority , Record_A <EOL> from mock import MagicMock <EOL> class TestRuntimeAuthority ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . a = RuntimeAuthority ( "<STR_LIT:foo>" , None ) <EOL> def test_a_records ( self ) : <EOL> foo_value = MagicMock ( Record_A , autospec = True ) <EOL> bar_value = MagicMock ( Record_A , autospec = True ) <EOL> foo_value . TYPE = <NUM_LIT:1> <EOL> bar_value . TYPE = <NUM_LIT:1> <EOL> foo_value . name = "<STR_LIT:foo>" <EOL> bar_value . name = "<STR_LIT:bar>" <EOL> foo_value . ttl = None <EOL> bar_value . ttl = None <EOL> foo_value . compareAttributes = ( '<STR_LIT:address>' , '<STR_LIT>' ) <EOL> bar_value . compareAttributes = ( '<STR_LIT:address>' , '<STR_LIT>' ) <EOL> foo_value . dottedQuad . return_value = "<STR_LIT>" <EOL> bar_value . dottedQuad . return_value = "<STR_LIT>" <EOL> self . a . records = { <EOL> "<STR_LIT>" : [ foo_value ] , <EOL> "<STR_LIT>" : [ bar_value ] , <EOL> } <EOL> rv = self . a . get_records_by_type ( "<STR_LIT:A>" ) <EOL> self . assertEqual ( sorted ( rv ) , [ <EOL> ( "<STR_LIT:A>" , "<STR_LIT>" , [ "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT:A>" , "<STR_LIT>" , [ "<STR_LIT>" ] ) , <EOL> ] ) <EOL> def test_txt_records ( self ) : <EOL> pass <EOL> def test_cname_records ( self ) : <EOL> pass <EOL> def test_conflict_rules ( self ) : <EOL> pass <EOL> def test_load ( self ) : <EOL> os . mkdir ( "<STR_LIT>" ) <EOL> json . dump ( ( <EOL> { "<STR_LIT:bar>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:A>" , <EOL> "<STR_LIT:address>" : "<STR_LIT>" , <EOL> } } , <EOL> { "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:A>" , <EOL> "<STR_LIT:address>" : "<STR_LIT>" , <EOL> } } , <EOL> ) , open ( "<STR_LIT>" , "<STR_LIT:w>" ) ) <EOL> self . a = RuntimeAuthority ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> self . assertEqual ( self . a . records , { <EOL> "<STR_LIT>" : [ Record_A ( address = "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ Record_A ( address = "<STR_LIT>" ) ] , <EOL> } ) <EOL> os . unlink ( "<STR_LIT>" ) <EOL> os . rmdir ( "<STR_LIT>" ) <EOL> def test_save ( self ) : <EOL> os . mkdir ( "<STR_LIT>" ) <EOL> self . a = RuntimeAuthority ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> self . a . set_record ( "<STR_LIT>" , "<STR_LIT:A>" , { '<STR_LIT:address>' : "<STR_LIT>" } , True ) <EOL> self . a . set_record ( "<STR_LIT:bar>" , "<STR_LIT:A>" , { '<STR_LIT:address>' : "<STR_LIT>" } , True ) <EOL> self . assertEqual ( json . load ( open ( "<STR_LIT>" ) ) , [ <EOL> { "<STR_LIT:bar>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:A>" , <EOL> "<STR_LIT:address>" : "<STR_LIT>" , <EOL> } } , <EOL> { "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:A>" , <EOL> "<STR_LIT:address>" : "<STR_LIT>" , <EOL> } } <EOL> ] ) </s>
