Beispiel #1
0
    def assert_deal_created(self, activity, user):
        # Check if deal is public
        request = self.factory.get(
            reverse('deal_detail',
                    kwargs={'deal_id': activity.activity_identifier}))
        request.user = AnonymousUser()
        response = DealDetailView.as_view()(
            request, deal_id=activity.activity_identifier)
        self.assertEqual(
            response.status_code,
            200,
            msg='Deal is not public after approval of Administrator')

        # Check if deal is in latest added log
        request = self.factory.get(reverse('log_added'))
        request.user = user
        response = LogAddedView.as_view()(request)
        self.assertEqual(response.status_code,
                         200,
                         msg='Latest Added Log does not work')
        self.assert_deal_in_list(response, activity)

        # Check if deal is in elasticsearch/export
        self.run_commit_hooks()
        request = self.factory.get(reverse('export', kwargs={'format': 'xls'}))
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = AnonymousUser()
        response = ExportView.as_view()(request, format='xls')
        self.assertEqual(response.status_code, 200, msg='Export does not work')
        wb = load_workbook(BytesIO(response.content), read_only=True)
        ws = wb['Deals']
        activity_identifiers = [row[0].value for row in ws.rows]
    def handle(self, *args, **options):
        # Get export
        rf = RequestFactory()
        request = rf.get('/data/all.xls')
        request.session = {}
        request.user = AnonymousUser()
        export = ExportView()
        export.request = request
        export.set_default_filters({})
        query = export.create_query_from_filters()
        sort = ['activity_identifier',]
        results = {}
        deals = export.execute_elasticsearch_query(query, doc_type='deal', fallback=False,
                                                  sort=sort)
        deals = export.filter_deals(deals)
        export_deals = list(deals)
        export_ids = set(row['activity_identifier'] for row in export_deals)
        export_count = len(export_ids)

        # Get grid
        rf = RequestFactory()
        request = rf.get('/')
        request.session = {}
        request.user = AnonymousUser()
        grid = OldTableGroupView()
        grid.group = 'all'
        grid.request = request
        grid._limit_query = lambda: False
        query_result = grid.get_records()
        grid_deals = grid._get_items(query_result)
        grid_ids = set(row['deal_id'] for row in grid_deals)
        grid_count = len(grid_ids)

        self.stdout.write("{} deals found in export".format(str(export_count)))
        self.stdout.write("{} deals found in grid".format(str(grid_count)))

        missing_grid = export_ids - grid_ids
        self.stdout.write("{} deals missing in grid ({})".format(str(len(missing_grid)),
                                                                 ', '.join([str(i)
                                                                            for i in
                                                                            missing_grid])))
        missing_export = grid_ids - export_ids
        self.stdout.write("{} deals missing in export ({})".format(str(len(missing_export)),
                                                                 ', '.join([str(i) for i in
                                                                            missing_export])))
Beispiel #3
0
    def assert_investor_deleted(self, investor, user=None):
        # Check if investor is NOT public
        request = self.factory.get(
            reverse('investor_detail',
                    kwargs={'investor_id': investor.investor_identifier}))
        request.user = AnonymousUser()
        try:
            response = InvestorDetailView.as_view()(
                request, investor_id=investor.investor_identifier)
        except Http404:
            pass
        else:
            self.fail("Investor still exists after deletion")

        # Check if investor is in latest deleted log
        request = self.factory.get(reverse('log_deleted'))
        request.user = user
        response = LogDeletedView.as_view()(request)
        self.assertEqual(response.status_code,
                         200,
                         msg='Latest Deleted Log does not work')
        self.assert_investor_in_list(response, investor)

        # Check if investor is NOT in elasticsearch/export
        self.run_commit_hooks()
        request = self.factory.get(reverse('export', kwargs={'format': 'xls'}))
        # Mock messages framework (not available for unit tests)
        setattr(request, 'session', {})
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        request.user = AnonymousUser()
        response = ExportView.as_view()(request, format='xls')
        self.assertEqual(response.status_code, 200, msg='Export does not work')
        wb = load_workbook(BytesIO(response.content), read_only=True)
        ws = wb['Investors']
        investor_identifiers = [row[0].value for row in ws.rows]
Beispiel #4
0
     DealDetailView.as_view(),
     name='deal_detail'),
 url(r'^deal/(?P<deal_id>\d+)/(?P<history_id>\d+)/$',
     DealDetailView.as_view(),
     name='deal_detail'),
 url(r'^deal/(?P<deal_id>\d+)\.pdf$',
     DealDetailView.as_view(), {'format': 'PDF'},
     name='deal_detail_pdf'),
 url(r'^deal/(?P<deal_id>\d+)/(?P<history_id>\d+)\.pdf$',
     DealDetailView.as_view(), {'format': 'PDF'},
     name='deal_detail_pdf'),
 url(r'^deal/(?P<deal_id>\d+)/changes\.rss$',
     ActivityChangesFeed(),
     name='deal_changes_feed'),
 url(r'^deal/(?P<deal_id>\d+)\.(?P<format>(csv|xml|xls))/$',
     ExportView.as_view(),
     name='export'),
 url(r'^deal/edit/(?P<deal_id>\d+)/$',
     DealUpdateView.as_view(),
     name='change_deal'),
 url(r'^deal/edit/(?P<deal_id>\d+)/(?P<history_id>\d+)/$',
     DealUpdateView.as_view(),
     name='change_deal'),
 url(r'^deal/add/$', DealCreateView.as_view(), name='add_deal'),
 url(r'^deal/delete/(?P<deal_id>\d+)/$',
     DeleteDealView.as_view(),
     name='delete_deal'),
 url(r'^deal/recover/(?P<deal_id>\d+)/$',
     DealRecoverView.as_view(),
     name='recover_deal'),
 url(r'^compare/(?P<activity_1>\d+)/(?P<activity_2>\d+)/$',
Beispiel #5
0
CACHE_TIMEOUT = 24*3600

urlpatterns = [
    # please leave them here, commented out, for quick cache de-/activation when developing
    # url(r'^$', DealsView.as_view(), name='app_main'),
    # url(r'^(?P<group>.+)/(?P<list>.+)/$', DealListView.as_view(), name='deal_list'),

    url(
        r'^$',
        save_filter_query_params()(DealListView.as_view()),
        name='data'
    ),
    url(
        r'^all\.(?P<format>(csv|xml|xls))/$',
        save_filter_query_params()(ExportView.as_view()),
        name='export'
    ),
    url(
        r'^(?P<group>.+)/(?P<group_value>.+)\.(?P<format>(csv|xml|xls))/$',
        save_filter_query_params()(ExportView.as_view()),
        name='export'
    ),
    url(
        r'^(?P<group>.+)\.(?P<format>(csv|xml|xls))/$',
        save_filter_query_params()(ExportView.as_view()),
        name='export'
    ),

    url(
        r'^investors/$',