def test_get_nominee_right_split(self): UserFactory.create(first_name='Foo', last_name='Foo Bar', groups=['Rep']) user = get_nominee('Foo Foo Bar') ok_(user) eq_(user.first_name, 'Foo') eq_(user.last_name, 'Foo Bar')
def test_comment_multiple_users(self): """Test sending email when a new comment is added on a Poll and the users have the option enabled in their settings. """ commenter = UserFactory.create() creator = UserFactory.create( userprofile__receive_email_on_add_voting_comment=True) poll = PollFactoryNoSignals.create(created_by=creator) users_with_comments = UserFactory.create_batch( 2, userprofile__receive_email_on_add_voting_comment=True) # disconnect the signals in order to add two users in PollComment for user_obj in users_with_comments: PollCommentFactoryNoSignals.create( user=user_obj, poll=poll, comment='This is a comment') PollCommentFactory.create(user=commenter, poll=poll, comment='This is a comment') eq_(len(mail.outbox), 3) recipients = ['%s <%s>' % (creator.get_full_name(), creator.email), '%s <%s>' % (users_with_comments[0].get_full_name(), users_with_comments[0].email), '%s <%s>' % (users_with_comments[1].get_full_name(), users_with_comments[1].email)] receivers = [mail.outbox[0].to[0], mail.outbox[1].to[0], mail.outbox[2].to[0]] eq_(set(recipients), set(receivers)) msg = ('[Voting] User {0} commented on {1}' .format(commenter.get_full_name(), poll)) eq_(mail.outbox[0].subject, msg)
def test_list_no_alumni(self): """Test page header context for rep.""" UserFactory.create(groups=['Rep']) response = self.get(reverse('profiles_alumni')) self.assertTemplateUsed(response, 'profiles_list_alumni.html') eq_(response.status_code, 200) ok_(not response.context['objects'].object_list)
def test_view_dashboard_page(self): """Get dashboard page.""" c = Client() # Get as anonymous user. response = c.get(reverse('dashboard'), follow=True) eq_(response.status_code, 200) self.assertJinja2TemplateUsed(response, 'main.jinja') # Get as logged in rep. rep = UserFactory.create(groups=['Rep']) with self.login(rep) as client: response = client.get(reverse('dashboard')) eq_(response.status_code, 200) self.assertJinja2TemplateUsed(response, 'dashboard_reps.jinja') # Get as logged in mentor. mentor = UserFactory.create(groups=['Mentor']) with self.login(mentor) as client: response = client.get(reverse('dashboard')) eq_(response.status_code, 200) self.assertJinja2TemplateUsed(response, 'dashboard_reps.jinja') # Get as logged in counselor. councelor = UserFactory.create(groups=['Council']) with self.login(councelor) as client: response = client.get(reverse('dashboard')) eq_(response.status_code, 200) self.assertJinja2TemplateUsed(response, 'dashboard_reps.jinja')
def test_resolve_mentor_validation(self): model = ContentType.objects.get_for_model(Bug) items = ActionItem.objects.filter(content_type=model) ok_(not items.exists()) mentor = UserFactory.create(groups=['Rep', 'Mentor']) UserFactory.create(groups=['Rep'], userprofile__mentor=mentor) bug = BugFactory.build(pending_mentor_validation=True, assigned_to=mentor) bug.save() items = ActionItem.objects.filter(content_type=model) eq_(items.count(), 1) eq_(items[0].name, 'Waiting mentor validation for ' + bug.summary) eq_(items[0].user, mentor) eq_(items[0].priority, ActionItem.BLOCKER) bug.pending_mentor_validation = False bug.save() items = ActionItem.objects.filter(content_type=model, object_id=bug.id) for item in items: ok_(item.completed) ok_(item.resolved)
def test_base(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) event = EventFactory.create() functional_areas = [FunctionalAreaFactory.create()] campaign = CampaignFactory.create() activity = ActivityFactory.create() report = NGReportFactory.create( functional_areas=functional_areas, mentor=mentor, campaign=campaign, user=user, event=event, activity=activity) url = '/api/beta/activities/%s' % report.id request = RequestFactory().get(url) data = ActivitiesDetailedSerializer(report, context={'request': request}).data eq_(data['user']['first_name'], user.first_name) eq_(data['user']['last_name'], user.last_name) eq_(data['user']['display_name'], user.userprofile.display_name) ok_(data['user']['_url']) eq_(data['activity'], activity.name) eq_(data['initiative'], campaign.name) eq_(data['functional_areas'][0]['name'], functional_areas[0].name) eq_(data['activity_description'], report.activity_description) eq_(data['location'], report.location) eq_(data['latitude'], float(report.latitude)) eq_(data['longitude'], float(report.longitude)) eq_(data['report_date'], report.report_date.strftime('%Y-%m-%d')) eq_(data['link'], report.link) eq_(data['link_description'], report.link_description) eq_(data['mentor']['first_name'], mentor.first_name) eq_(data['mentor']['last_name'], mentor.last_name) eq_(data['mentor']['display_name'], mentor.userprofile.display_name) ok_(data['mentor']['_url']) eq_(data['passive_report'], report.is_passive) eq_(data['event']['name'], event.name) ok_(data['event']['_url'])
def test_comment_multiple_users(self): """Test sending email when a new comment is added on a NGReport and the users have the option enabled in their settings. """ commenter = UserFactory.create() reporter = UserFactory.create( userprofile__receive_email_on_add_comment=True) report = NGReportFactory.create(user=reporter) users_with_comments = UserFactory.create_batch( 2, userprofile__receive_email_on_add_comment=True) # disconnect the signals in order to add two users in NGReportComment for user_obj in users_with_comments: NGReportCommentFactoryNoSignals.create( user=user_obj, report=report, comment='This is a comment') NGReportCommentFactory.create(user=commenter, report=report, comment='This is a comment') eq_(len(mail.outbox), 3) recipients = ['%s <%s>' % (reporter.get_full_name(), reporter.email), '%s <%s>' % (users_with_comments[0].get_full_name(), users_with_comments[0].email), '%s <%s>' % (users_with_comments[1].get_full_name(), users_with_comments[1].email)] receivers = [mail.outbox[0].to[0], mail.outbox[1].to[0], mail.outbox[2].to[0]] eq_(set(recipients), set(receivers)) msg = ('[Report] User {0} commented on {1}' .format(commenter.get_full_name(), report)) eq_(mail.outbox[0].subject, msg)
def test_base(self): mentor = UserFactory.create() rep = UserFactory.create(userprofile__mentor=mentor) UserStatusFactory.create(user=rep, start_date=get_date(days=-1), is_unavailable=False) set_unavailability_flag() status = UserStatus.objects.get(user=rep) ok_(status.is_unavailable)
def test_send_notification(self): """Test sending of first notification to Reps to fill reports.""" mentor = UserFactory.create(groups=['Mentor']) rep = UserFactory.create(groups=['Rep'], userprofile__mentor=mentor) ReportFactoryWithoutSignals.create(user=rep) management.call_command('send_first_report_notification', [], {}) eq_(len(mail.outbox), 1)
def test_dry_run(self): """Test sending of first notification with debug activated.""" mentor = UserFactory.create(groups=['Mentor']) rep = UserFactory.create(groups=['Rep'], userprofile__mentor=mentor) ReportFactoryWithoutSignals.create(user=rep) management.call_command('send_first_report_notification', dry_run=True) eq_(len(mail.outbox), 0)
def setUp(self): """Setup tests.""" self.admin = UserFactory.create(username='******', groups=['Admin']) self.counselor = UserFactory.create(username='******') self.mentor = UserFactory.create(username='******', groups=['Mentor']) self.user = UserFactory.create(username='******', groups=['Rep'], userprofile__mentor=self.mentor) self.up = self.user.userprofile self.data = {'empty': False, 'recruits': '10', 'recruits_comments': 'This is recruit comments.', 'past_items': 'This is past items.', 'next_items': 'This is next items.', 'flags': 'This is flags.', 'delete_report': False, 'reportevent_set-TOTAL_FORMS': '1', 'reportevent_set-INITIAL_FORMS': '0', 'reportevent_set-MAX_NUM_FORMS': '', 'reportevent_set-0-id': '', 'reportevent_set-0-name': 'Event name', 'reportevent_set-0-description': 'Event description', 'reportevent_set-0-link': 'http://example.com/evtlnk', 'reportevent_set-0-participation_type': '1', 'reportevent_set-0-DELETE': False, 'reportlink_set-TOTAL_FORMS': '1', 'reportlink_set-INITIAL_FORMS': '0', 'reportlink_set-MAX_NUM_FORMS': '', 'reportlink_set-0-id': '', 'reportlink_set-0-link': 'http://example.com/link', 'reportlink_set-0-description': 'This is description', 'reportlink_set-0-DELETE': False}
def test_invalid_timespan(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) date = get_date(weeks=15) data = {'expected_date': date} form = UserStatusForm(data, instance=UserStatus(user=user)) ok_(not form.is_valid()) ok_('expected_date' in form.errors)
def test_change_invalid_bugzilla_email(self): """Test change bugzilla email with an invalid one.""" mentor = UserFactory.create(groups=["Mentor"], userprofile__initial_council=True) rep = UserFactory.create(groups=["Rep"], userprofile__mentor=mentor) data = {"first_name": rep.first_name, "last_name": rep.last_name, "email": mentor.email} form = ChangeUserForm(data=data, instance=rep) ok_(not form.is_valid())
def test_get_as_other_rep(self): user = UserFactory.create() rep = UserFactory.create() display_name = user.userprofile.display_name UserStatusFactory.create(user=user) url = reverse('edit_availability', kwargs={'display_name': display_name}) self.get(url=url, user=rep)
def test_get_as_anonymous(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) display_name = user.userprofile.display_name UserStatusFactory.create(user=user) client = Client() client.get(reverse('edit_availability', kwargs={'display_name': display_name}))
def test_automated_radio_poll_valid_bug(self): """Test the creation of an automated radio poll.""" UserFactory.create(username='******') bug = BugFactory.create(council_vote_requested=True, component='Budget Requests') poll = Poll.objects.get(bug=bug) eq_(poll.bug.bug_id, bug.bug_id) eq_(poll.description, bug.first_comment) eq_(poll.name, bug.summary)
def test_get_remo_url(self): mentor = UserFactory.create() functional_areas = FunctionalAreaFactory.create_batch(2) user = UserFactory.create(userprofile__mentor=mentor, groups=['Rep'], userprofile__functional_areas=functional_areas) url = '/api/beta/users/%s' % user.id request = RequestFactory().get(url) data = UserProfileDetailedSerializer(user.userprofile, context={'request': request}).data ok_(user.userprofile.get_absolute_url() in data['remo_url'])
def test_get_as_owner(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) display_name = user.userprofile.display_name UserStatusFactory.create(user=user) url = reverse('edit_availability', kwargs={'display_name': display_name}) self.get(url=url, user=user) self.assertTemplateUsed('edit_availability.html')
def test_uppercase_status(self): """Test that status and resolution are always saved in uppercase.""" mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) bug = BugFactory.create(bug_id=0000, status='foo', resolution='bar', assigned_to=user) eq_(bug.status, 'FOO') eq_(bug.resolution, 'BAR')
def test_with_report_filled(self): mentor = UserFactory.create(groups=["Mentor"]) today = now().date() rep = UserFactory.create(groups=["Rep"], userprofile__mentor=mentor) NGReportFactory.create(user=rep, report_date=today - timedelta(weeks=2)) with patch("remo.reports.utils.send_remo_mail") as mail_mock: send_second_report_notification() ok_(not mail_mock.called)
def test_delete_as_other_rep(self): user = UserFactory.create(groups=['Rep']) group = Group.objects.get(name='Rep') poll = PollFactory.create(created_by=user, valid_groups=group) comment = PollCommentFactory.create(poll=poll, user=user, comment='This is a comment') other_rep = UserFactory.create(groups=['Rep']) self.post(user=other_rep, url=comment.get_absolute_delete_url()) ok_(PollComment.objects.filter(pk=comment.id).exists())
def test_expected_date_before_start_date(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) start_date = get_date(4) expected_date = get_date(days=2) data = {'start_date': start_date, 'expected_date': expected_date} form = UserStatusForm(data, instance=UserStatus(user=user)) ok_(not form.is_valid()) ok_('expected_date' in form.errors)
def test_get_as_other_rep(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) rep = UserFactory.create() display_name = user.userprofile.display_name UserStatusFactory.create(user=user) url = reverse('edit_availability', kwargs={'display_name': display_name}) with self.login(rep) as client: client.get(url, user=rep)
def test_get_as_owner(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) display_name = user.userprofile.display_name UserStatusFactory.create(user=user) url = reverse('edit_availability', kwargs={'display_name': display_name}) with self.login(user) as client: response = client.get(url, user=user) self.assertJinja2TemplateUsed(response, 'edit_availability.jinja')
def test_base(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) date = get_date(days=1) data = {"expected_date": date} form = UserStatusForm(data, instance=UserStatus(user=user)) ok_(form.is_valid()) db_obj = form.save() eq_(db_obj.expected_date, get_date(days=1)) eq_(db_obj.user.get_full_name(), user.get_full_name())
def test_change_valid_bugzilla_email(self): """Test change bugzilla email with a valid one.""" mentor = UserFactory.create(groups=['Mentor'], userprofile__initial_council=True) rep = UserFactory.create(groups=['Rep'], userprofile__mentor=mentor, last_name='Doe') data = {'first_name': rep.first_name, 'last_name': rep.last_name, 'email': rep.email} form = ChangeUserForm(data=data, instance=rep) ok_(form.is_valid())
def test_change_invalid_login_email(self): """Test change login email with an invalid one.""" mentor = UserFactory.create(groups=['Mentor'], userprofile__initial_council=True) rep = UserFactory.create(groups=['Rep'], userprofile__mentor=mentor) data = {'first_name': rep.first_name, 'last_name': rep.last_name, 'email': mentor.email} form = ChangeUserForm(data=data, instance=rep) ok_(not form.is_valid())
def test_automated_radio_poll_already_exists(self): """Test that a radio poll is not created if the bug already exists. """ UserFactory.create(username='******') bug = BugFactory.create(council_vote_requested=True, component='Budget Requests') bug.first_comment = 'My first comment.' bug.save() eq_(Poll.objects.filter(automated_poll=True).count(), 1)
def test_edit_owner(self): """Test change event ownership.""" owner = UserFactory.create() EventFactory.create(owner=owner) report = NGReport.objects.get(user=owner) new_owner = UserFactory.create() report.event.owner = new_owner report.event.save() report = NGReport.objects.get(pk=report.id) eq_(report.user, new_owner) eq_(report.mentor, new_owner.userprofile.mentor)
def test_one_user_settings_False(self, mocked_mail): """Test sending email when a new comment is added on a NGReport and the user has the option disabled in his/her settings. """ comment_user = UserFactory.create() user = UserFactory.create( userprofile__receive_email_on_add_comment=False) report = NGReportFactory.create(user=user) NGReportCommentFactory.create(user=comment_user, report=report, comment='This is a comment') ok_(not mocked_mail.called)
def test_user_new_future_activity(self): report_notification = now().date() - datetime.timedelta(weeks=3) new_report_date = now().date() + datetime.timedelta(weeks=6) rep = UserFactory.create( groups=['Rep'], userprofile__first_report_notification=report_notification) NGReportFactory.create(user=rep, report_date=new_report_date) user = User.objects.get(pk=rep.id) eq_(user.userprofile.first_report_notification, report_notification)
def test_delete_event_admin(self, mock_success): """Test delete event with admin permissions.""" user = UserFactory.create(groups=['Admin']) event = EventFactory.create() with self.login(user) as client: response = client.post(reverse('events_delete_event', kwargs={'slug': event.slug}), follow=True) self.assertJinja2TemplateUsed(response, 'list_events.jinja') ok_(not Event.objects.filter(pk=event.id).exists()) mock_success.assert_called_with(ANY, 'Event successfully deleted.')
def test_base_content_campaign_delete_post(self): """Test delete campaign.""" admin = UserFactory.create(groups=['Admin']) campaign = CampaignFactory.create(name='test campaign') response = self.post(reverse('delete_campaign', kwargs={'pk': campaign.id}), user=admin, follow=True) eq_(response.status_code, 200) query = Campaign.objects.filter(name='test campaign') eq_(query.exists(), False)
def test_view_incomplete_profile_page_unauthed(self): """Test permission to view incomplete profile page unauthenticated.""" user = UserFactory.create(groups=['Rep'], first_name='', userprofile__registration_complete=False) name = user.userprofile.display_name url = reverse('profiles_view_profile', kwargs={'display_name': name}) response = self.client.get(url, follow=True) self.assertTemplateUsed(response, '404.html', 'Anonymous can view the page')
def test_base_content_activity_delete_post(self): """Test delete activity.""" admin = UserFactory.create(groups=['Admin']) activity = ActivityFactory.create(name='test activity') response = self.post(reverse('delete_activity', kwargs={'pk': activity.id}), user=admin, follow=True) eq_(response.status_code, 200) query = Activity.objects.filter(name='test activity') eq_(query.exists(), False)
def test_get_edit_event_admin(self, mock_success): """Test get event edit page with admin permissions""" user = UserFactory.create(groups=['Admin']) event = EventFactory.create() with self.login(user) as client: response = client.get(event.get_absolute_edit_url(), follow=True) eq_(response.request['PATH_INFO'], event.get_absolute_edit_url()) ok_(not response.context['creating']) ok_(response.context['event_form'].editable_owner) eq_(response.context['event'].slug, event.slug) self.assertJinja2TemplateUsed(response, 'edit_event.jinja')
def test_delete_as_owner(self, redirect_mock): user = UserFactory.create(groups=['Rep']) group = Group.objects.get(name='Rep') poll = PollFactory.create(created_by=user, valid_groups=group) comment = PollCommentFactory.create(poll=poll, user=user, comment='This is a comment') with self.login(user) as client: client.post(comment.get_absolute_delete_url(), user=comment.user) ok_(not PollComment.objects.filter(pk=comment.id).exists()) redirect_mock.assert_called_with(poll.get_absolute_url())
def test_post_a_comment(self, form_mock, messages_mock): user = UserFactory.create() report = NGReportFactory.create(user=user) form_mock.is_valid.return_value = True response = self.post(url=report.get_absolute_url(), user=user) eq_(response.status_code, 200) messages_mock.assert_called_with(mock.ANY, 'Comment saved successfully.') ok_(form_mock().save.called) eq_(response.context['report'], report) self.assertTemplateUsed('view_ng_report.html')
def test_edit_featured(self, form_mock, redirect_mock, messages_mock): form_mock.is_valid.return_value = True featured = FeaturedRepFactory.create() user = UserFactory.create(groups=['Admin']) response = self.post(url=reverse('featuredrep_edit_featured', args=[featured.id]), user=user) eq_(response.status_code, 200) messages_mock.assert_called_with( mock.ANY, 'Featured rep article successfuly edited.') ok_(form_mock().save.called)
def test_create_new_report(self, get_absolute_url_mock, form_mock, redirect_mock, messages_mock): form_mock.is_valid.return_value = True get_absolute_url_mock.return_value = 'main' user = UserFactory.create() response = self.post(url=reverse('reports_new_ng_report'), user=user) eq_(response.status_code, 200) messages_mock.assert_called_with(mock.ANY, 'Report successfully created.') redirect_mock.assert_called_with('main') ok_(form_mock().save.called)
def test_list(self): """Test view alumni list page.""" date_joined = now() - timedelta(days=10) date_left = now() + timedelta(days=10) user = UserFactory.create(groups=['Alumni'], userprofile__date_joined_program=date_joined, userprofile__date_left_program=date_left) response = self.client.get(reverse('profiles_alumni')) self.assertJinja2TemplateUsed(response, 'profiles_list_alumni.jinja') eq_(response.status_code, 200) eq_(set(response.context['objects'].object_list), set([user]))
def test_delete_event_no_permissions(self): """Test delete event no permissions.""" user = UserFactory.create(groups=['Rep']) event = EventFactory.create(slug='test-event') self.client.login(username=user.username, password='******') response = self.client.get(reverse('events_delete_event', kwargs={'slug': 'test-event'}), follow=True) self.assertTemplateUsed(response, 'main.html', ('Rep is not returned to main.html.')) ok_(Event.objects.filter(pk=event.id).exists())
def test_base_content_activities_list(self): """Test list activities.""" admin = UserFactory.create(groups=['Admin']) response = self.get(reverse('list_activities'), user=admin, follow=True) eq_(response.status_code, 200) eq_(response.context['verbose_name'], 'activity') eq_(response.context['verbose_name_plural'], 'activities') eq_(response.context['create_object_url'], reverse('create_activity')) self.assertTemplateUsed(response, 'base_content_list.html')
def test_view_incomplete_profile_page_authenticated(self): """Test view incomplete profile page without permissions.""" user = UserFactory.create(groups=['Rep'], first_name='', userprofile__registration_complete=False) name = user.userprofile.display_name url = reverse('profiles_view_profile', kwargs={'display_name': name}) self.client.login(username=self.rep.username, password='******') response = self.client.get(url, follow=True) self.assertTemplateUsed(response, '404.html', 'Rep without permission can view the page')
def test_base(self): past_day = get_date(-8) user = UserFactory.create(groups=['Rep']) NGReportFactory.create(user=user, report_date=past_day) user.userprofile.current_streak_start = past_day user.userprofile.save() zero_current_streak() user = User.objects.get(pk=user.id) ok_(not user.userprofile.current_streak_start)
def test_first_name_completes_registration(self): """Test that filling first_name automatically changes registration_complete variable to True. """ rep = UserFactory.create(groups=['Rep'], first_name='', userprofile__registration_complete=False) rep.first_name = u'Foobar' rep.save() ok_(rep.userprofile.registration_complete)
def test_needinfo(self): model = ContentType.objects.get_for_model(Bug) items = ActionItem.objects.filter(content_type=model) ok_(not items.exists()) needinfo = UserFactory.create(groups=['Rep']) user = UserFactory.create(groups=['Rep']) bug = BugFactory.build(assigned_to=user) bug.save() bug.budget_needinfo.add(needinfo) bug.save() items = ActionItem.objects.filter(content_type=model, object_id=bug.id) ok_(items.count(), 1) for item in items: eq_(item.name, 'Need info for ' + bug.summary) eq_(item.user, needinfo) ok_(item.priority, ActionItem.MINOR)
def test_base_content_functional_area_edit_post(self): """Test post edit functional area.""" admin = UserFactory.create(groups=['Admin']) area = FunctionalAreaFactory.create(name='test functional area') response = self.post(reverse('edit_functional_area', kwargs={'pk': area.id}), data={'name': 'edit functional area'}, user=admin, follow=True) eq_(response.status_code, 200) query = FunctionalArea.objects.filter(name='edit functional area') eq_(query.exists(), True)
def test_user_without_mentor(self, mocked_mail): task = MagicMock() task.task_id = 1 mocked_mail.return_value = task rep = UserFactory.create(userprofile__mentor=None) UserStatusFactory.create(user=rep) ok_(mocked_mail.called) eq_(mocked_mail.call_count, 1) data = mocked_mail.call_args_list[0][1] eq_(data['kwargs']['subject'], 'Confirm if you are available for Reps activities')
def test_post_delete_event_comment_user_no_perms(self): """Test delete event comment as rep without delete permissions.""" event = EventFactory.create(slug='test-event') user = UserFactory.create(groups=['Rep']) comment = EventCommentFactory.create(event=event) comment_delete = reverse('events_delete_event_comment', kwargs={'slug': 'test-event', 'pk': comment.id}) self.client.login(username=user.username, password='******') self.client.post(comment_delete, follow=True) ok_(EventComment.objects.filter(pk=comment.id).exists())
def test_get_edit_event_admin(self, mock_success): """Test get event edit page with admin permissions""" user = UserFactory.create(groups=['Admin']) EventFactory.create(slug='test-event') self.client.login(username=user.username, password='******') response = self.client.get(self.event_edit_url, follow=True) eq_(response.request['PATH_INFO'], self.event_edit_url) ok_(not response.context['creating']) ok_(response.context['event_form'].editable_owner) eq_(response.context['event'].slug, 'test-event') self.assertTemplateUsed('edit_event.html')
def test_base(self): mentor = UserFactory.create() functional_areas = FunctionalAreaFactory.create_batch(2) user = UserFactory.create( userprofile__mentor=mentor, groups=['Rep'], userprofile__functional_areas=functional_areas) url = '/api/beta/users/%s' % user.id request = RequestFactory().get(url) profile = user.userprofile data = UserProfileDetailedSerializer(user.userprofile, context={ 'request': request }).data eq_(data['first_name'], user.first_name) eq_(data['last_name'], user.last_name) eq_(data['display_name'], profile.display_name) eq_(data['date_joined_program'], profile.date_joined_program.strftime('%Y-%m-%d')) eq_(data['date_left_program'], profile.date_left_program) eq_(data['city'], profile.city) eq_(data['region'], profile.region) eq_(data['country'], profile.country) eq_(data['twitter_account'], profile.twitter_account) eq_(data['jabber_id'], profile.jabber_id) eq_(data['irc_name'], profile.irc_name) eq_(data['wiki_profile_url'], profile.wiki_profile_url) eq_(data['irc_channels'], profile.irc_channels) eq_(data['linkedin_url'], profile.linkedin_url) eq_(data['facebook_url'], profile.facebook_url) eq_(data['diaspora_url'], profile.diaspora_url) eq_(data['bio'], profile.bio) eq_(data['mozillians_profile_url'], profile.mozillians_profile_url) eq_(data['timezone'], profile.timezone) eq_(data['groups'][0]['name'], 'Rep') eq_(data['mentor']['first_name'], mentor.first_name) eq_(data['mentor']['last_name'], mentor.last_name) eq_(data['mentor']['display_name'], mentor.userprofile.display_name) ok_(data['mentor']['_url']) eq_(data['functional_areas'][0]['name'], functional_areas[0].name) eq_(data['functional_areas'][1]['name'], functional_areas[1].name)
def test_base_content_event_goal_edit_post(self): """Test post edit event goal.""" admin = UserFactory.create(groups=['Admin']) goal = EventGoalFactory.create(name='test event goal') response = self.post(reverse('edit_event_goal', kwargs={'pk': goal.id}), data={'name': 'edit event goal'}, user=admin, follow=True) eq_(response.status_code, 200) query = EventGoal.objects.filter(name='edit event goal') eq_(query.exists(), True)
def test_edit_event_page_no_delete_perms(self, mock_perm): """Test view edit event page without delete permissions.""" user = UserFactory.create(groups=['Admin']) event = EventFactory.create() mock_perm.side_effect = [True, False] with self.login(user) as client: response = client.get(event.get_absolute_edit_url(), follow=True) eq_(response.request['PATH_INFO'], event.get_absolute_edit_url()) ok_(not response.context['creating']) ok_(response.context['event_form'].editable_owner) eq_(response.context['event'].slug, event.slug) ok_(not response.context['can_delete_event'])
def test_unsubscribe_from_event_subscribed(self, mock_success): """Test unsubscribe from event subscribed user.""" user = UserFactory.create(groups=['Rep']) event = EventFactory.create() AttendanceFactory.create(user=user, event=event) with self.login(user) as client: response = client.post(reverse('events_unsubscribe_from_event', kwargs={'slug': event.slug}), follow=True) self.assertJinja2TemplateUsed(response, 'view_event.jinja') msg = 'You have unsubscribed from this event.' mock_success.assert_called_with(ANY, msg)
def test_new_report_initial_data(self): user = UserFactory.create(groups=['Mentor'], userprofile__city='City', userprofile__region='Region', userprofile__country='Country', userprofile__lat=0, userprofile__lon=90) response = self.get(url=reverse('reports_new_ng_report'), user=user) initial = response.context['report_form'].initial eq_(initial['location'], 'City, Region, Country') eq_(initial['latitude'], 0) eq_(initial['longitude'], 90)
def test_subscription_management_subscribed(self, mock_warning): """ Test subscribe already subscribed user.""" user = UserFactory.create(groups=['Rep']) event = EventFactory.create() AttendanceFactory.create(user=user, event=event) with self.login(user) as client: response = client.post(reverse('events_subscribe_to_event', kwargs={'slug': event.slug}), follow=True) self.assertJinja2TemplateUsed(response, 'view_event.jinja') msg = 'You are already subscribed to this event.' mock_warning.assert_called_with(ANY, msg)
def test_with_existing_action_item(self): owner = UserFactory.create() EventFactory.create(start=self.start, end=self.end, owner=owner) with patch('remo.events.tasks.send_remo_mail.delay') as mail_mock: notify_event_owners_to_input_metrics() ok_(mail_mock.called) with patch('remo.events.tasks.send_remo_mail.delay') as mail_mock1: notify_event_owners_to_input_metrics() ok_(not mail_mock1.called)
def test_without_message_and_template(self): recipient = UserFactory.create() subject = 'This is the subject' from_email = u'Joe Doe <*****@*****.**>' with patch('remo.base.tasks.EmailMessage') as mocked_email_message: send_remo_mail( subject, recipients_list=[recipient.id], sender=from_email, ) ok_(not mocked_email_message.called)
def test_unsubscribe_from_event_unsubscribed(self, mock_warning): """Test unsubscribe from event without subscription.""" user = UserFactory.create(groups=['Rep']) event = EventFactory.create() with self.login(user) as client: response = client.post(reverse('events_unsubscribe_from_event', kwargs={'slug': event.slug}), follow=True) self.assertJinja2TemplateUsed(response, 'view_event.jinja') msg = 'You are not subscribed to this event.' mock_warning.assert_called_with(ANY, msg)