def test_delete_deal_as_editor(self):
        # Delete deal as editor
        activity = HistoricalActivity.objects.public().latest()
        data = {
            # Action comment
            "tg_action_comment": "Test delete deal",
        }
        request = self.factory.post(reverse('delete_deal', kwargs={'deal_id': activity.activity_identifier}), data)
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['editor']
        response = DeleteDealView.as_view()(request, deal_id=activity.activity_identifier)
        #if response.status_code == 200:
        #    # For debugging purposes
        #    errors = list(filter(None, [form.errors or None for form in response.context_data['forms']]))
        #    self.assertEqual(errors, [])
        self.assertEqual(response.status_code, 302, msg='Delete deal does not redirect')

        activity = HistoricalActivity.objects.to_delete().latest()

        # Check if deal appears in manage section of administrator
        request = self.factory.get(reverse('manage_pending_deletes'))
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['administrator']
        response = ManageDeletesView.as_view()(request)
        self.assertEqual(response.status_code, 200, msg='Manage Pending Deletes of Administrator does not work')
        activities = list(response.context_data['activities'])
        self.assertEqual(len(activities), 1, msg='Wrong list of deals in Manage Pending Deletes of Administrator')
        self.assertEqual(activities[0]['id'], activity.id, msg='Deal does not appear in Manage Pending Deletes of Administrator')
        self.assertEqual(activities[0]['user'], self.users['editor'].username, msg='Deal has wrong user in Manage Pending Deletes of Administrator')

        # Approve deal as administrator
        data = {
            # Action comment
            "tg_action_comment": "Test approve by Administrator",
        }
        request = self.factory.post(reverse('manage_approve_delete_deal', kwargs={'id': activity.id}), data)
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['administrator']
        response = ApproveActivityDeleteView.as_view()(request, id=activity.id)
        #if response.status_code == 200:
        #    # For debugging purposes
        #    errors = list(filter(None, [form.errors or None for form in response.context_data['forms']]))
        #    self.assertEqual(errors, [])
        self.assertEqual(response.status_code, 302, msg='Approve deal does not redirect')

        self.is_deal_deleted(activity, self.users['editor'])
Beispiel #2
0
    def test_delete_deal_as_editor(self):
        # Delete deal as editor
        activity = HistoricalActivity.objects.public().latest()
        data = {
            # Action comment
            "tg_action_comment": "Test delete deal",
        }
        request = self.factory.post(
            reverse('delete_deal',
                    kwargs={'deal_id': activity.activity_identifier}), data)
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['editor']
        response = DeleteDealView.as_view()(
            request, deal_id=activity.activity_identifier)
        #if response.status_code == 200:
        #    # For debugging purposes
        #    errors = list(filter(None, [form.errors or None for form in response.context_data['forms']]))
        #    self.assertEqual(errors, [])
        self.assertEqual(response.status_code,
                         302,
                         msg='Delete deal does not redirect')

        activity = HistoricalActivity.objects.to_delete().latest()

        # Check if deal appears in manage section of administrator
        request = self.factory.get(reverse('manage_pending_deletes'))
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['administrator']
        response = ManageDeletesView.as_view()(request)
        self.assertEqual(
            response.status_code,
            200,
            msg='Manage Pending Deletes of Administrator does not work')
        activities = list(response.context_data['activities'])
        self.assertEqual(
            len(activities),
            1,
            msg='Wrong list of deals in Manage Pending Deletes of Administrator'
        )
        self.assertEqual(
            activities[0]['id'],
            activity.id,
            msg=
            'Deal does not appear in Manage Pending Deletes of Administrator')
        self.assertEqual(
            activities[0]['user'],
            self.users['editor'].username,
            msg='Deal has wrong user in Manage Pending Deletes of Administrator'
        )

        # Approve deal as administrator
        data = {
            # Action comment
            "tg_action_comment": "Test approve by Administrator",
        }
        request = self.factory.post(
            reverse('manage_approve_delete_deal', kwargs={'id': activity.id}),
            data)
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['administrator']
        response = ApproveActivityDeleteView.as_view()(request, id=activity.id)
        #if response.status_code == 200:
        #    # For debugging purposes
        #    errors = list(filter(None, [form.errors or None for form in response.context_data['forms']]))
        #    self.assertEqual(errors, [])
        self.assertEqual(response.status_code,
                         302,
                         msg='Approve deal does not redirect')

        self.is_deal_deleted(activity, self.users['editor'])
Beispiel #3
0
    ApproveActivityChangeView,
    RejectActivityChangeView,
    ApproveActivityDeleteView,
    RejectActivityDeleteView,
)

urlpatterns = [
    url(r'^$', DashboardView.as_view(), name='editor'),
    url(r'^manage/feedback/',
        ManageFeedbackView.as_view(),
        name='manage_feedback'),
    url(r'^manage/my_deals/',
        ManageMyDealsView.as_view(),
        name='manage_my_deals'),
    url(r'^manage/pending_deletes/',
        ManageDeletesView.as_view(),
        name='manage_pending_deletes'),
    url(r'^manage/pending_adds/',
        ManageAddsView.as_view(),
        name='manage_pending_adds'),
    url(r'^manage/pending_updates/',
        ManageUpdatesView.as_view(),
        name='manage_pending_updates'),
    url(r'^manage/rejected/',
        ManageRejectedView.as_view(),
        name='manage_rejected'),
    url(r'^manage/investor_deletes/',
        ManageInvestorDeletesView.as_view(),
        name='manage_investor_deletes'),
    url(r'^manage/deal/approve_change/(?P<id>[0-9]+)/',
        ApproveActivityChangeView.as_view(),
Beispiel #4
0
    def test_reporter(self):
        # Delete investor as reporter
        investor = HistoricalInvestor.objects.latest_only().public().latest()
        data = {
            # Action comment
            "tg_action_comment": "Test delete investor",
        }
        request = self.factory.post(
            reverse('investor_delete',
                    kwargs={'investor_id': investor.investor_identifier}),
            data)
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['reporter']
        response = DeleteInvestorView.as_view()(
            request, investor_id=investor.investor_identifier)
        #if response.status_code == 200:
        #    # For debugging purposes
        #    errors = list(filter(None, [form.errors or None for form in response.context_data['forms']]))
        #    self.assertEqual(errors, [])
        self.assertEqual(response.status_code,
                         302,
                         msg='Delete investor by Reporter does not redirect')

        investor = HistoricalInvestor.objects.latest_only().to_delete().latest(
        )

        # Check if investor appears in my investors section of reporter
        request = self.factory.get(reverse('manage_for_user'))
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['reporter']
        response = ManageForUserView.as_view()(request)
        self.assertEqual(
            response.status_code,
            200,
            msg='Manage My Deals/Investors of Reporter does not work')
        self.assert_investor_in_list(response, investor)

        # Check if investor appears in manage section of administrator
        request = self.factory.get(reverse('manage_pending_deletes'))
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['administrator']
        response = ManageDeletesView.as_view()(request)
        self.assertEqual(
            response.status_code,
            200,
            msg='Manage Pending Deletes of Administrator does not work')
        self.assert_investor_in_list(response, investor)

        # Check if investor appears in manage section of editor
        request = self.factory.get(reverse('manage_pending_deletes'))
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['editor']
        response = ManageDeletesView.as_view()(request)
        self.assertEqual(response.status_code,
                         200,
                         msg='Manage Pending Deletes of Editor does not work')
        self.assert_investor_in_list(response, investor, role='reporter')

        # Approve investor as editor
        data = {
            # Action comment
            "tg_action_comment": "Test approve by Editor",
        }
        request = self.factory.post(
            reverse('manage_approve_delete_investor',
                    kwargs={'id': investor.id}), data)
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['editor']
        response = ApproveInvestorDeleteView.as_view()(request, id=investor.id)
        #if response.status_code == 200:
        #    # For debugging purposes
        #    errors = list(filter(None, [form.errors or None for form in response.context_data['forms']]))
        #    self.assertEqual(errors, [])
        self.assertEqual(response.status_code,
                         302,
                         msg='Approve investor by Editor does not redirect')

        # Check if investor appears in manage section of administrator
        request = self.factory.get(reverse('manage_pending_deletes'))
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['administrator']
        response = ManageDeletesView.as_view()(request)
        self.assertEqual(
            response.status_code,
            200,
            msg='Manage Pending Deletes of Administrator does not work')
        self.assert_investor_in_list(response, investor, role='reporter')

        # Approve investor as administrator
        data = {
            # Action comment
            "tg_action_comment": "Test approve by Administrator",
        }
        request = self.factory.post(
            reverse('manage_approve_delete_investor',
                    kwargs={'id': investor.id}), data)
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = self.users['administrator']
        response = ApproveInvestorDeleteView.as_view()(request, id=investor.id)
        #if response.status_code == 200:
        #    # For debugging purposes
        #    errors = list(filter(None, [form.errors or None for form in response.context_data['forms']]))
        #    self.assertEqual(errors, [])
        self.assertEqual(
            response.status_code,
            302,
            msg='Approve investor by Administrator does not redirect')

        self.assert_investor_deleted(investor, self.users['reporter'])
Beispiel #5
0
    ManageDeletesView, ManageInvestorDeletesView, ManageMyDealsView,
    ManageRootView, ApproveActivityChangeView, RejectActivityChangeView,
    ApproveActivityDeleteView, RejectActivityDeleteView,
)


urlpatterns = [
    url(r'^$', DashboardView.as_view(), name='editor'),
    url(
        r'^manage/feedback/', ManageFeedbackView.as_view(),
        name='manage_feedback'),
    url(
        r'^manage/my_deals/', ManageMyDealsView.as_view(),
        name='manage_my_deals'),
    url(
        r'^manage/pending_deletes/', ManageDeletesView.as_view(),
        name='manage_pending_deletes'),
    url(
        r'^manage/pending_adds/', ManageAddsView.as_view(),
        name='manage_pending_adds'),
    url(
        r'^manage/pending_updates/', ManageUpdatesView.as_view(),
        name='manage_pending_updates'),
    url(
        r'^manage/rejected/', ManageRejectedView.as_view(),
        name='manage_rejected'),
    url(
        r'^manage/investor_deletes/', ManageInvestorDeletesView.as_view(),
        name='manage_investor_deletes'),
    url(
        r'^manage/deal/approve_change/(?P<id>[0-9]+)/',