<s> from nose . tools import * <EOL> from api . base . settings . defaults import API_BASE <EOL> from website . models import NodeLog <EOL> from framework . auth . core import Auth <EOL> from tests . base import ApiTestCase <EOL> from tests . factories import ( <EOL> ProjectFactory , <EOL> AuthUserFactory , <EOL> UserFactory , <EOL> RegistrationFactory , <EOL> RetractedRegistrationFactory <EOL> ) <EOL> from tests . utils import assert_logs <EOL> from website . util import permissions <EOL> class NodeCRUDTestCase ( ApiTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( NodeCRUDTestCase , self ) . setUp ( ) <EOL> self . user = AuthUserFactory ( ) <EOL> self . user_two = AuthUserFactory ( ) <EOL> self . title = '<STR_LIT>' <EOL> self . new_title = '<STR_LIT>' <EOL> self . description = '<STR_LIT>' <EOL> self . new_description = '<STR_LIT>' <EOL> self . category = '<STR_LIT:data>' <EOL> self . new_category = '<STR_LIT>' <EOL> self . public_project = ProjectFactory ( title = self . title , <EOL> description = self . description , <EOL> category = self . category , <EOL> is_public = True , <EOL> creator = self . user ) <EOL> self . public_url = '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) <EOL> self . private_project = ProjectFactory ( title = self . title , <EOL> description = self . description , <EOL> category = self . category , <EOL> is_public = False , <EOL> creator = self . user ) <EOL> self . private_url = '<STR_LIT>' . format ( API_BASE , self . private_project . _id ) <EOL> self . fake_url = '<STR_LIT>' . format ( API_BASE , '<STR_LIT>' ) <EOL> def make_node_payload ( node , attributes ) : <EOL> return { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : node . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : attributes , <EOL> } <EOL> } <EOL> class TestNodeContributorList ( NodeCRUDTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNodeContributorList , self ) . setUp ( ) <EOL> self . private_url = '<STR_LIT>' . format ( API_BASE , self . private_project . _id ) <EOL> self . public_url = '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) <EOL> def test_return_public_contributor_list_logged_out ( self ) : <EOL> self . public_project . add_contributor ( self . user_two , save = True ) <EOL> res = self . app . get ( self . public_url ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( res . content_type , '<STR_LIT>' ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:2> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , self . user . _id ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> def test_return_public_contributor_list_logged_in ( self ) : <EOL> res = self . app . get ( self . public_url , auth = self . user_two . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( res . content_type , '<STR_LIT>' ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , self . user . _id ) <EOL> def test_return_private_contributor_list_logged_out ( self ) : <EOL> res = self . app . get ( self . private_url , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert '<STR_LIT>' in res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> def test_return_private_contributor_list_logged_in_contributor ( self ) : <EOL> self . private_project . add_contributor ( self . user_two ) <EOL> self . private_project . save ( ) <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> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:2> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , self . user . _id ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> def test_return_private_contributor_list_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 '<STR_LIT>' in res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> def test_can_not_access_retracted_contributors ( self ) : <EOL> registration = RegistrationFactory ( creator = self . user , project = self . public_project ) <EOL> url = '<STR_LIT>' . format ( API_BASE , registration . _id ) <EOL> retraction = RetractedRegistrationFactory ( registration = registration , user = registration . creator ) <EOL> res = self . app . get ( url , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_filtering_on_obsolete_fields ( self ) : <EOL> url_fullname = '<STR_LIT>' . format ( self . public_url ) <EOL> res = self . app . get ( url_fullname , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> errors = res . json [ '<STR_LIT>' ] <EOL> assert_equal ( len ( errors ) , <NUM_LIT:1> ) <EOL> assert_equal ( errors [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , u"<STR_LIT>" ) <EOL> url_middle_name = '<STR_LIT>' . format ( self . public_url ) <EOL> res = self . app . get ( url_middle_name , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> errors = res . json [ '<STR_LIT>' ] <EOL> assert_equal ( len ( errors ) , <NUM_LIT:1> ) <EOL> assert_equal ( errors [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_disabled_contributors_contain_names_under_meta ( self ) : <EOL> self . public_project . add_contributor ( self . user_two , save = True ) <EOL> self . user_two . is_disabled = True <EOL> self . user_two . save ( ) <EOL> res = self . app . get ( self . public_url ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( res . content_type , '<STR_LIT>' ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:2> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , self . user . _id ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . user_two . fullname ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> class TestNodeContributorFiltering ( ApiTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNodeContributorFiltering , self ) . setUp ( ) <EOL> self . user = AuthUserFactory ( ) <EOL> self . project = ProjectFactory ( creator = self . user ) <EOL> def test_filtering_full_name_field ( self ) : <EOL> url = '<STR_LIT>' . format ( API_BASE , self . project . _id ) <EOL> res = self . app . get ( url , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> errors = res . json [ '<STR_LIT>' ] <EOL> assert_equal ( len ( errors ) , <NUM_LIT:1> ) <EOL> assert_equal ( errors [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_filtering_permission_field ( self ) : <EOL> url = '<STR_LIT>' . format ( API_BASE , self . project . _id ) <EOL> res = self . app . get ( url , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_filtering_node_with_only_bibliographic_contributors ( self ) : <EOL> base_url = '<STR_LIT>' . format ( API_BASE , self . project . _id ) <EOL> res = self . app . get ( base_url , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> url = base_url + '<STR_LIT>' <EOL> res = self . app . get ( url , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> assert_true ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] . get ( '<STR_LIT>' , None ) ) <EOL> url = base_url + '<STR_LIT>' <EOL> res = self . app . get ( url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:0> ) <EOL> def test_filtering_node_with_non_bibliographic_contributor ( self ) : <EOL> non_bibliographic_contrib = UserFactory ( ) <EOL> self . project . add_contributor ( non_bibliographic_contrib , visible = False ) <EOL> self . project . save ( ) <EOL> base_url = '<STR_LIT>' . format ( API_BASE , self . project . _id ) <EOL> res = self . app . get ( base_url , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:2> ) <EOL> url = base_url + '<STR_LIT>' <EOL> res = self . app . get ( url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> assert_true ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] . get ( '<STR_LIT>' , None ) ) <EOL> url = base_url + '<STR_LIT>' <EOL> res = self . app . get ( url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> assert_false ( res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] . get ( '<STR_LIT>' , None ) ) <EOL> def test_filtering_on_invalid_field ( self ) : <EOL> url = '<STR_LIT>' . format ( API_BASE , self . project . _id ) <EOL> res = self . app . get ( url , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> errors = res . json [ '<STR_LIT>' ] <EOL> assert_equal ( len ( errors ) , <NUM_LIT:1> ) <EOL> assert_equal ( errors [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> class TestNodeContributorAdd ( NodeCRUDTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNodeContributorAdd , self ) . setUp ( ) <EOL> self . private_url = '<STR_LIT>' . format ( API_BASE , self . private_project . _id ) <EOL> self . public_url = '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) <EOL> self . user_three = AuthUserFactory ( ) <EOL> self . data_user_two = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> self . data_user_three = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : self . user_three . _id , <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> def test_add_node_contributors_relationships_is_a_list ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : self . user_three . _id } ] <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , 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_contributor_create_invalid_data ( self ) : <EOL> res = self . app . post_json_api ( self . public_url , "<STR_LIT>" , auth = self . user_three . 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> res = self . app . post_json_api ( self . public_url , [ "<STR_LIT>" ] , auth = self . user_three . 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_add_contributor_no_relationships ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , 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:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_add_contributor_empty_relationships ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_add_contributor_no_user_key_in_relationships ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , 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_add_contributor_no_data_in_relationships ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , 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_add_contributor_no_target_type_in_relationships ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , 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_add_contributor_no_target_id_in_relationships ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , 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:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_add_contributor_incorrect_target_id_in_relationships ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_add_contributor_incorrect_target_type_in_relationships ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : self . user_two . _id <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_add_contributor_no_type ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , 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:source>' ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_add_contributor_incorrect_type ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , data , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> @ assert_logs ( NodeLog . CONTRIB_ADDED , '<STR_LIT>' ) <EOL> def test_add_contributor_is_visible_by_default ( self ) : <EOL> del self . data_user_two [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> res = self . app . post_json_api ( self . public_url , self . data_user_two , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> self . public_project . reload ( ) <EOL> assert_in ( self . user_two , self . public_project . contributors ) <EOL> assert_true ( self . public_project . get_visible ( self . user_two ) ) <EOL> @ assert_logs ( NodeLog . CONTRIB_ADDED , '<STR_LIT>' ) <EOL> def test_adds_bibliographic_contributor_public_project_admin ( self ) : <EOL> res = self . app . post_json_api ( self . public_url , self . data_user_two , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> self . public_project . reload ( ) <EOL> assert_in ( self . user_two , self . public_project . contributors ) <EOL> @ assert_logs ( NodeLog . CONTRIB_ADDED , '<STR_LIT>' ) <EOL> def test_adds_non_bibliographic_contributor_private_project_admin ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . private_url , data , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , False ) <EOL> self . private_project . reload ( ) <EOL> assert_in ( self . user_two , self . private_project . contributors ) <EOL> assert_false ( self . private_project . get_visible ( self . user_two ) ) <EOL> def test_adds_contributor_public_project_non_admin ( self ) : <EOL> self . public_project . add_contributor ( self . user_two , permissions = [ permissions . READ , permissions . WRITE ] , auth = Auth ( self . user ) , save = True ) <EOL> res = self . app . post_json_api ( self . public_url , self . data_user_three , <EOL> auth = self . user_two . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> self . public_project . reload ( ) <EOL> assert_not_in ( self . user_three , self . public_project . contributors ) <EOL> def test_adds_contributor_public_project_non_contributor ( self ) : <EOL> res = self . app . post_json_api ( self . public_url , self . data_user_three , <EOL> auth = self . user_two . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_not_in ( self . user_three , self . public_project . contributors ) <EOL> def test_adds_contributor_public_project_not_logged_in ( self ) : <EOL> res = self . app . post_json_api ( self . public_url , self . data_user_two , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_not_in ( self . user_two , self . public_project . contributors ) <EOL> @ assert_logs ( NodeLog . CONTRIB_ADDED , '<STR_LIT>' ) <EOL> def test_adds_contributor_private_project_admin ( self ) : <EOL> res = self . app . post_json_api ( self . private_url , self . data_user_two , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> self . private_project . reload ( ) <EOL> assert_in ( self . user_two , self . private_project . contributors ) <EOL> @ assert_logs ( NodeLog . CONTRIB_ADDED , '<STR_LIT>' ) <EOL> def test_adds_contributor_without_bibliographic_private_project_admin ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . private_url , data , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> self . private_project . reload ( ) <EOL> assert_in ( self . user_two , self . private_project . contributors ) <EOL> @ assert_logs ( NodeLog . CONTRIB_ADDED , '<STR_LIT>' ) <EOL> def test_adds_admin_contributor_private_project_admin ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : permissions . ADMIN <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . private_url , data , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> self . private_project . reload ( ) <EOL> assert_in ( self . user_two , self . private_project . contributors ) <EOL> assert_equal ( self . private_project . get_permissions ( self . user_two ) , [ permissions . READ , permissions . WRITE , permissions . ADMIN ] ) <EOL> @ assert_logs ( NodeLog . CONTRIB_ADDED , '<STR_LIT>' ) <EOL> def test_adds_write_contributor_private_project_admin ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : permissions . WRITE <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . private_url , data , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> self . private_project . reload ( ) <EOL> assert_in ( self . user_two , self . private_project . contributors ) <EOL> assert_equal ( self . private_project . get_permissions ( self . user_two ) , [ permissions . READ , permissions . WRITE ] ) <EOL> @ assert_logs ( NodeLog . CONTRIB_ADDED , '<STR_LIT>' ) <EOL> def test_adds_read_contributor_private_project_admin ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : permissions . READ <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . private_url , data , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT:data>' ] [ '<STR_LIT:id>' ] , self . user_two . _id ) <EOL> self . private_project . reload ( ) <EOL> assert_in ( self . user_two , self . private_project . contributors ) <EOL> assert_equal ( self . private_project . get_permissions ( self . user_two ) , [ permissions . READ ] ) <EOL> def test_adds_invalid_permission_contributor_private_project_admin ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . private_url , data , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> self . private_project . reload ( ) <EOL> assert_not_in ( self . user_two , self . private_project . contributors ) <EOL> @ assert_logs ( NodeLog . CONTRIB_ADDED , '<STR_LIT>' ) <EOL> def test_adds_none_permission_contributor_private_project_admin_uses_default_permissions ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : None <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . private_url , data , auth = self . user . auth ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> self . private_project . reload ( ) <EOL> assert_in ( self . user_two , self . private_project . contributors ) <EOL> for permission in permissions . DEFAULT_CONTRIBUTOR_PERMISSIONS : <EOL> assert_true ( self . private_project . has_permission ( self . user_two , permission ) ) <EOL> def test_adds_already_existing_contributor_private_project_admin ( self ) : <EOL> self . private_project . add_contributor ( self . user_two , auth = Auth ( self . user ) , save = True ) <EOL> self . private_project . reload ( ) <EOL> res = self . app . post_json_api ( self . private_url , self . data_user_two , <EOL> auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_adds_non_existing_user_private_project_admin ( self ) : <EOL> data = { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . private_url , data , auth = self . user . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> self . private_project . reload ( ) <EOL> assert_equal ( len ( self . private_project . contributors ) , <NUM_LIT:1> ) <EOL> def test_adds_contributor_private_project_non_admin ( self ) : <EOL> self . private_project . add_contributor ( self . user_two , permissions = [ permissions . READ , permissions . WRITE ] , auth = Auth ( self . user ) ) <EOL> res = self . app . post_json_api ( self . private_url , self . data_user_three , <EOL> auth = self . user_two . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> self . private_project . reload ( ) <EOL> assert_not_in ( self . user_three , self . private_project . contributors ) <EOL> def test_adds_contributor_private_project_non_contributor ( self ) : <EOL> res = self . app . post_json_api ( self . private_url , self . data_user_three , <EOL> auth = self . user_two . auth , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> self . private_project . reload ( ) <EOL> assert_not_in ( self . user_three , self . private_project . contributors ) <EOL> def test_adds_contributor_private_project_not_logged_in ( self ) : <EOL> res = self . app . post_json_api ( self . private_url , self . data_user_two , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> self . private_project . reload ( ) <EOL> assert_not_in ( self . user_two , self . private_project . contributors ) <EOL> class TestNodeContributorBulkCreate ( NodeCRUDTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNodeContributorBulkCreate , self ) . setUp ( ) <EOL> self . user_three = AuthUserFactory ( ) <EOL> self . private_url = '<STR_LIT>' . format ( API_BASE , self . private_project . _id ) <EOL> self . public_url = '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) <EOL> self . payload_one = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> self . payload_two = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:id>' : self . user_three . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> def test_bulk_create_contributors_blank_request ( self ) : <EOL> res = self . app . post_json_api ( self . public_url , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_node_contributor_bulk_create_contributor_exists ( self ) : <EOL> self . public_project . add_contributor ( self . user_two , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> res = self . app . post_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_two , self . payload_one ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert "<STR_LIT>" in res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:2> ) <EOL> def test_node_contributor_bulk_create_logged_out_public_project ( self ) : <EOL> res = self . app . post_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> def test_node_contributor_bulk_create_logged_in_public_project_project ( self ) : <EOL> res = self . app . post_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user . auth , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_items_equal ( [ res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ True , False ] ) <EOL> assert_items_equal ( [ res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert_equal ( res . content_type , '<STR_LIT>' ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> def test_node_contributor_bulk_create_logged_out_private_project ( self ) : <EOL> res = self . app . post_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> def test_node_contributor_bulk_create_logged_in_contrib_private_project ( self ) : <EOL> res = self . app . post_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:2> ) <EOL> assert_items_equal ( [ res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ True , False ] ) <EOL> assert_items_equal ( [ res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , res . json [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert_equal ( res . content_type , '<STR_LIT>' ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> def test_node_contributor_bulk_create_logged_in_non_contrib_private_project ( self ) : <EOL> res = self . app . post_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user_two . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> def test_node_contributor_bulk_create_logged_in_read_only_contrib_private_project ( self ) : <EOL> self . private_project . add_contributor ( self . user_two , permissions = [ permissions . READ ] , save = True ) <EOL> res = self . app . post_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_two ] } , <EOL> auth = self . user_two . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> def test_node_contributor_bulk_create_all_or_nothing ( self ) : <EOL> invalid_id_payload = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_one , invalid_id_payload ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> def test_node_contributor_bulk_create_limits ( self ) : <EOL> node_contrib_create_list = { '<STR_LIT:data>' : [ self . payload_one ] * <NUM_LIT> } <EOL> res = self . app . post_json_api ( self . public_url , node_contrib_create_list , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_node_contributor_bulk_create_no_type ( self ) : <EOL> payload = { '<STR_LIT:data>' : [ { '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT:data>' : { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:id>' : self . user_two . _id } } } } ] } <EOL> res = self . app . post_json_api ( self . public_url , payload , auth = self . user . auth , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_node_contributor_bulk_create_incorrect_type ( self ) : <EOL> payload = { <EOL> '<STR_LIT:data>' : [ { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : self . user_two . _id <EOL> } <EOL> } <EOL> } <EOL> } ] <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , payload , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_node_contributor_bulk_create_no_relationships ( self ) : <EOL> payload = { <EOL> '<STR_LIT:data>' : [ { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : self . user_two . _id <EOL> } ] <EOL> } <EOL> res = self . app . post_json_api ( self . public_url , payload , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_node_contributor_ugly_payload ( self ) : <EOL> payload = '<STR_LIT>' <EOL> res = self . app . post_json_api ( self . public_url , payload , auth = self . user . auth , expect_errors = True , bulk = 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_node_contributor_bulk_create_invalid_permissions_all_or_nothing ( self ) : <EOL> payload = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : self . user_two . _id <EOL> } <EOL> } <EOL> } <EOL> } <EOL> payload = { '<STR_LIT:data>' : [ self . payload_two , payload ] } <EOL> res = self . app . post_json_api ( self . public_url , payload , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> class TestNodeContributorBulkUpdate ( NodeCRUDTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNodeContributorBulkUpdate , self ) . setUp ( ) <EOL> self . user_three = AuthUserFactory ( ) <EOL> self . user_four = AuthUserFactory ( ) <EOL> self . public_project . add_contributor ( self . user_two , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . public_project . add_contributor ( self . user_three , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . private_project . add_contributor ( self . user_two , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . private_project . add_contributor ( self . user_three , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . private_url = '<STR_LIT>' . format ( API_BASE , self . private_project . _id ) <EOL> self . public_url = '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) <EOL> self . payload_one = { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } <EOL> self . payload_two = { <EOL> '<STR_LIT:id>' : self . user_three . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } <EOL> def test_bulk_update_contributors_blank_request ( self ) : <EOL> res = self . app . patch_json_api ( self . public_url , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_bulk_update_contributors_dict_instead_of_list ( self ) : <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : self . payload_one } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_bulk_update_contributors_public_project_one_not_found ( self ) : <EOL> invalid_id = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } <EOL> } <EOL> empty_payload = { '<STR_LIT:data>' : [ invalid_id , self . payload_one ] } <EOL> res = self . app . put_json_api ( self . public_url , empty_payload , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> res = self . app . get ( self . public_url ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_update_contributors_public_projects_logged_out ( self ) : <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_update_contributors_public_projects_logged_in ( self ) : <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user . auth , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_update_contributors_private_projects_logged_out ( self ) : <EOL> res = self . app . put_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_update_contributors_private_projects_logged_in_contrib ( self ) : <EOL> res = self . app . put_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user . auth , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_update_contributors_private_projects_logged_in_non_contrib ( self ) : <EOL> res = self . app . put_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user_four . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_update_contributors_private_projects_logged_in_read_only_contrib ( self ) : <EOL> res = self . app . put_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user_two . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_update_contributors_projects_send_dictionary_not_list ( self ) : <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : self . payload_one } , <EOL> auth = self . user . auth , expect_errors = True , bulk = 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_bulk_update_contributors_id_not_supplied ( self ) : <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : [ { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : { } } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_bulk_update_contributors_type_not_supplied ( self ) : <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : [ { '<STR_LIT:id>' : self . user_two . _id , '<STR_LIT>' : { } } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_bulk_update_contributors_wrong_type ( self ) : <EOL> invalid_type = { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } <EOL> } <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : [ invalid_type ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_bulk_update_contributors_wrong_id ( self ) : <EOL> invalid_id = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } <EOL> } <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : [ invalid_id ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = 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_bulk_update_contributors_limits ( self ) : <EOL> contrib_update_list = { '<STR_LIT:data>' : [ self . payload_one ] * <NUM_LIT> } <EOL> res = self . app . put_json_api ( self . public_url , contrib_update_list , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_bulk_update_contributors_invalid_permissions ( self ) : <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_two , { '<STR_LIT:id>' : self . user_two . _id , '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_update_contributors_invalid_bibliographic ( self ) : <EOL> res = self . app . put_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_two , { '<STR_LIT:id>' : self . user_two . _id , '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class TestNodeContributorBulkPartialUpdate ( NodeCRUDTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNodeContributorBulkPartialUpdate , self ) . setUp ( ) <EOL> self . user_three = AuthUserFactory ( ) <EOL> self . user_four = AuthUserFactory ( ) <EOL> self . public_project . add_contributor ( self . user_two , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . public_project . add_contributor ( self . user_three , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . private_project . add_contributor ( self . user_two , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . private_project . add_contributor ( self . user_three , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . private_url = '<STR_LIT>' . format ( API_BASE , self . private_project . _id ) <EOL> self . public_url = '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) <EOL> self . payload_one = { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } <EOL> self . payload_two = { <EOL> '<STR_LIT:id>' : self . user_three . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> } <EOL> def test_bulk_partial_update_contributors_blank_request ( self ) : <EOL> res = self . app . patch_json_api ( self . public_url , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_bulk_partial_update_contributors_public_project_one_not_found ( self ) : <EOL> invalid_id = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } <EOL> } <EOL> empty_payload = { '<STR_LIT:data>' : [ invalid_id , self . payload_one ] } <EOL> res = self . app . patch_json_api ( self . public_url , empty_payload , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> res = self . app . get ( self . public_url ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_partial_update_contributors_public_projects_logged_out ( self ) : <EOL> res = self . app . patch_json_api ( self . public_url , <EOL> { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , bulk = True , expect_errors = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_partial_update_contributors_public_projects_logged_in ( self ) : <EOL> res = self . app . patch_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user . auth , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_partial_update_contributors_private_projects_logged_out ( self ) : <EOL> res = self . app . patch_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_partial_update_contributors_private_projects_logged_in_contrib ( self ) : <EOL> res = self . app . patch_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user . auth , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT:200> ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_partial_update_contributors_private_projects_logged_in_non_contrib ( self ) : <EOL> res = self . app . patch_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user_four . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_partial_update_contributors_private_projects_logged_in_read_only_contrib ( self ) : <EOL> res = self . app . patch_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user_two . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_partial_update_contributors_projects_send_dictionary_not_list ( self ) : <EOL> res = self . app . patch_json_api ( self . public_url , { '<STR_LIT:data>' : self . payload_one } , <EOL> auth = self . user . auth , expect_errors = True , bulk = 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_bulk_partial_update_contributors_id_not_supplied ( self ) : <EOL> res = self . app . patch_json_api ( self . public_url , { '<STR_LIT:data>' : [ { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : { } } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_bulk_partial_update_contributors_type_not_supplied ( self ) : <EOL> res = self . app . patch_json_api ( self . public_url , { '<STR_LIT:data>' : [ { '<STR_LIT:id>' : self . user_two . _id , '<STR_LIT>' : { } } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_bulk_partial_update_contributors_wrong_type ( self ) : <EOL> invalid_type = { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } <EOL> } <EOL> res = self . app . patch_json_api ( self . public_url , { '<STR_LIT:data>' : [ invalid_type ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_bulk_partial_update_contributors_wrong_id ( self ) : <EOL> invalid_id = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } <EOL> } <EOL> res = self . app . patch_json_api ( self . public_url , { '<STR_LIT:data>' : [ invalid_id ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = 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_bulk_partial_update_contributors_limits ( self ) : <EOL> contrib_update_list = { '<STR_LIT:data>' : [ self . payload_one ] * <NUM_LIT> } <EOL> res = self . app . patch_json_api ( self . public_url , contrib_update_list , auth = self . user . auth , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_bulk_partial_update_invalid_permissions ( self ) : <EOL> res = self . app . patch_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_two , { '<STR_LIT:id>' : self . user_two . _id , '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bulk_partial_update_invalid_bibliographic ( self ) : <EOL> res = self . app . patch_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_two , { '<STR_LIT:id>' : self . user_two . _id , '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> data = res . json [ '<STR_LIT:data>' ] <EOL> assert_items_equal ( [ data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:1> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , data [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class TestNodeContributorBulkDelete ( NodeCRUDTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNodeContributorBulkDelete , self ) . setUp ( ) <EOL> self . user_three = AuthUserFactory ( ) <EOL> self . user_four = AuthUserFactory ( ) <EOL> self . public_project . add_contributor ( self . user_two , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . public_project . add_contributor ( self . user_three , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . private_project . add_contributor ( self . user_two , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . private_project . add_contributor ( self . user_three , permissions = [ permissions . READ ] , visible = True , save = True ) <EOL> self . private_url = '<STR_LIT>' . format ( API_BASE , self . private_project . _id ) <EOL> self . public_url = '<STR_LIT>' . format ( API_BASE , self . public_project . _id ) <EOL> self . payload_one = { <EOL> '<STR_LIT:id>' : self . user_two . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> } <EOL> self . payload_two = { <EOL> '<STR_LIT:id>' : self . user_three . _id , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> } <EOL> def test_bulk_delete_contributors_blank_request ( self ) : <EOL> res = self . app . delete_json_api ( self . public_url , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_bulk_delete_invalid_id ( self ) : <EOL> res = self . app . delete_json_api ( self . public_url , { '<STR_LIT:data>' : [ { '<STR_LIT:id>' : '<STR_LIT>' , '<STR_LIT:type>' : '<STR_LIT>' } ] } , auth = self . user . auth , <EOL> expect_errors = True , bulk = 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_bulk_delete_non_contributor ( self ) : <EOL> res = self . app . delete_json_api ( self . public_url , { '<STR_LIT:data>' : [ { '<STR_LIT:id>' : self . user_four . _id , '<STR_LIT:type>' : '<STR_LIT>' } ] } , auth = self . user . auth , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_bulk_delete_all_contributors ( self ) : <EOL> res = self . app . delete_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two , <EOL> { '<STR_LIT:id>' : self . user . _id , '<STR_LIT:type>' : '<STR_LIT>' } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_in ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . public_project . reload ( ) <EOL> assert_equal ( len ( self . public_project . contributors ) , <NUM_LIT:3> ) <EOL> def test_bulk_delete_contributors_no_id ( self ) : <EOL> res = self . app . delete_json_api ( self . public_url , { '<STR_LIT:data>' : [ { '<STR_LIT:type>' : '<STR_LIT>' } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = 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_bulk_delete_contributors_no_type ( self ) : <EOL> res = self . app . delete_json_api ( self . public_url , { '<STR_LIT:data>' : [ { '<STR_LIT:id>' : self . public_project . _id } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = 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_bulk_delete_contributors_invalid_type ( self ) : <EOL> res = self . app . delete_json_api ( self . public_url , { '<STR_LIT:data>' : [ { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:id>' : self . user_two . _id } ] } , <EOL> auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> def test_bulk_delete_dict_inside_data ( self ) : <EOL> res = self . app . delete_json_api ( self . public_url , { '<STR_LIT:data>' : { '<STR_LIT:id>' : self . public_project . _id , '<STR_LIT:type>' : '<STR_LIT>' } } , <EOL> auth = self . user . auth , expect_errors = True , bulk = 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_bulk_delete_contributors_public_project_logged_in ( self ) : <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> res = self . app . delete_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user . auth , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> def test_bulk_delete_contributors_public_projects_logged_out ( self ) : <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> res = self . app . delete_json_api ( self . public_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> def test_bulk_delete_contributors_private_projects_logged_in_contributor ( self ) : <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> res = self . app . delete_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user . auth , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:1> ) <EOL> def test_bulk_delete_contributors_private_projects_logged_out ( self ) : <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> res = self . app . delete_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> def test_bulk_delete_contributors_private_projects_logged_in_non_contributor ( self ) : <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> res = self . app . delete_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user_four . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> def test_bulk_delete_contributors_private_projects_logged_in_read_only_contributor ( self ) : <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> res = self . app . delete_json_api ( self . private_url , { '<STR_LIT:data>' : [ self . payload_one , self . payload_two ] } , <EOL> auth = self . user_two . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> res = self . app . get ( self . private_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> def test_bulk_delete_contributors_all_or_nothing ( self ) : <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> invalid_id = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> } <EOL> new_payload = { '<STR_LIT:data>' : [ self . payload_one , invalid_id ] } <EOL> res = self . app . delete_json_api ( self . public_url , new_payload , auth = self . user . auth , <EOL> expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> res = self . app . get ( self . public_url , auth = self . user . auth ) <EOL> assert_equal ( len ( res . json [ '<STR_LIT:data>' ] ) , <NUM_LIT:3> ) <EOL> def test_bulk_delete_contributors_limits ( self ) : <EOL> new_payload = { '<STR_LIT:data>' : [ self . payload_one ] * <NUM_LIT> } <EOL> res = self . app . delete_json_api ( self . public_url , new_payload , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> assert_equal ( res . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_bulk_delete_contributors_no_payload ( self ) : <EOL> res = self . app . delete_json_api ( self . public_url , auth = self . user . auth , expect_errors = True , bulk = True ) <EOL> assert_equal ( res . status_code , <NUM_LIT> ) </s>
