<s> from uuid import uuid4 <EOL> from mock import patch <EOL> from oslo_serialization import jsonutils <EOL> from nailgun . db . sqlalchemy . models import Release <EOL> from nailgun . test . base import BaseIntegrationTest <EOL> from nailgun . utils import reverse <EOL> class TestHandlers ( BaseIntegrationTest ) : <EOL> def test_release_list_empty ( self ) : <EOL> resp = self . app . get ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> headers = self . default_headers <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:200> , resp . status_code ) <EOL> self . assertEqual ( [ ] , resp . json_body ) <EOL> def test_release_creation ( self ) : <EOL> resp = self . app . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> params = jsonutils . dumps ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT:1.0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> headers = self . default_headers <EOL> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> def test_release_create ( self ) : <EOL> release_name = "<STR_LIT>" <EOL> release_version = "<STR_LIT>" <EOL> release_description = "<STR_LIT>" <EOL> resp = self . app . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> jsonutils . dumps ( { <EOL> '<STR_LIT:name>' : release_name , <EOL> '<STR_LIT:version>' : release_version , <EOL> '<STR_LIT:description>' : release_description , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> } , <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } ) , <EOL> headers = self . default_headers <EOL> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> resp = self . app . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> jsonutils . dumps ( { <EOL> '<STR_LIT:name>' : release_name , <EOL> '<STR_LIT:version>' : release_version , <EOL> '<STR_LIT:description>' : release_description , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } ) , <EOL> headers = self . default_headers , <EOL> expect_errors = True <EOL> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> release_from_db = self . db . query ( Release ) . filter_by ( <EOL> name = release_name , <EOL> version = release_version , <EOL> description = release_description <EOL> ) . all ( ) <EOL> self . assertEqual ( len ( release_from_db ) , <NUM_LIT:1> ) <EOL> def test_release_create_already_exist ( self ) : <EOL> release_name = "<STR_LIT>" <EOL> release_version = "<STR_LIT>" <EOL> release_description = "<STR_LIT>" <EOL> resp = self . app . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> jsonutils . dumps ( { <EOL> '<STR_LIT:name>' : release_name , <EOL> '<STR_LIT:version>' : release_version , <EOL> '<STR_LIT:description>' : release_description , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> } , <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } ) , <EOL> headers = self . default_headers <EOL> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> resp = self . app . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> jsonutils . dumps ( { <EOL> '<STR_LIT:name>' : release_name , <EOL> '<STR_LIT:version>' : release_version , <EOL> '<STR_LIT:description>' : release_description , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } ) , <EOL> headers = self . default_headers , <EOL> expect_errors = True <EOL> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> class ReleaseCollectionSortBaseTest ( BaseIntegrationTest ) : <EOL> releases = [ ] <EOL> expected = [ ] <EOL> def setUp ( self ) : <EOL> super ( ReleaseCollectionSortBaseTest , self ) . setUp ( ) <EOL> for r in self . releases : <EOL> self . env . create_release ( ** { <EOL> '<STR_LIT:version>' : r [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : r [ <NUM_LIT:1> ] , <EOL> '<STR_LIT:name>' : '<STR_LIT>' . format ( uuid4 ( ) ) <EOL> } ) <EOL> def test_release_collection_order ( self ) : <EOL> resp = self . app . get ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> headers = self . default_headers <EOL> ) . json_body <EOL> actual = [ ( r [ '<STR_LIT:version>' ] , r [ '<STR_LIT>' ] ) for r in resp ] <EOL> self . assertEqual ( actual , self . expected ) <EOL> @ patch ( '<STR_LIT>' , <EOL> dict . fromkeys ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) ) <EOL> class TestReleaseCollectionSortingAllCriteria ( ReleaseCollectionSortBaseTest ) : <EOL> releases = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ] <EOL> expected = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] <EOL> class TestReleaseCollectionSortByFuelVersion ( ReleaseCollectionSortBaseTest ) : <EOL> releases = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] <EOL> expected = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] <EOL> class TestReleaseCollectionSortByOpenstack ( ReleaseCollectionSortBaseTest ) : <EOL> releases = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] <EOL> expected = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] <EOL> @ patch ( '<STR_LIT>' , <EOL> dict . fromkeys ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) ) <EOL> class TestReleaseCollectionSortByOS ( ReleaseCollectionSortBaseTest ) : <EOL> releases = [ <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ] <EOL> expected = [ <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:X>" , "<STR_LIT>" ) , <EOL> ] </s>
