<s> import os <EOL> import unittest <EOL> import itertools <EOL> import sys <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> from systestlib import DutSystemTest <EOL> class TestApiNtp ( DutSystemTest ) : <EOL> def test_get ( self ) : <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> self . assertIsNotNone ( response ) <EOL> def test_create ( self ) : <EOL> intf = '<STR_LIT>' <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . create ( intf ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] , intf ) <EOL> def test_delete ( self ) : <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . delete ( ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> self . assertIsNone ( response [ '<STR_LIT>' ] ) <EOL> def test_default ( self ) : <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . default ( ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> self . assertIsNone ( response [ '<STR_LIT>' ] ) <EOL> def test_set_source_interface ( self ) : <EOL> intf = '<STR_LIT>' <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . set_source_interface ( intf ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] , intf ) <EOL> def test_add_server_single ( self ) : <EOL> server = '<STR_LIT>' <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . add_server ( server ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> keys = [ x . keys ( ) for x in response [ '<STR_LIT>' ] ] <EOL> keys = list ( itertools . chain . from_iterable ( keys ) ) <EOL> self . assertListEqual ( keys , [ server ] ) <EOL> def test_add_server_multiple ( self ) : <EOL> servers = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> for server in servers : <EOL> response = dut . api ( '<STR_LIT>' ) . add_server ( server ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> keys = [ x . keys ( ) for x in response [ '<STR_LIT>' ] ] <EOL> keys = list ( itertools . chain . from_iterable ( keys ) ) <EOL> self . assertListEqual ( sorted ( keys ) , sorted ( servers ) ) <EOL> def test_add_server_prefer ( self ) : <EOL> server = '<STR_LIT>' <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . add_server ( server , prefer = False ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> self . assertIsNone ( response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ server ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . add_server ( server , prefer = True ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ server ] , '<STR_LIT>' ) <EOL> def test_add_server_invalid ( self ) : <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> with self . assertRaises ( ValueError ) : <EOL> dut . api ( '<STR_LIT>' ) . add_server ( None ) <EOL> dut . api ( '<STR_LIT>' ) . add_server ( '<STR_LIT>' ) <EOL> dut . api ( '<STR_LIT>' ) . add_server ( '<STR_LIT:U+0020>' ) <EOL> def test_remove_server ( self ) : <EOL> server = '<STR_LIT>' <EOL> servers = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % server ] ) <EOL> for addserver in servers : <EOL> dut . config ( [ '<STR_LIT>' % addserver ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . remove_server ( server ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> keys = [ x . keys ( ) for x in response [ '<STR_LIT>' ] ] <EOL> keys = list ( itertools . chain . from_iterable ( keys ) ) <EOL> self . assertListEqual ( sorted ( keys ) , sorted ( servers ) ) <EOL> def test_remove_all_servers ( self ) : <EOL> servers = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for dut in self . duts : <EOL> dut . config ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> for addserver in servers : <EOL> dut . config ( [ '<STR_LIT>' % addserver ] ) <EOL> response = dut . api ( '<STR_LIT>' ) . remove_all_servers ( ) <EOL> self . assertTrue ( response ) <EOL> response = dut . api ( '<STR_LIT>' ) . get ( ) <EOL> self . assertEqual ( response [ '<STR_LIT>' ] , [ ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
