<s> """<STR_LIT>""" <EOL> import json <EOL> from django . test import TestCase <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . models import AnonymousUser <EOL> from django . http import HttpResponseRedirect <EOL> from django . contrib . gis . geos import GEOSGeometry <EOL> from django . contrib . messages . storage . fallback import FallbackStorage <EOL> from rest_framework . test import APIRequestFactory , force_authenticate <EOL> from geokey . categories . tests . model_factories import ( <EOL> TextFieldFactory , CategoryFactory <EOL> ) <EOL> from geokey . users . tests . model_factories import UserFactory <EOL> from . model_factories import ProjectFactory <EOL> from . . models import Project , Admins <EOL> from . . views import ( <EOL> ProjectCreate , ProjectSettings , ProjectUpdate , ProjectAdmins , <EOL> ProjectAdminsUser , Projects , SingleProject , ProjectOverview , <EOL> ProjectGeographicExtent , CategoriesReorderView , ProjectsInvolved , <EOL> ProjectDelete <EOL> ) <EOL> class ProjectCreateTest ( TestCase ) : <EOL> def test_get_with_user ( self ) : <EOL> view = ProjectCreate . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = UserFactory . create ( ) <EOL> response = view ( request ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_anonymous ( self ) : <EOL> view = ProjectCreate . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = AnonymousUser ( ) <EOL> response = view ( request ) <EOL> self . assertTrue ( isinstance ( response , HttpResponseRedirect ) ) <EOL> def test_post_with_user ( self ) : <EOL> data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> view = ProjectCreate . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> request = APIRequestFactory ( ) . post ( url , data ) <EOL> request . user = UserFactory . create ( ) <EOL> setattr ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = FallbackStorage ( request ) <EOL> setattr ( request , '<STR_LIT>' , messages ) <EOL> response = view ( request ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Project . objects . count ( ) , <NUM_LIT:1> ) <EOL> def test_post_with_anonymous ( self ) : <EOL> data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> view = ProjectCreate . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> request = APIRequestFactory ( ) . post ( url , data ) <EOL> request . user = AnonymousUser ( ) <EOL> response = view ( request ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Project . objects . count ( ) , <NUM_LIT:0> ) <EOL> class ProjectsInvolvedTest ( TestCase ) : <EOL> def test_get_with_user ( self ) : <EOL> user = UserFactory . create ( ) <EOL> ProjectFactory . create ( add_contributors = [ user ] ) <EOL> view = ProjectsInvolved . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = user <EOL> response = view ( request ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_anonymous ( self ) : <EOL> view = ProjectsInvolved . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = AnonymousUser ( ) <EOL> response = view ( request ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> class ProjectGeographicExtentTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . creator = UserFactory . create ( ) <EOL> self . admin = UserFactory . create ( ) <EOL> self . view_member = UserFactory . create ( ) <EOL> self . contributor = UserFactory . create ( ) <EOL> self . project = ProjectFactory . create ( <EOL> add_admins = [ self . admin ] , <EOL> add_contributors = [ self . contributor ] , <EOL> ** { <EOL> '<STR_LIT>' : self . creator <EOL> } <EOL> ) <EOL> def test_get_with_creator ( self ) : <EOL> view = ProjectSettings . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . creator <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_admin ( self ) : <EOL> view = ProjectGeographicExtent . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . admin <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_contributor ( self ) : <EOL> view = ProjectGeographicExtent . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . contributor <EOL> response = view ( request , project_id = self . project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_view_member ( self ) : <EOL> view = ProjectGeographicExtent . as_view ( ) <EOL> url = reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } <EOL> ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . view_member <EOL> response = view ( request , project_id = self . project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_anonymous ( self ) : <EOL> view = ProjectGeographicExtent . as_view ( ) <EOL> url = reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } <EOL> ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = AnonymousUser ( ) <EOL> response = view ( request ) <EOL> self . assertTrue ( isinstance ( response , HttpResponseRedirect ) ) <EOL> def test_get_deleted_project ( self ) : <EOL> self . project . delete ( ) <EOL> view = ProjectGeographicExtent . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . admin <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_update ( self ) : <EOL> data = { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' } <EOL> view = ProjectGeographicExtent . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . post ( url , data ) <EOL> request . user = self . admin <EOL> setattr ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = FallbackStorage ( request ) <EOL> setattr ( request , '<STR_LIT>' , messages ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( <EOL> response , '<STR_LIT>' ) <EOL> updated = Project . objects . get ( pk = self . project . id ) <EOL> self . assertEqual ( updated . geographic_extent . geom_type , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> updated . geographic_extent . json , <EOL> GEOSGeometry ( data . get ( '<STR_LIT>' ) ) . json <EOL> ) <EOL> def test_update_with_none ( self ) : <EOL> data = None <EOL> view = ProjectGeographicExtent . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . post ( url , data ) <EOL> request . user = self . admin <EOL> setattr ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = FallbackStorage ( request ) <EOL> setattr ( request , '<STR_LIT>' , messages ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( <EOL> response , '<STR_LIT>' ) <EOL> updated = Project . objects . get ( pk = self . project . id ) <EOL> self . assertEqual ( updated . geographic_extent , None ) <EOL> def test_update_with_empty_string ( self ) : <EOL> data = { '<STR_LIT>' : '<STR_LIT>' } <EOL> view = ProjectGeographicExtent . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . post ( url , data ) <EOL> request . user = self . admin <EOL> setattr ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = FallbackStorage ( request ) <EOL> setattr ( request , '<STR_LIT>' , messages ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( <EOL> response , '<STR_LIT>' ) <EOL> updated = Project . objects . get ( pk = self . project . id ) <EOL> self . assertEqual ( updated . geographic_extent , None ) <EOL> def test_update_with_locked_project ( self ) : <EOL> self . project . islocked = True <EOL> self . project . geographic_extent = None <EOL> self . project . save ( ) <EOL> data = { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' } <EOL> view = ProjectGeographicExtent . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . post ( url , data ) <EOL> request . user = self . admin <EOL> setattr ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = FallbackStorage ( request ) <EOL> setattr ( request , '<STR_LIT>' , messages ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( <EOL> response , '<STR_LIT>' ) <EOL> updated = Project . objects . get ( pk = self . project . id ) <EOL> self . assertEqual ( updated . geographic_extent , None ) <EOL> class ProjectSettingsTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . creator = UserFactory . create ( ) <EOL> self . admin = UserFactory . create ( ) <EOL> self . view_member = UserFactory . create ( ) <EOL> self . contributor = UserFactory . create ( ) <EOL> self . project = ProjectFactory . create ( <EOL> add_admins = [ self . admin ] , <EOL> add_contributors = [ self . contributor ] , <EOL> ** { '<STR_LIT>' : self . creator } <EOL> ) <EOL> def test_get_with_creator ( self ) : <EOL> view = ProjectSettings . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . creator <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_admin ( self ) : <EOL> view = ProjectSettings . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . admin <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_contributor ( self ) : <EOL> view = ProjectSettings . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . contributor <EOL> response = view ( request , project_id = self . project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_view_member ( self ) : <EOL> view = ProjectSettings . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . view_member <EOL> response = view ( request , project_id = self . project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_anonymous ( self ) : <EOL> view = ProjectSettings . as_view ( ) <EOL> url = reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } <EOL> ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = AnonymousUser ( ) <EOL> response = view ( request ) <EOL> self . assertTrue ( isinstance ( response , HttpResponseRedirect ) ) <EOL> def test_get_deleted_project ( self ) : <EOL> self . project . delete ( ) <EOL> view = ProjectSettings . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . admin <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_post_with_admin ( self ) : <EOL> data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> view = ProjectSettings . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . post ( url , data ) <EOL> request . user = self . creator <EOL> setattr ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = FallbackStorage ( request ) <EOL> setattr ( request , '<STR_LIT>' , messages ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> class ProjectOverviewTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . creator = UserFactory . create ( ) <EOL> self . admin = UserFactory . create ( ) <EOL> self . view_member = UserFactory . create ( ) <EOL> self . contributor = UserFactory . create ( ) <EOL> self . project = ProjectFactory . create ( <EOL> add_admins = [ self . admin ] , <EOL> add_contributors = [ self . contributor ] , <EOL> ** { <EOL> '<STR_LIT>' : self . creator <EOL> } <EOL> ) <EOL> def test_get_with_admin ( self ) : <EOL> view = ProjectOverview . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . admin <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_contributor ( self ) : <EOL> view = ProjectOverview . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . contributor <EOL> response = view ( request , project_id = self . project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_view_member ( self ) : <EOL> view = ProjectOverview . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . view_member <EOL> response = view ( request , project_id = self . project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_with_anonymous ( self ) : <EOL> view = ProjectOverview . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = AnonymousUser ( ) <EOL> response = view ( request ) <EOL> self . assertTrue ( isinstance ( response , HttpResponseRedirect ) ) <EOL> def test_get_deleted_project ( self ) : <EOL> self . project . delete ( ) <EOL> view = ProjectOverview . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = self . admin <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> class ProjectDeleteTest ( TestCase ) : <EOL> def test_delete_with_admin ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( add_admins = [ user ] ) <EOL> view = ProjectDelete . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = user <EOL> setattr ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = FallbackStorage ( request ) <EOL> setattr ( request , '<STR_LIT>' , messages ) <EOL> response = view ( request , project_id = project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Project . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_delete_non_existing_project ( self ) : <EOL> user = UserFactory . create ( ) <EOL> view = ProjectDelete . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : <NUM_LIT> } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = user <EOL> setattr ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = FallbackStorage ( request ) <EOL> setattr ( request , '<STR_LIT>' , messages ) <EOL> response = view ( request , project_id = <NUM_LIT> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Project . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_delete_locked_project ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( islocked = True , add_admins = [ user ] ) <EOL> view = ProjectDelete . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = user <EOL> setattr ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> messages = FallbackStorage ( request ) <EOL> setattr ( request , '<STR_LIT>' , messages ) <EOL> response = view ( request , project_id = project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Project . objects . count ( ) , <NUM_LIT:1> ) <EOL> def test_delete_with_contributor ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( add_contributors = [ user ] ) <EOL> view = ProjectDelete . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = user <EOL> response = view ( request , project_id = project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Project . objects . count ( ) , <NUM_LIT:1> ) <EOL> def test_delete_with_anonymous ( self ) : <EOL> project = ProjectFactory . create ( ) <EOL> view = ProjectDelete . as_view ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : project . id } ) <EOL> request = APIRequestFactory ( ) . get ( url ) <EOL> request . user = AnonymousUser ( ) <EOL> response = view ( request , project_id = project . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Project . objects . count ( ) , <NUM_LIT:1> ) <EOL> class ProjectUpdateTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . factory = APIRequestFactory ( ) <EOL> self . admin = UserFactory . create ( ) <EOL> self . contributor = UserFactory . create ( ) <EOL> self . non_member = UserFactory . create ( ) <EOL> self . project = ProjectFactory . create ( <EOL> add_admins = [ self . admin ] , <EOL> add_contributors = [ self . contributor ] <EOL> ) <EOL> def test_unauthenticated ( self ) : <EOL> request = self . factory . put ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT:status>' : '<STR_LIT>' } <EOL> ) <EOL> view = ProjectUpdate . as_view ( ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_update_with_wrong_status ( self ) : <EOL> request = self . factory . put ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT:status>' : '<STR_LIT>' } <EOL> ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = ProjectUpdate . as_view ( ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_update_project_status_with_admin ( self ) : <EOL> request = self . factory . put ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT:status>' : '<STR_LIT>' } <EOL> ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = ProjectUpdate . as_view ( ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( <EOL> Project . objects . get ( pk = self . project . id ) . status , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_update_project_description_with_admin ( self ) : <EOL> request = self . factory . put ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT:description>' : '<STR_LIT>' } <EOL> ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = ProjectUpdate . as_view ( ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( <EOL> Project . objects . get ( pk = self . project . id ) . description , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_update_project_description_with_contributor ( self ) : <EOL> request = self . factory . put ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT:description>' : '<STR_LIT>' } <EOL> ) <EOL> force_authenticate ( request , user = self . contributor ) <EOL> view = ProjectUpdate . as_view ( ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( <EOL> Project . objects . get ( pk = self . project . id ) . description , <EOL> self . project . description <EOL> ) <EOL> def test_update_project_description_with_non_member ( self ) : <EOL> request = self . factory . put ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT:description>' : '<STR_LIT>' } <EOL> ) <EOL> force_authenticate ( request , user = self . non_member ) <EOL> view = ProjectUpdate . as_view ( ) <EOL> response = view ( request , project_id = self . project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( <EOL> Project . objects . get ( pk = self . project . id ) . description , <EOL> self . project . description <EOL> ) <EOL> class ProjectAdminsTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . factory = APIRequestFactory ( ) <EOL> self . admin = UserFactory . create ( ) <EOL> self . contributor = UserFactory . create ( ) <EOL> self . non_member = UserFactory . create ( ) <EOL> self . user_to_add = UserFactory . create ( ) <EOL> self . project = ProjectFactory . create ( <EOL> add_admins = [ self . admin ] , <EOL> add_contributors = [ self . contributor ] <EOL> ) <EOL> def test_add_when_project_does_not_exist ( self ) : <EOL> project_id = <NUM_LIT> <EOL> request = self . factory . post ( <EOL> '<STR_LIT>' % project_id , <EOL> { '<STR_LIT>' : self . user_to_add . id } <EOL> ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = ProjectAdmins . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = project_id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_add_when_user_does_not_exist ( self ) : <EOL> user_id = <NUM_LIT> <EOL> request = self . factory . post ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT>' : user_id } <EOL> ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = ProjectAdmins . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_add_when_user_already_an_admin ( self ) : <EOL> Admins . objects . create ( project = self . project , user = self . user_to_add ) <EOL> request = self . factory . post ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT>' : self . user_to_add . id } <EOL> ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = ProjectAdmins . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_add_with_admin ( self ) : <EOL> request = self . factory . post ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT>' : self . user_to_add . id } <EOL> ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = ProjectAdmins . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( <EOL> self . user_to_add , <EOL> Project . objects . get ( pk = self . project . id ) . admins . all ( ) <EOL> ) <EOL> def test_add_with_contributor ( self ) : <EOL> request = self . factory . post ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT>' : self . user_to_add . id } <EOL> ) <EOL> force_authenticate ( request , user = self . contributor ) <EOL> view = ProjectAdmins . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertNotIn ( <EOL> self . user_to_add , <EOL> Project . objects . get ( pk = self . project . id ) . admins . all ( ) <EOL> ) <EOL> def test_add_with_non_member ( self ) : <EOL> request = self . factory . post ( <EOL> '<STR_LIT>' % self . project . id , <EOL> { '<STR_LIT>' : self . user_to_add . id } <EOL> ) <EOL> force_authenticate ( request , user = self . non_member ) <EOL> view = ProjectAdmins . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertNotIn ( <EOL> self . user_to_add , <EOL> Project . objects . get ( pk = self . project . id ) . admins . all ( ) <EOL> ) <EOL> class ProjectAdminsUserTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . factory = APIRequestFactory ( ) <EOL> self . admin = UserFactory . create ( ) <EOL> self . contributor = UserFactory . create ( ) <EOL> self . non_member = UserFactory . create ( ) <EOL> self . admin_to_remove = UserFactory . create ( ) <EOL> self . project = ProjectFactory . create ( <EOL> add_admins = [ self . admin , self . admin_to_remove ] , <EOL> add_contributors = [ self . contributor ] <EOL> ) <EOL> def test_delete_not_existing_admin ( self ) : <EOL> user = UserFactory . create ( ) <EOL> request = self . factory . delete ( <EOL> '<STR_LIT>' % <EOL> ( self . project . id , user . id ) <EOL> ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = ProjectAdminsUser . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id , <EOL> user_id = user . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_delete_adminuser_with_admin ( self ) : <EOL> request = self . factory . delete ( <EOL> '<STR_LIT>' % <EOL> ( self . project . id , self . admin_to_remove . id ) <EOL> ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = ProjectAdminsUser . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id , <EOL> user_id = self . admin_to_remove . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertNotIn ( <EOL> self . admin_to_remove , <EOL> Project . objects . get ( pk = self . project . id ) . admins . all ( ) <EOL> ) <EOL> def test_delete_adminuser_with_contributor ( self ) : <EOL> request = self . factory . delete ( <EOL> '<STR_LIT>' % <EOL> ( self . project . id , self . admin_to_remove . id ) <EOL> ) <EOL> force_authenticate ( request , user = self . contributor ) <EOL> view = ProjectAdminsUser . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id , <EOL> user_id = self . admin_to_remove . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( <EOL> self . admin_to_remove , <EOL> Project . objects . get ( pk = self . project . id ) . admins . all ( ) <EOL> ) <EOL> def test_delete_adminuser_with_non_member ( self ) : <EOL> request = self . factory . delete ( <EOL> '<STR_LIT>' % <EOL> ( self . project . id , self . admin_to_remove . id ) <EOL> ) <EOL> force_authenticate ( request , user = self . non_member ) <EOL> view = ProjectAdminsUser . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id , <EOL> user_id = self . admin_to_remove . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( <EOL> self . admin_to_remove , <EOL> Project . objects . get ( pk = self . project . id ) . admins . all ( ) <EOL> ) <EOL> class ReorderCategoriesTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . factory = APIRequestFactory ( ) <EOL> self . project = ProjectFactory . create ( ) <EOL> self . category_0 = CategoryFactory . create ( ** { '<STR_LIT>' : self . project } ) <EOL> self . category_1 = CategoryFactory . create ( ** { '<STR_LIT>' : self . project } ) <EOL> self . category_2 = CategoryFactory . create ( ** { '<STR_LIT>' : self . project } ) <EOL> self . category_3 = CategoryFactory . create ( ** { '<STR_LIT>' : self . project } ) <EOL> self . category_4 = CategoryFactory . create ( ** { '<STR_LIT>' : self . project } ) <EOL> def test_reorder ( self ) : <EOL> url = reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { <EOL> '<STR_LIT>' : self . project . id <EOL> } <EOL> ) <EOL> data = [ <EOL> self . category_4 . id , self . category_0 . id , self . category_2 . id , <EOL> self . category_1 . id , self . category_3 . id <EOL> ] <EOL> request = self . factory . post ( <EOL> url , json . dumps ( { '<STR_LIT>' : data } ) , content_type = '<STR_LIT:application/json>' ) <EOL> force_authenticate ( request , user = self . project . creator ) <EOL> view = CategoriesReorderView . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> categories = self . project . categories . all ( ) <EOL> self . assertTrue ( categories . ordered ) <EOL> self . assertEqual ( categories [ <NUM_LIT:0> ] , self . category_4 ) <EOL> self . assertEqual ( categories [ <NUM_LIT:1> ] , self . category_0 ) <EOL> self . assertEqual ( categories [ <NUM_LIT:2> ] , self . category_2 ) <EOL> self . assertEqual ( categories [ <NUM_LIT:3> ] , self . category_1 ) <EOL> self . assertEqual ( categories [ <NUM_LIT:4> ] , self . category_3 ) <EOL> def test_reorder_with_false_category ( self ) : <EOL> url = reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { <EOL> '<STR_LIT>' : self . project . id <EOL> } <EOL> ) <EOL> data = [ <EOL> self . category_4 . id , self . category_0 . id , self . category_2 . id , <EOL> self . category_1 . id , <NUM_LIT> <EOL> ] <EOL> request = self . factory . post ( <EOL> url , json . dumps ( { '<STR_LIT>' : data } ) , content_type = '<STR_LIT:application/json>' ) <EOL> force_authenticate ( request , user = self . project . creator ) <EOL> view = CategoriesReorderView . as_view ( ) <EOL> response = view ( <EOL> request , <EOL> project_id = self . project . id <EOL> ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> categories = self . project . categories . all ( ) <EOL> self . assertTrue ( categories . ordered ) <EOL> self . assertEqual ( categories [ <NUM_LIT:0> ] . order , <NUM_LIT:0> ) <EOL> self . assertEqual ( categories [ <NUM_LIT:1> ] . order , <NUM_LIT:1> ) <EOL> self . assertEqual ( categories [ <NUM_LIT:2> ] . order , <NUM_LIT:2> ) <EOL> self . assertEqual ( categories [ <NUM_LIT:3> ] . order , <NUM_LIT:3> ) <EOL> self . assertEqual ( categories [ <NUM_LIT:4> ] . order , <NUM_LIT:4> ) <EOL> class ProjectsTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . factory = APIRequestFactory ( ) <EOL> self . admin = UserFactory . create ( ) <EOL> self . contributor = UserFactory . create ( ) <EOL> self . non_member = UserFactory . create ( ) <EOL> self . public_project = ProjectFactory . create ( <EOL> add_admins = [ self . admin ] , <EOL> add_contributors = [ self . contributor ] , <EOL> ** { <EOL> '<STR_LIT>' : False <EOL> } <EOL> ) <EOL> self . private_project = ProjectFactory . create ( <EOL> add_admins = [ self . admin ] , <EOL> add_contributors = [ self . contributor ] <EOL> ) <EOL> self . inactive_project = ProjectFactory . create ( <EOL> add_admins = [ self . admin ] , <EOL> add_contributors = [ self . contributor ] , <EOL> ** { <EOL> '<STR_LIT:status>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> self . deleted_project = ProjectFactory . create ( <EOL> add_admins = [ self . admin ] , <EOL> add_contributors = [ self . contributor ] , <EOL> ** { '<STR_LIT>' : False } <EOL> ) <EOL> self . deleted_project . delete ( ) <EOL> def test_get_projects_with_admin ( self ) : <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> force_authenticate ( request , user = self . admin ) <EOL> view = Projects . as_view ( ) <EOL> response = view ( request ) . render ( ) <EOL> projects = json . loads ( response . content ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( projects ) , <NUM_LIT:2> ) <EOL> self . assertNotContains ( response , self . deleted_project . name ) <EOL> def test_get_projects_with_contributor ( self ) : <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> force_authenticate ( request , user = self . contributor ) <EOL> view = Projects . as_view ( ) <EOL> response = view ( request ) . render ( ) <EOL> projects = json . loads ( response . content ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( projects ) , <NUM_LIT:2> ) <EOL> self . assertNotContains ( response , self . inactive_project . name ) <EOL> self . assertNotContains ( response , self . deleted_project . name ) <EOL> def test_get_projects_with_non_member ( self ) : <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> force_authenticate ( request , user = self . non_member ) <EOL> view = Projects . as_view ( ) <EOL> response = view ( request ) . render ( ) <EOL> projects = json . loads ( response . content ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( projects ) , <NUM_LIT:1> ) <EOL> self . assertNotContains ( response , self . inactive_project . name ) <EOL> self . assertNotContains ( response , self . deleted_project . name ) <EOL> self . assertNotContains ( response , self . private_project . name ) <EOL> def test_get_projects_with_anonymous ( self ) : <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> force_authenticate ( request , user = AnonymousUser ( ) ) <EOL> view = Projects . as_view ( ) <EOL> response = view ( request ) . render ( ) <EOL> projects = json . loads ( response . content ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( projects ) , <NUM_LIT:1> ) <EOL> self . assertNotContains ( response , self . inactive_project . name ) <EOL> self . assertNotContains ( response , self . deleted_project . name ) <EOL> self . assertNotContains ( response , self . private_project . name ) <EOL> class SingleProjectTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . factory = APIRequestFactory ( ) <EOL> def test_category_serialization ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( <EOL> add_admins = [ user ] <EOL> ) <EOL> CategoryFactory . create ( ** { '<STR_LIT>' : project } ) <EOL> CategoryFactory . create ( <EOL> ** { '<STR_LIT>' : project , '<STR_LIT:status>' : '<STR_LIT>' } <EOL> ) <EOL> o1 = CategoryFactory . create ( ** { '<STR_LIT>' : project } ) <EOL> TextFieldFactory . create ( ** { '<STR_LIT>' : o1 } ) <EOL> o2 = CategoryFactory . create ( ** { '<STR_LIT>' : project } ) <EOL> TextFieldFactory . create ( ** { '<STR_LIT>' : o2 } ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( <EOL> <NUM_LIT:2> , <EOL> len ( json . loads ( response . content ) . get ( '<STR_LIT>' ) ) <EOL> ) <EOL> def test_get_deleted_project_with_admin ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( <EOL> add_admins = [ user ] <EOL> ) <EOL> project . delete ( ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_get_private_project_with_admin ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( <EOL> add_admins = [ user ] <EOL> ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , project . name ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_get_inactive_project_with_admin ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( <EOL> add_admins = [ user ] , <EOL> ** { '<STR_LIT:status>' : '<STR_LIT>' } <EOL> ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_get_public_project_with_admin ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( <EOL> add_admins = [ user ] , <EOL> ** { '<STR_LIT>' : False } <EOL> ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , project . name ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_get_deleted_project_with_contributor ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( <EOL> add_contributors = [ user ] <EOL> ) <EOL> project . delete ( ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_get_private_project_with_contributor ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( <EOL> add_contributors = [ user ] <EOL> ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , project . name ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_get_inactive_project_with_contributor ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( <EOL> add_contributors = [ user ] , <EOL> ** { '<STR_LIT:status>' : '<STR_LIT>' } <EOL> ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_get_public_project_with_contributor ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( <EOL> add_contributors = [ user ] , <EOL> ** { '<STR_LIT>' : False } <EOL> ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , project . name ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_get_deleted_project_with_non_member ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( ) <EOL> project . delete ( ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_get_private_project_with_non_member ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_get_inactive_project_with_non_member ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( ** { <EOL> '<STR_LIT:status>' : '<STR_LIT>' <EOL> } ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_get_public_project_with_non_member ( self ) : <EOL> user = UserFactory . create ( ) <EOL> project = ProjectFactory . create ( ** { <EOL> '<STR_LIT>' : False <EOL> } ) <EOL> request = self . factory . get ( <EOL> '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , project . name ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_get_public_project_with_anonymous ( self ) : <EOL> user = AnonymousUser ( ) <EOL> project = ProjectFactory . create ( ** { <EOL> '<STR_LIT>' : False <EOL> } ) <EOL> request = self . factory . get ( '<STR_LIT>' % project . id ) <EOL> force_authenticate ( request , user = user ) <EOL> view = SingleProject . as_view ( ) <EOL> response = view ( request , project_id = project . id ) . render ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , project . name ) <EOL> self . assertContains ( response , '<STR_LIT>' ) </s>
