<s> from uuid import uuid4 <EOL> from urllib import quote <EOL> from changes . constants import Cause , Result <EOL> from changes . testutils import APITestCase <EOL> class ProjectBuildListTest ( APITestCase ) : <EOL> def test_simple ( self ) : <EOL> fake_project_id = uuid4 ( ) <EOL> project = self . create_project ( ) <EOL> self . create_build ( project ) <EOL> project1 = self . create_project ( ) <EOL> build1 = self . create_build ( project1 , label = '<STR_LIT:test>' , target = '<STR_LIT>' , <EOL> result = Result . passed ) <EOL> project2 = self . create_project ( ) <EOL> build2 = self . create_build ( project2 , label = '<STR_LIT:test>' , target = '<STR_LIT>' , tags = [ '<STR_LIT:foo>' ] , <EOL> result = Result . failed ) <EOL> path = '<STR_LIT>' . format ( fake_project_id . hex ) <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT> <EOL> path = '<STR_LIT>' . format ( project1 . id . hex ) <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build1 . id . hex <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build1 . id . hex <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build1 . id . hex <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build1 . id . hex <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:0> <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build1 . id . hex <EOL> path = '<STR_LIT>' . format ( project2 . id . hex ) <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build2 . id . hex <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:0> <EOL> build3 = self . create_build ( project2 , label = '<STR_LIT:test>' , target = '<STR_LIT>' , tags = [ '<STR_LIT:bar>' ] , <EOL> result = Result . failed ) <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build2 . id . hex <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build3 . id . hex <EOL> def test_more_searches ( self ) : <EOL> project1 = self . create_project ( ) <EOL> build1 = self . create_build ( project1 , label = '<STR_LIT>' , <EOL> target = '<STR_LIT>' ) <EOL> build2 = self . create_build ( project1 , label = '<STR_LIT>' , <EOL> target = '<STR_LIT>' ) <EOL> build3 = self . create_build ( project1 , label = '<STR_LIT>' , <EOL> target = '<STR_LIT>' ) <EOL> path = '<STR_LIT>' . format ( project1 . id . hex ) <EOL> queries_to_results = [ <EOL> ( "<STR_LIT>" , [ build1 ] ) , <EOL> ( "<STR_LIT>" , [ build3 ] ) , <EOL> ( "<STR_LIT>" , [ ] ) , <EOL> ( "<STR_LIT>" , [ build1 , build2 , build3 ] ) , <EOL> ( "<STR_LIT>" , [ build1 ] ) , <EOL> ( "<STR_LIT>" , [ build2 ] ) , <EOL> ( "<STR_LIT>" , [ build3 ] ) , <EOL> ( "<STR_LIT>" , [ ] ) , <EOL> ( "<STR_LIT>" , [ build1 ] ) , <EOL> ( "<STR_LIT>" , [ build2 ] ) , <EOL> ( "<STR_LIT>" , [ build3 ] ) , <EOL> ] <EOL> errmsg = "<STR_LIT>" <EOL> for term , expected_builds in queries_to_results : <EOL> resp = self . client . get ( path + '<STR_LIT>' + term ) <EOL> assert resp . status_code == <NUM_LIT:200> , errmsg % term <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == len ( expected_builds ) , errmsg . format ( term ) <EOL> assert set ( [ d [ '<STR_LIT:id>' ] for d in data ] ) == set ( [ b . id . hex for b in expected_builds ] ) , errmsg % term <EOL> def test_include_patches ( self ) : <EOL> project = self . create_project ( ) <EOL> patch = self . create_patch ( repository = project . repository ) <EOL> source = self . create_source ( project , patch = patch ) <EOL> build = self . create_build ( project ) <EOL> self . create_build ( project , source = source ) <EOL> path = '<STR_LIT>' . format ( <EOL> project . id . hex ) <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build . id . hex <EOL> path = '<STR_LIT>' . format ( <EOL> project . id . hex ) <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:2> <EOL> def test_patches_only ( self ) : <EOL> project = self . create_project ( ) <EOL> patch = self . create_patch ( repository = project . repository ) <EOL> source = self . create_source ( project , patch = patch ) <EOL> self . create_build ( project ) <EOL> patch_build = self . create_build ( project , source = source ) <EOL> path = '<STR_LIT>' . format ( <EOL> project . id . hex ) <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == patch_build . id . hex <EOL> def test_by_cause ( self ) : <EOL> project = self . create_project ( ) <EOL> patch = self . create_patch ( repository = project . repository ) <EOL> source = self . create_source ( project , patch = patch ) <EOL> self . create_build ( project ) <EOL> push_build = self . create_build ( project , source = source , cause = Cause . push ) <EOL> push_build2 = self . create_build ( project , source = source , cause = Cause . push ) <EOL> snapshot_build = self . create_build ( project , source = source , cause = Cause . snapshot ) <EOL> snapshot_path = '<STR_LIT>' . format ( <EOL> project . id . hex ) <EOL> push_path = '<STR_LIT>' . format ( <EOL> project . id . hex ) <EOL> resp = self . client . get ( snapshot_path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == snapshot_build . id . hex <EOL> resp = self . client . get ( push_path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:2> <EOL> push_build_ids = [ push_build . id . hex , push_build2 . id . hex ] <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] in push_build_ids <EOL> assert data [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] in push_build_ids <EOL> def test_author ( self ) : <EOL> project = self . create_project ( ) <EOL> patch = self . create_patch ( repository = project . repository ) <EOL> source = self . create_source ( project , patch = patch ) <EOL> author = self . create_author ( email = self . default_user . email ) <EOL> build = self . create_build ( project , author = author ) <EOL> self . create_build ( project , source = source ) <EOL> path = '<STR_LIT>' . format ( project . id . hex ) <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> , resp . data <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:0> <EOL> resp = self . client . get ( <EOL> path + '<STR_LIT>' + quote ( self . default_user . email ) ) <EOL> assert resp . status_code == <NUM_LIT:200> , resp . data <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build . id . hex <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT> , resp . data <EOL> self . login_default ( ) <EOL> resp = self . client . get ( path + '<STR_LIT>' ) <EOL> assert resp . status_code == <NUM_LIT:200> , resp . data <EOL> data = self . unserialize ( resp ) <EOL> assert len ( data ) == <NUM_LIT:1> <EOL> assert data [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] == build . id . hex </s>
