def test_update_project(self): # PREPARE DATA self.client.login( username=self.user.username, password='******') url = reverse('api:project:project-detail', kwargs={'slug': self.sprint_automated.slug}) timezone_workshop = 'UTC' place_id = 'ChIJgTwKgJcpQg0RaSKMYcHeNsQ' # DO ACTION data = { 'name': faker.word(), 'start': build_datetime(string_to_datetime('2018, 10, 10', custom_timezone='Europe/Madrid')), 'end': build_datetime(string_to_datetime('2018, 10, 12', custom_timezone='Europe/Madrid')), 'location': '{}, {}'.format(faker.city(), faker.country()), 'place_id': place_id, 'comment': faker.text(), } response = self.client.put(url, data=data) data = response.json() # ASSERTS self.assertTrue(status.is_success(response.status_code)) self.sprint_automated.refresh_from_db() self.assertEqual(self.sprint_automated.name, data['name']) self.assertEqual(self.sprint_automated.comment, data['comment']) self.assertEqual(self.sprint_automated.location, data['location']) self.assertEqual(self.sprint_automated.place_id, place_id) self.assertEqual(self.sprint_automated.timezone.zone, timezone_workshop)
def data_job_for_applicant(applicant): if not applicant.has_sow: return {} start_date = applicant.sow.start_date end_date = applicant.sow.end_date if start_date is None or end_date is None: return {} data = { 'user': applicant.user.uuid.__str__(), 'related_class': 'CO', 'related_uuid': applicant.opportunity.uuid.__str__(), 'category': applicant.opportunity.exo_role.categories.first().code, 'exoRole': applicant.opportunity.exo_role.code, 'title': applicant.opportunity.title, 'start': string_to_datetime(str(applicant.sow.start_date)).isoformat(), 'end': string_to_datetime(str(applicant.sow.end_date)).isoformat(), 'url': applicant.url, 'status': get_data_job_status(applicant), } if applicant.opportunity.is_online: data['extraData'] = {'url': applicant.opportunity.location_url} return data
def create_cohorts(self): self.cohort_lvl_2 = CertificationCohort.objects.create( date=string_to_datetime(faker.date()), certification=ExOCertification.objects.get( level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2), seats=25, price=1500, status=settings.EXO_CERTIFICATION_COHORT_STATUS_CH_OPEN, invoice_concept=' '.join(faker.words()), ) self.cohort_lvl_2_ft = CertificationCohort.objects.create( date=string_to_datetime(faker.date()), certification=ExOCertification.objects.get( level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2A), seats=25, price=1500, status=settings.EXO_CERTIFICATION_COHORT_STATUS_CH_OPEN, invoice_concept=' '.join(faker.words()), ) self.cohort_lvl_3 = CertificationCohort.objects.create( date=string_to_datetime(faker.date()), certification=ExOCertification.objects.get( level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_3), seats=25, price=2500, first_price_tier=1250, status=settings.EXO_CERTIFICATION_COHORT_STATUS_CH_OPEN, invoice_concept=' '.join(faker.words()), )
def data_job_for_user_project_role(user_project_role): start_date = user_project_role.project.start end_date = user_project_role.project.end project = user_project_role.project if start_date is None or end_date is None: return {} data = { 'user': user_project_role.user.uuid.__str__(), 'related_class': 'CX', 'related_uuid': user_project_role.project.uuid.__str__(), 'category': user_project_role.exo_role.categories.first().code, 'exoRole': user_project_role.exo_role.code, 'title': project.name, 'start': string_to_datetime(str(start_date)).isoformat(), 'end': string_to_datetime(str(end_date)).isoformat(), 'url': user_project_role.url, 'status': get_data_job_status(user_project_role), } try: current_step = project.steps.filter( status=settings.PROJECT_CH_STATUS_STEP_CURRENT).get().name except Exception: current_step = project.current_step().name data['status_detail'] = current_step return data
def test_total_rating_avg_method_with_differents_users(self): # PREPARE DATA qa_session1 = QASession.objects.create( project=self.sprint.project_ptr, start_at=string_to_datetime('2018, 10, 10, 10:00'), end_at=string_to_datetime('2018, 10, 10, 14:00'), ) for c_project_role in self.advisors: qa_session1.qa_session_advisors.create( consultant_project_role=c_project_role) team_qa_session_1 = qa_session1.teams.get(team=self.team) new_user = self.team.add_member( user_from=self.super_user, email=faker.email(), name=faker.name(), ) users = [self.user, new_user] inputs = [ [4, 4, 4], [4, (4, 4), 4], [(4, 4), 4, (4, 4)], [4, (4, 4), 4], [4, 4, (4, 4)], ] # DO ACTIONS for k in range(len(inputs)): post = Post.objects.create_project_qa_session_post( user_from=random.choice(users), title=' '.join(faker.words()), description=faker.text(), qa_session_team=team_qa_session_1, ) for j in range(3): user = random.choice(self.advisors).consultant.user answer = post.reply(user, faker.text()) rating = inputs[k][j] if isinstance(rating, tuple): for index, user in enumerate(users): answer.do_rating(user, rating[index]) else: answer.do_rating(random.choice(users), rating) # ASSERTS self.assertEqual(round(team_qa_session_1.rating_average, 1), 4)
def test_dates_days(self): start_date = string_to_datetime('Jun 1 2005 09:10:00') timezone = string_to_timezone('America/Sao_Paulo') dates = generate_dates( start_date=start_date, dates_number=5, lapse=settings.PROJECT_LAPSE_DAY, timezone=timezone, ) # Expected day self.assertEqual(dates[0][0], start_date) self.assertEqual(dates[0][1], string_to_datetime('2005, 6, 2, 09:09:59'))
def run(self, *args, **kwargs): if settings.POPULATOR_MODE: return email = kwargs.get('email') date = kwargs.get('date') contact = Contact.get_contact(email) contact.set_foundations_joining_date(string_to_datetime(date))
def test_skip_weekends(self): # Jun 1 2005 is Wednesday start_date = string_to_datetime('Jun 1 2005 06:10:00') dates = generate_dates( start_date=start_date, dates_number=10, lapse=settings.PROJECT_LAPSE_DAY, timezone=string_to_timezone('America/Sao_Paulo'), skip_weekends=True, ) for _date in dates: self.assertTrue(_date[0].isocalendar()[2] < 6) dates = generate_dates( start_date=start_date, dates_number=21, lapse=settings.PROJECT_LAPSE_DAY, timezone=string_to_timezone('America/Sao_Paulo'), skip_weekends=True, ) for _date in dates: self.assertTrue(_date[0].isocalendar()[2] < 6)
def test_retrieve_post(self): # PREPARE DATA self.circle = Circle.objects.first() self.user.hubs.create(hub=self.circle.hub) post = Post.objects.create_circle_post(circle=self.circle, user_from=self.user, title=' '.join(faker.words()), description=faker.text()) user_read_only = FakeUserFactory(is_active=True, password='******') url_slug = reverse('api:forum:post-slug-detail', kwargs={'slug': post.slug}) url = reverse('api:forum:post-detail', kwargs={'pk': post.pk}) # DO ACTION self.client.login(username=self.user.username, password='******') response = self.client.get(url) response_slug = self.client.get(url_slug) self.client.login(username=user_read_only.username, password='******') # ASSERTS self.assertTrue(status.is_success(response.status_code)) data = response.json() data_slug = response_slug.json() self.assertEqual(post.pk, data_slug.get('pk')) self.assertEqual(post.pk, data.get('pk')) self.assertEqual(post.answers.count(), data.get('answers')) self.assertEqual(post.answers_unseen(self.user), data.get('answersUnseen')) self.assertIn('avgRating', data) self.assertEqual(post.can_update_or_remove(self.user), data.get('canEdit')) self.assertTrue(data.get('canReply')) self.assertEqual(post.created, string_to_datetime(data.get('created'))) self.assertIsNotNone(data.get('createdBy')) self.assertIn('counterRating', data) self.assertEqual(post.description, data.get('description')) self.assertEqual(post.modified, string_to_datetime(data.get('modified'))) self.assertEqual(post.has_seen(self.user), data.get('seen')) self.assertEqual(post.tags.count(), len(data.get('tags'))) self.assertEqual(post.title, data.get('title')) self.assertEqual(len(post.uploaded_files), len(data.get('uploadedFiles'))) self.assertEqual(post.url_project, data.get('urlProject', '')) self.assertIn('yourRating', data)
def test_qa_detail_success(self): # PREPARE DATA query_params = {'pk': self.qa_session_first.pk} url = reverse('api:swarms:swarms-ecosystem-detail', kwargs=query_params) adv_user = self.advisors_first[0].consultant.user # DO ACTION self.client.login(username=self.super_user.username, password='******') response_su = self.client.get(url) self.client.login(username=adv_user.username, password='******') response_adv = self.client.get(url) # ASSERTS self.assertEqual(response_su.status_code, status.HTTP_200_OK) data = response_su.json() self.assertEqual(data.get('pk'), self.qa_session_first.pk) self.assertEqual(data.get('name'), self.qa_session_first.name) self.assertEqual(string_to_datetime(data.get('startAt')), self.qa_session_first.start_at) self.assertEqual(string_to_datetime(data.get('endAt')), self.qa_session_first.end_at) self.assertEqual(response_adv.status_code, status.HTTP_200_OK) data = response_adv.json() self.assertEqual(data.get('pk'), self.qa_session_first.pk) self.assertEqual(data.get('name'), self.qa_session_first.name) self.assertEqual(string_to_datetime(data.get('startAt')), self.qa_session_first.start_at) self.assertEqual(string_to_datetime(data.get('endAt')), self.qa_session_first.end_at) self.assertEqual(len(data.get('advisors')), self.qa_session_first.members.count()) for item in data.get('advisors', None): self.assertIsNotNone(item.get('pk')) self.assertIsNotNone(item.get('shortName')) self.assertIsNotNone(item.get('fullName')) self.assertIsNotNone(item.get('slug')) self.assertIsNotNone(item.get('profilePictures'))
def data_job_for_participant(participant): start_date = participant.event.start end_date = participant.event.end if start_date is None or end_date is None: return {} data = { 'user': participant.user.uuid.__str__(), 'related_class': 'CE', 'related_uuid': participant.event.uuid.__str__(), 'category': participant.category.code, 'exoRole': participant.exo_role.code, 'title': participant.event.title, 'start': string_to_datetime(str(participant.event.start)).isoformat(), 'end': string_to_datetime(str(participant.event.end)).isoformat(), 'url': participant.event.url, 'status': get_data_job_status(participant), } return data
def create_cohort(self, level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2 ): certification = ExOCertification.objects.get(level=level) return CertificationCohort.objects.create( date=string_to_datetime(faker.date()), certification=certification, seats=25, price=2500, status=settings.EXO_CERTIFICATION_COHORT_STATUS_CH_OPEN, invoice_concept=' '.join(faker.words()), )
def test_qa_detail_success(self): # PREPARE DATA swarm_id = self.qa_session_first.teams.get(team=self.team_A).pk query_params = { 'project_id': self.qa_session_first.project.pk, 'team_id': self.team_A.pk, 'pk': swarm_id, } url = reverse('api:swarms:swarms-project-detail', kwargs=query_params) # DO ACTION self.client.login(username=self.user.username, password='******') response = self.client.get(url) # ASSERTS self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() self.assertEqual(data.get('pk'), swarm_id) self.assertEqual(data.get('name'), self.qa_session_first.name) self.assertEqual(string_to_datetime(data.get('startAt')), self.qa_session_first.start_at) self.assertEqual(string_to_datetime(data.get('endAt')), self.qa_session_first.end_at)
def test_filter_qa_session(self): # PREPARE DATA # Session1: 10-10-2018 10:00 to 10-10-2018 14:00 # Session 2: 10-11-2018 10:00 to 10-11-2018 14:00 qa_session1 = QASession.objects.create( project=self.sprint.project_ptr, start_at=string_to_datetime('2018, 10, 10, 10:00'), end_at=string_to_datetime('2018, 10, 10, 14:00'), ) qa_session2 = QASession.objects.create( project=self.sprint.project_ptr, start_at=string_to_datetime('2018, 10, 11, 10:00'), end_at=string_to_datetime('2018, 10, 11, 14:00'), ) for c_project_role in self.advisors: qa_session1.qa_session_advisors.create( consultant_project_role=c_project_role) qa_session2.qa_session_advisors.create( consultant_project_role=c_project_role) # ASSERTS inputs = [ string_to_datetime('2018, 10, 10, 1:00'), string_to_datetime('2018, 10, 10, 18:00'), string_to_datetime('2018, 10, 9, 10:00'), string_to_datetime('2018, 10, 11, 10:10'), string_to_datetime('2018, 10, 12, 10:00'), ] outputs = [ qa_session1, qa_session2, qa_session1, qa_session2, qa_session2 ] for index, when in enumerate(inputs): qa_session = self.team.qa_sessions.select_session_by_datetime(when) self.assertEqual(qa_session.session, outputs[index])
def initialize_swarms(self, superuser, user): self.secondary_user = FakeUserFactory.create() self.sprint = FakeSprintAutomatedFactory.create( status=settings.PROJECT_CH_PROJECT_STATUS_WAITING) self.team_A = FakeTeamFactory.create(project=self.sprint.project_ptr) self.team_B = FakeTeamFactory.create(project=self.sprint.project_ptr) self.team_A.add_member(user_from=superuser, email=user.email, name=user.short_name) self.team_B.add_member(user_from=superuser, email=self.secondary_user.email, name=self.secondary_user.short_name) self.advisors_first = [ FakeConsultantProjectRoleFactory.create( project=self.sprint.project_ptr, consultant=FakeConsultantFactory(user__is_active=True), exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_ADVISOR), exo_role_other_name='Swarm', status=settings.RELATION_ROLE_CH_ACTIVE, ) for i in range(4) ] self.advisors_second = [ FakeConsultantProjectRoleFactory.create( project=self.sprint.project_ptr, consultant=FakeConsultantFactory(user__is_active=True), exo_role=ExORole.objects.get( code=settings.EXO_ROLE_CODE_ADVISOR), exo_role_other_name='Swarm', status=settings.RELATION_ROLE_CH_ACTIVE, ) for i in range(3) ] self.qa_session_first = QASession.objects.create( project=self.sprint.project_ptr, start_at=string_to_datetime('2019, 04, 20, 11:00'), end_at=string_to_datetime('2019, 04, 20, 12:00'), ) self.qa_session_second = QASession.objects.create( project=self.sprint.project_ptr, start_at=string_to_datetime('2019, 04, 26, 13:00'), end_at=string_to_datetime('2019, 04, 26, 14:00'), ) for c_project_role in self.advisors_first: self.qa_session_first.qa_session_advisors.create( consultant_project_role=c_project_role) self.qa_session_second.qa_session_advisors.create( consultant_project_role=c_project_role) self.posts_first_A = [ Post.objects.create_project_qa_session_post( user_from=user, title=' '.join(faker.words()), description=faker.text(), qa_session_team=self.qa_session_first.teams.get( team=self.team_A)) for i in range(6) ] post = self.posts_first_A[0] post.reply(self.advisors_first[0].consultant.user, faker.text()) post.reply(self.advisors_first[1].consultant.user, faker.text()) post.reply(self.advisors_first[2].consultant.user, faker.text()) self.post_first_B = [ Post.objects.create_project_qa_session_post( user_from=self.secondary_user, title=' '.join(faker.words()), description=faker.text(), qa_session_team=self.qa_session_first.teams.get( team=self.team_B)) for i in range(4) ] post = self.post_first_B[0] post.reply(self.advisors_first[0].consultant.user, faker.text()) post.reply(self.advisors_first[1].consultant.user, faker.text()) post.reply(self.advisors_first[0].consultant.user, faker.text())
def test_total_answers_by_participant(self): # PREPARE DATA qa_session1 = QASession.objects.create( project=self.sprint.project_ptr, start_at=string_to_datetime('2018, 10, 10, 10:00'), end_at=string_to_datetime('2018, 10, 10, 14:00'), ) qa_session_team_1 = qa_session1.teams.get(team=self.team) for c_project_role in self.advisors: qa_session1.qa_session_advisors.create( consultant_project_role=c_project_role) qa_session2 = QASession.objects.create( project=self.sprint.project_ptr, start_at=string_to_datetime('2018, 10, 11, 10:00'), end_at=string_to_datetime('2018, 10, 11, 14:00'), ) qa_session_team_2 = qa_session2.teams.get(team=self.team) for c_project_role in self.advisors: qa_session2.qa_session_advisors.create( consultant_project_role=c_project_role) new_user = self.team.add_member( user_from=self.super_user, email=faker.email(), name=faker.name(), ) # DO ACTIONS post = Post.objects.create_project_qa_session_post( user_from=self.user, title=' '.join(faker.words()), description=faker.text(), qa_session_team=qa_session_team_1, ) post2 = Post.objects.create_project_qa_session_post( user_from=self.user, title=' '.join(faker.words()), description=faker.text(), qa_session_team=qa_session_team_2, ) post3 = Post.objects.create_project_qa_session_post( user_from=new_user, title=' '.join(faker.words()), description=faker.text(), qa_session_team=qa_session_team_2, ) post.reply(self.advisors[0].consultant.user, faker.text()) post.reply(self.advisors[2].consultant.user, faker.text()) post2.reply(self.advisors[0].consultant.user, faker.text()) post2.reply(self.advisors[1].consultant.user, faker.text()) post3.reply(self.advisors[2].consultant.user, faker.text()) post3.reply(self.advisors[3].consultant.user, faker.text()) post3.reply(self.advisors[0].consultant.user, faker.text()) # ASSERTS self.assertEqual(qa_session_team_1.questions.count(), 1) self.assertEqual( qa_session_team_1.total_answers_by_participant(self.user), 2) self.assertEqual( qa_session_team_1.total_answers_by_participant(new_user), 0) self.assertEqual(qa_session_team_2.questions.count(), 2) self.assertEqual( qa_session_team_2.total_answers_by_participant(self.user), 2) self.assertEqual( qa_session_team_2.total_answers_by_participant(new_user), 3)