def __init__(self, user_type="ENTREPRENEUR", primary_industry=None, additional_industries=None, functional_expertise=None): user = UserFactory(date_joined=(timezone.now() + timedelta(-10))) self.user = user self.baseprofile = BaseProfileFactory(user=user, user_type=user_type) if user_type == "ENTREPRENEUR": self.profile = EntrepreneurProfileFactory(user=user) user.entrepreneurprofile = self.profile elif user_type == "EXPERT": self.primary_industry = primary_industry or IndustryFactory() self.additional_industries = additional_industries or [] self.functional_expertise = functional_expertise or [] self.profile = ExpertProfileFactory( user=self.user, primary_industry=self.primary_industry, additional_industries=self.additional_industries, functional_expertise=self.functional_expertise) user.expertprofile = self.profile elif user_type == "MEMBER": self.profile = MemberProfileFactory(user=self.user) user.memberprofile = self.profile user.save()
def test_user_created(self): user = UserFactory(date_joined=timezone.now()) with self.login(email=self.basic_user().email): url = reverse(UserHistoryView.view_name, args=[user.id]) response = self.client.get(url) events = find_events(response.data["results"], UserCreatedEvent.EVENT_TYPE) self.assertEqual(1, len(events)) self.assertEqual(user.date_joined, events[0]["datetime"])
def test_options(self): user = UserFactory() with self.login(email=self.basic_user().email): url = reverse(UserHistoryView.view_name, args=[user.id]) response = self.client.options(url) assert response.status_code == 200 results = response.data["actions"]["GET"]["properties"]["results"] get_options = results["item"]["properties"] assert_fields(UserHistoryView.fields().keys(), get_options)
class UserContext(object): def __init__(self, user_type="ENTREPRENEUR", primary_industry=None, additional_industries=None, functional_expertise=None, program_families=None, program_role_names=None, startup_status_names=None): self.user = UserFactory(date_joined=(timezone.now() + timedelta(-10))) self.program_families = program_families or [] self.program_role_names = program_role_names or [] self.startup_status_names = startup_status_names or [] self.baseprofile = BaseProfileFactory(user=self.user, user_type=user_type) if user_type == "ENTREPRENEUR": self.profile = EntrepreneurProfileFactory( user=self.user, program_families=self.program_families) self.user.entrepreneurprofile = self.profile elif user_type == "EXPERT": self.primary_industry = primary_industry or IndustryFactory() self.additional_industries = additional_industries or [] self.functional_expertise = functional_expertise or [] self.profile = ExpertProfileFactory( user=self.user, primary_industry=self.primary_industry, additional_industries=self.additional_industries, functional_expertise=self.functional_expertise, program_families=self.program_families) self.user.expertprofile = self.profile elif user_type == "MEMBER": self.profile = MemberProfileFactory(user=self.user) self.user.memberprofile = self.profile self.user.save() self.program_role_grants = [ ProgramRoleGrantFactory(person=self.user, program_role__user_role__name=role_name) for role_name in self.program_role_names] self.startup_role_grants = [ StartupStatusFactory( startup__user=self.user, program_startup_status__startup_role__name=status_name) for status_name in self.startup_status_names]
def test_options_against_get(self): user = UserFactory() with self.login(email=self.basic_user().email): url = reverse(UserHistoryView.view_name, args=[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_user_became_judge_with_no_cycle_deadline(self): user_date = days_from_now(-4) user = UserFactory(date_joined=user_date) cycle = ProgramCycleFactory(application_final_deadline_date=None) prg = ProgramRoleGrantFactory( person=user, program_role__program__cycle=cycle, program_role__user_role__name=UserRole.JUDGE) prg.created_at = None prg.save() with self.login(email=self.basic_user().email): url = reverse(UserHistoryView.view_name, args=[prg.person.id]) response = self.client.get(url) events = find_events(response.data["results"], UserBecameConfirmedJudgeEvent.EVENT_TYPE) self.assertEqual(1, len(events)) self.assertEqual(user_date, events[0]["datetime"])