<s> import json <EOL> import mock <EOL> import testtools <EOL> from openstack import exceptions <EOL> from openstack . message . v1 import claim <EOL> CLIENT = '<STR_LIT>' <EOL> QUEUE = '<STR_LIT>' <EOL> LIMIT = <NUM_LIT:2> <EOL> FAKE = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } <EOL> class TestClaim ( testtools . TestCase ) : <EOL> def test_basic ( self ) : <EOL> sot = claim . Claim ( ) <EOL> self . assertEqual ( '<STR_LIT>' , sot . resources_key ) <EOL> self . assertEqual ( '<STR_LIT>' , sot . base_path ) <EOL> self . assertEqual ( '<STR_LIT>' , sot . service . service_type ) <EOL> self . assertTrue ( sot . allow_create ) <EOL> self . assertFalse ( sot . allow_retrieve ) <EOL> self . assertFalse ( sot . allow_update ) <EOL> self . assertFalse ( sot . allow_delete ) <EOL> self . assertFalse ( sot . allow_list ) <EOL> def test_make_it ( self ) : <EOL> sot = claim . Claim . new ( client_id = CLIENT , <EOL> queue_name = QUEUE , <EOL> limit = LIMIT , <EOL> ** FAKE ) <EOL> self . assertEqual ( CLIENT , sot . client_id ) <EOL> self . assertEqual ( QUEUE , sot . queue_name ) <EOL> self . assertEqual ( LIMIT , sot . limit ) <EOL> self . assertEqual ( FAKE [ '<STR_LIT>' ] , sot . ttl ) <EOL> self . assertEqual ( FAKE [ '<STR_LIT>' ] , sot . grace ) <EOL> def test_create ( self ) : <EOL> sess = mock . Mock ( ) <EOL> obj = mock . Mock ( ) <EOL> fake_attrs = [ { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , { '<STR_LIT>' : '<STR_LIT>' } ] <EOL> obj . json = mock . Mock ( return_value = fake_attrs ) <EOL> sess . post = mock . Mock ( return_value = obj ) <EOL> sot = claim . Claim ( ) <EOL> c = claim . Claim . new ( client_id = CLIENT , queue_name = QUEUE , ** FAKE ) <EOL> list ( sot . claim_messages ( sess , c ) ) <EOL> url = '<STR_LIT>' % QUEUE <EOL> sess . post . assert_called_with ( <EOL> url , endpoint_filter = sot . service , <EOL> headers = { '<STR_LIT>' : CLIENT } , params = None , <EOL> data = json . dumps ( FAKE , cls = claim . ClaimEncoder ) ) <EOL> def test_claim_messages_no_invalid_response ( self ) : <EOL> sess = mock . Mock ( ) <EOL> resp = mock . Mock ( ) <EOL> resp . status_code = <NUM_LIT> <EOL> sess . post = mock . Mock ( <EOL> side_effect = exceptions . InvalidResponse ( response = resp ) ) <EOL> sot = claim . Claim ( ) <EOL> messages = list ( sot . claim_messages ( <EOL> sess , claim . Claim . new ( client_id = CLIENT , queue_name = QUEUE , ** FAKE ) ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( messages ) ) <EOL> def test_claim_messages_invalid_response ( self ) : <EOL> sess = mock . Mock ( ) <EOL> resp = mock . Mock ( ) <EOL> resp . status_code = <NUM_LIT> <EOL> sess . post = mock . Mock ( <EOL> side_effect = exceptions . InvalidResponse ( response = resp ) ) <EOL> sot = claim . Claim ( ) <EOL> try : <EOL> list ( sot . claim_messages ( <EOL> sess , claim . Claim . new ( client_id = CLIENT , <EOL> queue_name = QUEUE , <EOL> ** FAKE ) ) ) <EOL> except exceptions . InvalidResponse as e : <EOL> self . assertEqual ( <NUM_LIT> , e . response . status_code ) </s>
