def test_basic_post(self): context = UserContext() member = StartupTeamMemberFactory(user=context.user) startup = member.startup startup.additional_industries.add(IndustryFactory()) program = ProgramFactory() program_status = StartupStatusFactory( program_startup_status__program=program, program_startup_status__badge_display=BADGE_DISPLAYS[0], program_startup_status__startup_list_include=True, startup=startup).program_startup_status.startup_status other_status = StartupStatusFactory( program_startup_status__program=ProgramFactory(), program_startup_status__badge_display=BADGE_DISPLAYS[0], program_startup_status__startup_list_include=True, startup=startup).program_startup_status.startup_status with self.login(email=self.basic_user().email): response = self.client.post(STARTUP_DETAIL_URL, { "ProgramKey": program.id, "StartupKey": startup.id }) assert startup.name == response.data["name"] statuses = [ status["status_name"] for status in response.data["statuses"] ] assert program_status in statuses assert other_status not in statuses
def test_user_joined_startup_no_created_at(self): join_date = days_from_now(-10) stm = StartupTeamMemberFactory(user__date_joined=join_date) stm.created_at = None stm.save() next_created_at = days_from_now(-1) next_stm = StartupTeamMemberFactory() next_stm.created_at = next_created_at next_stm.save() with self.login(email=self.basic_user().email): url = reverse(UserHistoryView.view_name, args=[stm.user.id]) response = self.client.get(url) events = find_events(response.data["results"], UserJoinedStartupEvent.EVENT_TYPE) self.assertEqual(1, len(events)) self.assertEqual(join_date, events[0]["datetime"]) self.assertEqual(next_created_at, events[0]["latest_datetime"])
def test_options(self): stm = StartupTeamMemberFactory(startup_administrator=True) with self.login(email=self.basic_user().email): url = reverse(UserOrganizationsView.view_name, args=[stm.user.id]) response = self.client.options(url) assert response.status_code == 200 get_options = response.data["actions"]["GET"]["properties"] assert_fields(USER_ORGANIZATIONS_GET_FIELDS, get_options) assert (ORGANIZATION_USER_FIELDS.keys() == get_options["organizations"]["item"]["properties"].keys())
def test_options_against_get(self): stm = StartupTeamMemberFactory(startup_administrator=True) with self.login(email=self.basic_user().email): url = reverse(UserOrganizationsView.view_name, args=[stm.user.id]) options_response = self.client.options(url) get_response = self.client.get(url) schema = options_response.data["actions"]["GET"] validator = Draft4Validator(schema) assert validator.is_valid(json.loads(get_response.content))
def test_public_member_post(self): context = UserContext() member = StartupTeamMemberFactory(user=context.user, display_on_public_profile=True) startup = member.startup program = ProgramFactory() with self.login(email=self.basic_user().email): response = self.client.post(STARTUP_DETAIL_URL, { "ProgramKey": program.id, "StartupKey": startup.id }) assert startup.name == response.data["name"]
def test_stealth_startup_post(self): context = UserContext() member = StartupTeamMemberFactory(user=context.user, startup__is_visible=False) startup = member.startup program = ProgramFactory() with self.login(email=self.basic_user().email): response = self.client.post(STARTUP_DETAIL_URL, { "ProgramKey": program.id, "StartupKey": startup.id }) assert EMPTY_DETAIL_RESULT == response.data
def test_url_slug_post(self): context = UserContext() member = StartupTeamMemberFactory(user=context.user) startup = member.startup program = ProgramFactory() with self.login(email=self.basic_user().email): response = self.client.post( STARTUP_DETAIL_URL, { "ProgramKey": program.id, "StartupKey": startup.organization.url_slug }) assert startup.name == response.data["name"]
def test_user_joined_startup(self): stm = StartupTeamMemberFactory() with self.login(email=self.basic_user().email): url = reverse(UserHistoryView.view_name, args=[stm.user.id]) response = self.client.get(url) events = find_events(response.data["results"], UserJoinedStartupEvent.EVENT_TYPE) self.assertEqual(1, len(events)) self.assertEqual(stm.created_at, events[0]["datetime"]) startup = stm.startup startup_str = UserJoinedStartupEvent.DESCRIPTION_FORMAT.format( name=startup.name, id=startup.organization.id) self.assertEqual(startup_str, events[0]["description"])
def test_unrecognized_video_post(self): context = UserContext() member = StartupTeamMemberFactory( user=context.user, display_on_public_profile=True, startup__video_elevator_pitch_url=UNKNOWN_VIDEO_EXAMPLE) startup = member.startup program = ProgramFactory() with self.login(email=self.basic_user().email): response = self.client.post(STARTUP_DETAIL_URL, { "ProgramKey": program.id, "StartupKey": startup.id }) assert "" == response.data["video_elevator_pitch_url"]
def test_bad_video_post(self): context = UserContext() member = StartupTeamMemberFactory( user=context.user, display_on_public_profile=True, startup__video_elevator_pitch_url=BAD_YOUTUBE_EXAMPLE) startup = member.startup program = ProgramFactory() with self.login(email=self.basic_user().email): url = reverse("startup_detail") response = self.client.post(url, { "ProgramKey": program.id, "StartupKey": startup.id }) assert "" == response.data["video_elevator_pitch_url"]
def test_logos_are_resized(self): path = "startup_pics/yuge.png" context = UserContext() member = StartupTeamMemberFactory(user=context.user) startup = member.startup startup.high_resolution_logo = path startup.save() program = ProgramFactory() with self.login(email=self.basic_user().email): response = self.client.post(STARTUP_DETAIL_URL, { "ProgramKey": program.id, "StartupKey": startup.id }) url_base = (settings.IMAGE_RESIZE_HOST + settings.IMAGE_RESIZE_TEMPLATE).format("") self.assertTrue(url_base in response.data["logo_url"])
def test_api_object_relation_link_is_valid(self): url_name = "object-list" view_kwargs = {'app': 'accelerator', "model": "startupteammember"} StartupTeamMemberFactory() User = get_user_model() perm = PermissionFactory.create(codename='change_user') user = User.objects.create_superuser("*****@*****.**", "password") startup_permission, _ = Permission.objects.get_or_create( content_type=ContentType.objects.get( app_label='accelerator', model='startup'), codename='view_startup_stealth_mode_true', name='Can view Startups in Stealth Mode', ) startup_member_permission, _ = Permission.objects.get_or_create( content_type=ContentType.objects.get( app_label='accelerator', model='startupteammember'), codename='view_startupteammember', ) user_permission, _ = Permission.objects.get_or_create( content_type=ContentType.objects.get( app_label='simpleuser', model='user'), codename='view_user', ) user.user_permissions.add(user_permission) user.user_permissions.add(perm) user.user_permissions.add(startup_permission) user.user_permissions.add(startup_member_permission) user.save() with self.login(email="*****@*****.**"): response = self.get(url_name, **view_kwargs) self.response_200(response) response_dict = json.loads(response.content) self.assertIn("user", response_dict['results'][0].keys()) entrepreneur_id = response_dict['results'][0]['user'] detail_args = {'app': 'simpleuser', "model": "user"} detail_args['pk'] = entrepreneur_id detail_response = self.get('object-detail', **detail_args) detail_json = json.loads(detail_response.content) self.assertEqual(detail_json['id'], entrepreneur_id)
def test_api_list_contains_url_to_related_object(self): url_name = "object-list" view_kwargs = {'app': 'accelerator', "model": "startupteammember"} StartupTeamMemberFactory() User = get_user_model() user = User.objects.create_superuser("*****@*****.**", "password") perm = PermissionFactory.create(codename='change_user') startup_permission, _ = Permission.objects.get_or_create( content_type=ContentType.objects.get( app_label='accelerator', model='startup'), codename='view_startup_stealth_mode_true', name='Can view Startups in Stealth Mode', ) startupteammember_permission, _ = Permission.objects.get_or_create( content_type=ContentType.objects.get( app_label='accelerator', model='startupteammember'), codename='view_startupteammember', ) user.user_permissions.add(perm) user.user_permissions.add(startup_permission) user.user_permissions.add(startupteammember_permission) user.save() with self.login(email="*****@*****.**"): response = self.get(url_name, **view_kwargs) self.response_200(response) response_dict = json.loads(response.content) self.assertIn("user", response_dict['results'][0].keys()) entrepreneur_id = response_dict['results'][0]['user'] detail_args = {'app': 'simpleuser', "model": "user"} detail_args['pk'] = entrepreneur_id detail_url = reverse('object-detail', kwargs=detail_args) absolute_uri = response.wsgi_request.build_absolute_uri( detail_url) detail_args['pk'] = response_dict['results'][0]['user'] returned_uri = response.wsgi_request.build_absolute_uri( reverse('object-detail', kwargs=detail_args)) self.assertEqual( returned_uri, absolute_uri)
def test_get(self): startup_team_member = StartupTeamMemberFactory( startup_administrator=True) startup_org_id = startup_team_member.startup.organization_id partner_team_member = PartnerTeamMemberFactory( team_member=startup_team_member.user) partner_org_id = partner_team_member.partner.organization_id with self.login(email=self.basic_user().email): url = reverse(UserOrganizationsView.view_name, args=[startup_team_member.user_id]) response = self.client.get(url) startups = [org for org in response.data["organizations"] if org["id"] == startup_org_id] self.assertEqual(len(startups), 1) self.assertEqual(startups[0]["startup_administrator"], True) self.assertEqual(startups[0]["primary_contact"], False) partners = [org for org in response.data["organizations"] if org["id"] == partner_org_id] self.assertEqual(len(partners), 1) self.assertEqual(partners[0]["partner_administrator"], False)
def test_post_without_program(self): context = UserContext() member = StartupTeamMemberFactory(user=context.user) startup = member.startup status1 = StartupStatusFactory( program_startup_status__badge_display=BADGE_DISPLAYS[0], program_startup_status__startup_list_include=True, startup=startup).program_startup_status.startup_status status2 = StartupStatusFactory( program_startup_status__badge_display=BADGE_DISPLAYS[0], program_startup_status__startup_list_include=True, startup=startup).program_startup_status.startup_status with self.login(email=self.basic_user().email): response = self.client.post(STARTUP_DETAIL_URL, {"StartupKey": startup.id}) assert startup.name == response.data["name"] statuses = [ status["status_name"] for status in response.data["statuses"] ] assert status1 in statuses assert status2 in statuses
def test_get(self): startup_team_member = StartupTeamMemberFactory( startup_administrator=True) startup_user_id = startup_team_member.user.id partner_team_member = PartnerTeamMemberFactory( partner__organization=startup_team_member.startup.organization) partner_user_id = partner_team_member.team_member.id with self.login(email=self.basic_user().email): url = reverse(OrganizationUsersView.view_name, args=[startup_team_member.startup.organization.id]) response = self.client.get(url) users = response.data["users"] self.assertEqual(len(users), 2) startup_user = [ user for user in users if user["id"] == startup_user_id ][0] self.assertTrue(startup_user["startup_administrator"]) self.assertFalse(startup_user["primary_contact"]) partner_user = [ user for user in users if user["id"] == partner_user_id ][0] self.assertFalse(partner_user["partner_administrator"])
def _user_for_date(date): user = UserContext().user StartupTeamMemberFactory(user=user) override_updated_at(get_profile(user), date) return user