<s> from urlparse import urlparse <EOL> from nose . tools import * <EOL> from api . base . settings . defaults import API_BASE <EOL> from tests . base import ApiTestCase <EOL> from tests . factories import ( <EOL> ProjectFactory , <EOL> RegistrationFactory , <EOL> AuthUserFactory , <EOL> RetractedRegistrationFactory <EOL> ) <EOL> class TestRegistrationDetail ( ApiTestCase ) : <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> super ( TestRegistrationDetail , self ) . setUp ( ) <EOL> self . user = AuthUserFactory ( ) <EOL> self . user_two = AuthUserFactory ( ) <EOL> self . public_project = ProjectFactory ( title = "<STR_LIT>" , is_public = True , creator = self . user ) <EOL> self . private_project = ProjectFactory ( title = "<STR_LIT>" , is_public = False , creator = self . user ) <EOL> self . public_registration = RegistrationFactory ( project = self . public_project , creator = self . user , is_public = True ) <EOL> self . private_registration = RegistrationFactory ( project = self . private_project , creator = self . user ) <EOL> self . public_url = '<STR_LIT>' . format ( API_BASE , self . public_registration . _id ) <EOL> self . private_url = '<STR_LIT>' . format ( API_BASE , self . private_registration . _id ) <EOL> self . retraction_registration = RegistrationFactory ( creator = self . user , project = self . public_project , public = True ) <EOL> self . retraction_url = '<STR_LIT>' . format ( API_BASE , self . retraction_registration . _id ) <EOL> retraction = RetractedRegistrationFactory ( registration = self . retraction_registration , user = self . retraction_registration . creator ) <EOL> retraction . justification = '<STR_LIT>' <EOL> retraction . save ( ) <EOL> def test_return_public_registration_details_logged_out ( self ) : <EOL> res = self . app . get ( self . public_url ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> registered_from = urlparse ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) . path <EOL> assert_equal ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , True ) <EOL> assert_equal ( registered_from , '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) ) <EOL> def test_return_public_registration_details_logged_in ( self ) : <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( res . content_type , '<STR_LIT>' ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> registered_from = urlparse ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) . path <EOL> assert_equal ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , True ) <EOL> assert_equal ( registered_from , '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) ) <EOL> def test_return_private_registration_details_logged_out ( self ) : <EOL> res = self . app . get ( self . private_url , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_in ( '<STR_LIT>' , res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_return_private_project_registrations_logged_in_contributor ( self ) : <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( res . content_type , '<STR_LIT>' ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> registered_from = urlparse ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) . path <EOL> assert_equal ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , True ) <EOL> assert_equal ( registered_from , '<STR_LIT>' . format ( API_BASE , self . private_project . _id ) ) <EOL> def test_return_private_registration_details_logged_in_non_contributor ( self ) : <EOL> res = self . app . get ( self . private_url , auth = self . user_two . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_in ( '<STR_LIT>' , res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_do_not_return_node_detail ( self ) : <EOL> url = '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) <EOL> res = self . app . get ( url , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_do_not_return_node_detail_in_sub_view ( self ) : <EOL> url = '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) <EOL> res = self . app . get ( url , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_do_not_return_registration_in_node_detail ( self ) : <EOL> url = '<STR_LIT>' . format ( API_BASE , self . public_registration . _id ) <EOL> res = self . app . get ( url , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_retractions_display_limited_fields ( self ) : <EOL> registration = self . retraction_registration <EOL> res = self . app . get ( self . retraction_url , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> attributes = res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> expected_attributes = { <EOL> '<STR_LIT:title>' : registration . title , <EOL> '<STR_LIT:description>' : registration . description , <EOL> '<STR_LIT>' : registration . date_created , <EOL> '<STR_LIT>' : registration . registered_date , <EOL> '<STR_LIT>' : registration . retraction . justification , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : registration . registered_meta . keys ( ) [ <NUM_LIT:0> ] <EOL> } <EOL> assert_items_equal ( attributes , expected_attributes ) <EOL> contributors = urlparse ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) . path <EOL> assert_equal ( contributors , '<STR_LIT>' . format ( API_BASE , registration . _id ) ) <EOL> assert_not_in ( '<STR_LIT>' , res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> assert_not_in ( '<STR_LIT>' , res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> assert_not_in ( '<STR_LIT>' , res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> assert_not_in ( '<STR_LIT>' , res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> assert_not_in ( '<STR_LIT>' , res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> assert_not_in ( '<STR_LIT>' , res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> assert_not_in ( '<STR_LIT>' , res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> assert_not_in ( '<STR_LIT>' , res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> def test_registration_shows_specific_related_counts ( self ) : <EOL> url = '<STR_LIT>' . format ( API_BASE , self . private_registration . _id ) <EOL> res = self . app . get ( url , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:count>' ] , <NUM_LIT:0> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , { } ) <EOL> def test_field_specific_related_counts_ignored_if_hidden_field_on_retraction ( self ) : <EOL> url = '<STR_LIT>' . format ( API_BASE , self . retraction_registration . _id ) <EOL> res = self . app . get ( url , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_not_in ( '<STR_LIT>' , res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> def test_field_specific_related_counts_retrieved_if_visible_field_on_retraction ( self ) : <EOL> url = '<STR_LIT>' . format ( API_BASE , self . retraction_registration . _id ) <EOL> res = self . app . get ( url , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:count>' ] , <NUM_LIT:1> ) </s>
