def test_get_post_answer_seen(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_1 = FakeUserFactory.create() user_1.hubs.create(hub=self.circle.hub) user_2 = FakeUserFactory.create() user_2.hubs.create(hub=self.circle.hub) post.reply(user_1, faker.text()) post.reply(user_2, faker.text()) post.reply(user_1, faker.text()) url = reverse('api:forum:post-answers', kwargs={'pk': post.pk}) # DO ACTION self.client.login(username=self.user.username, password='******') unseen_response = self.client.get(url) seen_response = self.client.get(url) # ASSERTS self.assertTrue(status.is_success(unseen_response.status_code)) data = unseen_response.json() for item in data.get('results', None): self.assertFalse(item.get('seen')) self.assertTrue(status.is_success(seen_response.status_code)) data = seen_response.json() for item in data.get('results', None): self.assertTrue(item.get('seen'))
def test_retrieve_post_answers(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_1 = FakeUserFactory.create() user_1.hubs.create(hub=self.circle.hub) user_2 = FakeUserFactory.create() user_2.hubs.create(hub=self.circle.hub) post.reply(user_1, faker.text()) post.reply(user_2, faker.text()) post.reply(self.user, faker.text()) post.reply(user_1, faker.text()) url = reverse('api:forum:post-answers', kwargs={'pk': post.pk}) # DO ACTION self.client.login(username=self.user.username, password='******') response = self.client.get(url) # ASSERTS self.assertTrue(status.is_success(response.status_code)) data = response.json() self.assertEqual(data.get('count'), 4)
def initialize_consultants(self): self.crete_certification_groups() consultants = [(4, 'Sevilla,CONSULTANT Spain', [CONSULTANT, COACH]), (2, 'London, United Kingdom', [CONSULTANT]), (6, 'Barcelona, Spain', [CONSULTANT]), (18, 'Rostock, Germany', [CONSULTANT, COACH]), (7, 'Berlin, Germany', [CONSULTANT, COACH]), (14, 'Tokyo, Japan', [CONSULTANT]), (8, 'Buenos Aires, Argentina', []), (3, 'Munich, Germany', [CONSULTANT])] for num_project, location, certified_roles in consultants: user = FakeUserFactory.create(password='******', is_active=True, location=location) consultant = FakeConsultantFactory( user=user, status=settings.CONSULTANT_STATUS_CH_ACTIVE) self.add_certifications_to_consultant(consultant, certified_roles) member = consultant.user.ecosystem_member member.num_projects = num_project member.save() self.user = user FakeConsultantFactory.create_batch( size=4, user__location='Jaen, Spain', status=settings.CONSULTANT_STATUS_CH_DISABLED) FakeConsultantFactory.create_batch( size=16, user__location='Granada, Spain', status=settings.CONSULTANT_STATUS_CH_ACTIVE)
def test_question_delete(self): # PREPARE DATA user = self.posts_first_A[0].created_by user_unauth = FakeUserFactory.create(is_superuser=False, is_active=True, password='******') query_params = { 'project_id': self.qa_session_first.project.pk, 'team_id': self.team_A.pk, 'swarm_id': self.qa_session_first.teams.get(team=self.team_A).pk, 'pk': self.posts_first_A[0].pk } url = reverse('api:swarms:swarms-project-questions-detail', kwargs=query_params) # DO ACTION self.client.login(username=user_unauth.username, password='******') response_unauth = self.client.delete(url) self.client.login(username=user.username, password='******') response = self.client.delete(url) # ASSERTS self.assertEqual(response_unauth.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
def test_pending_user_non_consultant_application_consultant(self, mock_request, mock_email): # PREPARE DATA mock_request.register_uri( 'POST', get_root_payments_url() + settings.EXO_CERTIFICATION_PAYMENTS_API_URL, json=get_payment_mock() ) user = FakeUserFactory.create() cert_request = CertificationRequest.objects.create( requester_email=user.email, requester_name=user.full_name, user=user, certification=ExOCertification.objects.get( level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2 ), ) payload = { 'country': 'PT', 'recaptcha': faker.word(), 'billingName': faker.name(), 'taxId': faker.word(), 'billingAddress': faker.address(), 'companyName': faker.name(), 'cohort': self.cohort_lvl_2.pk, 'application_details': self.generate_application_details_data(), } url = reverse('api:exo-certification:applications-detail', kwargs={'pk': cert_request.pk}) # DO ACTION response = self.client.put(url, data=payload) # ASSERTS self.assertTrue(status.is_success(response.status_code)) data = response.json() self.assertIsNotNone(data.get('nextUrl'))
def test_circle_feed(self): # PREPARE DATA team = FakeTeamFactory.create() participant = FakeUserFactory.create(password='******', is_active=True) self.add_user_to_team(participant, team) user = self.consultant.user user.is_staff = True user.save() questions = [] for i in range(2): questions.append( Post.objects.create_project_team_post(title=' '.join( faker.words()), user_from=participant, team=team)) announcements = [] for i in range(3): announcements.append( Post.objects.create_announcement_post( user_from=self.super_user, title=' '.join(faker.words()), description=faker.text())) posts = [] for i in range(4): posts.append( Post.objects.create_circle_post( circle=Circle.objects.get(slug='ecosystem'), user_from=self.super_user, title=' '.join(faker.words()), description=faker.text())) posts.append( Post.objects.create_circle_post( circle=Circle.objects.get(slug='trainers'), user_from=self.consultant.user, title=' '.join(faker.words()), description=faker.text())) posts[0].reply(user_from=self.consultant.user, comment=faker.text()) announcements[0].reply(user_from=self.consultant.user, comment=faker.text()) questions[0].reply(user_from=self.consultant.user, comment=faker.text()) url = reverse('api:forum:feed') # DO ACTION self.client.login(username=self.consultant.user.username, password='******') response = self.client.get(url) # ASSERTS self.assertTrue(status.is_success(response.status_code)) data = response.json() self.assertEqual(data.get('count'), 10)
def test_circle_list_fail(self): # PREPARE DATA user = FakeUserFactory.create(is_active=True, password='******') url = reverse('api:circles:circles-list') # DO ACTION self.client.login(username=user.username, password='******') response = self.client.get(url) # ASSERTS self.assertTrue(status.is_client_error(response.status_code))
def test_circle_post_list_fail(self): # PREPARE DATA user = FakeUserFactory.create(is_active=True, password='******') self.circle = Circle.objects.first() url_params = {'circle_slug': self.circle.slug} url = reverse('api:forum:circle-post-list', kwargs=url_params) # DO ACTION self.client.login(username=user.username, password='******') response = self.client.get(url, kwargs=url_params) # ASSERTS self.assertTrue(response.status_code, status.HTTP_404_NOT_FOUND)
def create_sprint(self): 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=self.super_user, email=self.user.email, name=self.user.short_name) self.team_B.add_member(user_from=self.super_user, email=self.secondary_user.email, name=self.secondary_user.short_name)
def test_question_update(self): # PREPARE DATA user = self.posts_first_A[0].created_by user_unauth = FakeUserFactory.create(is_superuser=False, is_active=True, password='******') query_params = { 'project_id': self.qa_session_first.project.pk, 'team_id': self.team_A.pk, 'swarm_id': self.qa_session_first.teams.get(team=self.team_A).pk, 'pk': self.posts_first_A[0].pk } new_tags = [] for i in range(6): keyword = FakeKeywordFactory.create() new_tags.append({ 'pk': keyword.pk, 'name': keyword.name, }) url = reverse('api:swarms:swarms-project-questions-detail', kwargs=query_params) # DO ACTION self.client.login(username=user.username, password='******') response = self.client.get(url) post = response.data payload_data = { 'title': '{} EDITED'.format(post.get('title')), 'description': post.get('description'), 'tags': new_tags, 'uploaded_files': self.get_files_example(4), } response = self.client.put(url, data=payload_data) self.client.login(username=user_unauth.username, password='******') response_unauth = self.client.put(url, data=payload_data) # ASSERTS self.assertEqual(response_unauth.status_code, status.HTTP_404_NOT_FOUND) data = response.json() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(data.get('title'), payload_data.get('title')) self.assertEqual(data.get('description'), payload_data.get('description')) self.assertEqual(len(data.get('tags')), len(payload_data.get('tags'))) self.assertEqual(len(data.get('uploadedFiles')), len(payload_data.get('uploaded_files')))
def test_announcement_post_fail(self): # PREPARE DATA user = FakeUserFactory.create(is_active=True, password='******') for i in range(30): Post.objects.create_announcement_post(user_from=self.super_user, title=' '.join( faker.words()), description=faker.text()) url = reverse('api:forum:circle-post-list', kwargs={'circle_slug': 'announcements'}) # DO ACTION self.client.login(username=user.username, password='******') response = self.client.get(url) # ASSERTS self.assertTrue(response.status_code, status.HTTP_404_NOT_FOUND)
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_certification_early_parrot_notification(self, mock_subscribe): # PREPARE DATA campaign = FakeCampaignFactory.create() user = FakeUserFactory.create() cert_request = CertificationRequest.objects.create( requester_email=user.email, requester_name=user.full_name, user=user, certification=ExOCertification.objects.get( level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2 ), status=settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_PENDING, price=1500, referrer='{}:{}'.format(faker.word(), campaign.campaign_id), ) # DO ACTION cert_request.notify_referrer(conversion=False) # ASSERTS self.assertTrue(mock_subscribe.called)
def test_get_post_without_answers_seen(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_1 = FakeUserFactory.create(password='******') user_1.hubs.create(hub=self.circle.hub) url = reverse('api:forum:post-answers', kwargs={'pk': post.pk}) # ASSERTS self.assertFalse(post.has_seen(user_1)) # DO ACTION self.client.login(username=user_1.username, password='******') response = self.client.get(url) # ASSERTS self.assertTrue(status.is_success(response.status_code)) self.assertTrue(post.has_seen(user_1))
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())