Esempio n. 1
0
    def test_bad_restore(self):
        user = Mock()
        user.domain = None
        app_id = None
        request = Mock()
        request.GET = {}
        request.openrosa_headers = {}
        timing_context = Mock()
        timing_context.to_list.return_value = []
        with patch('corehq.apps.hqadmin.views.users.get_restore_response',
                   return_value=(HttpResponse('bad response',
                                              status=500), timing_context)):

            view = AdminRestoreView(user=user, app_id=app_id, request=request)
            context = view.get_context_data(foo='bar', view='AdminRestoreView')
            self.assertEqual(
                context, {
                    'foo':
                    'bar',
                    'view':
                    'AdminRestoreView',
                    'payload':
                    '<error>Unexpected restore response 500: bad response. If you believe this is a bug '
                    'please report an issue.</error>\n',
                    'status_code':
                    500,
                    'timing_data': [],
                    'hide_xml':
                    False,
                })
Esempio n. 2
0
 def test_admin_restore_counts(self):
     xml_payload = etree.fromstring(self.get_xml('restore'))
     self.assertEqual(
         AdminRestoreView.get_stats_from_xml(xml_payload), {
             'restore_id': '02bbfb3ea17711e8adb9bc764e203eaf',
             'num_cases': 2,
             'num_locations': 7,
             'num_v1_reports': 2,
             'num_v2_reports': 2,
             'case_type_counts': {},
             'location_type_counts': {
                 'country': 1,
                 'state': 1,
                 'county': 1,
                 'city': 1,
                 'neighborhood': 3,
             },
             'v1_report_row_counts': {
                 'e009c3dc89b0250a8accd09b9641c3250f4e38d0--0dc41ff3e342d3ac94c06bb5c6cdd416':
                 3,
                 '42dc83c562a474b7e5faba4fc3190ca37bd4777f--f1761733213601f7f77defc3bc2e2c87':
                 3,
             },
             'v2_report_row_counts': {
                 'commcare-reports:e009c3dc89b0250a8accd09b9641c3250f4e38d0--0dc41ff3e342d3ac94c06bb5c6cdd416':
                 3,
                 'commcare-reports:42dc83c562a474b7e5faba4fc3190ca37bd4777f--f1761733213601f7f77defc3bc2e2c87':
                 3,
             },
             'num_ledger_entries': 0,
         })
Esempio n. 3
0
 def test_admin_restore_counts(self):
     xml_payload = etree.fromstring(self.get_xml('restore'))
     self.assertEqual(AdminRestoreView.get_stats_from_xml(xml_payload), {
         'restore_id': '02bbfb3ea17711e8adb9bc764e203eaf',
         'num_cases': 2,
         'num_locations': 7,
         'num_v1_reports': 2,
         'num_v2_reports': 2,
         'case_type_counts': {},
         'location_type_counts': {
             'country': 1,
             'state': 1,
             'county': 1,
             'city': 1,
             'neighborhood': 3,
         },
         'v1_report_row_counts': {
             '0dc41ff3e342d3ac94c06bb5c6cdd416': 3,
             'f1761733213601f7f77defc3bc2e2c87': 3,
         },
         'v2_report_row_counts': {
             '0dc41ff3e342d3ac94c06bb5c6cdd416': 3,
             'f1761733213601f7f77defc3bc2e2c87': 3,
         },
         'num_ledger_entries': 0,
     })
Esempio n. 4
0
 def test_admin_restore_counts(self):
     xml_payload = etree.fromstring(self.get_xml('restore'))
     self.assertEqual(AdminRestoreView.get_stats_from_xml(xml_payload), {
         'restore_id': '02bbfb3ea17711e8adb9bc764e203eaf',
         'num_cases': 2,
         'num_locations': 7,
         'num_v1_reports': 2,
         'num_v2_reports': 2,
         'case_type_counts': {},
         'location_type_counts': {
             'country': 1,
             'state': 1,
             'county': 1,
             'city': 1,
             'neighborhood': 3,
         },
         'v1_report_row_counts': {
             'e009c3dc89b0250a8accd09b9641c3250f4e38d0--0dc41ff3e342d3ac94c06bb5c6cdd416': 3,
             '42dc83c562a474b7e5faba4fc3190ca37bd4777f--f1761733213601f7f77defc3bc2e2c87': 3,
         },
         'v2_report_row_counts': {
             'commcare-reports:e009c3dc89b0250a8accd09b9641c3250f4e38d0--0dc41ff3e342d3ac94c06bb5c6cdd416': 3,
             'commcare-reports:42dc83c562a474b7e5faba4fc3190ca37bd4777f--f1761733213601f7f77defc3bc2e2c87': 3,
         },
         'num_ledger_entries': 0,
     })
Esempio n. 5
0
 def test_admin_restore_counts(self):
     xml_payload = etree.fromstring(self.get_xml('restore'))
     self.assertEqual(
         AdminRestoreView.get_stats_from_xml(xml_payload), {
             'restore_id': None,
             'num_cases': 2,
             'num_locations': 7,
             'num_v1_reports': 2,
             'num_v2_reports': 2,
             'case_type_counts': {},
             'location_type_counts': {
                 'country': 1,
                 'state': 1,
                 'county': 1,
                 'city': 1,
                 'neighborhood': 3,
             },
             'v1_report_row_counts': {
                 '0dc41ff3e342d3ac94c06bb5c6cdd416': 3,
                 'f1761733213601f7f77defc3bc2e2c87': 3,
             },
             'v2_report_row_counts': {
                 '0dc41ff3e342d3ac94c06bb5c6cdd416': 3,
                 'f1761733213601f7f77defc3bc2e2c87': 3,
             },
             'num_ledger_entries': 0,
         })
Esempio n. 6
0
    def test_bad_restore(self):
        user = Mock()
        user.domain = None
        app_id = None
        request = Mock()
        request.GET = {}
        request.openrosa_headers = {}
        timing_context = Mock()
        timing_context.to_list.return_value = []
        with patch('corehq.apps.hqadmin.views.users.get_restore_response',
                   return_value=(HttpResponse('bad response', status=500), timing_context)):

            view = AdminRestoreView(user=user, app_id=app_id, request=request)
            context = view.get_context_data(foo='bar', view='AdminRestoreView')
            self.assertEqual(context, {
                'foo': 'bar',
                'view': 'AdminRestoreView',
                'payload': '<error>Unexpected restore response 500: bad response. If you believe this is a bug '
                           'please report an issue.</error>\n',
                'status_code': 500,
                'timing_data': [],
                'hide_xml': False,
            })
Esempio n. 7
0
def _get_headers_and_rows(domain, users, app_id):
    fixture_names = set()
    rows = []
    for user in users:
        response, timing_context = get_restore_response(
            domain,
            user,
            app_id=app_id,
        )
        timing_dict = timing_context.to_dict()
        xml_payload = etree.fromstring(b''.join(response.streaming_content))
        stats = AdminRestoreView.get_stats_from_xml(xml_payload)
        row = {
            'timestamp': datetime.datetime.now().isoformat(),
            'username': user.username,
            'total_duration': timing_dict['duration'],
            'num_cases': stats['num_cases'],
            'num_locations': stats['num_locations'],
            'num_v1_reports': stats['num_v1_reports'],
            'num_v2_reports': stats['num_v2_reports'],
            'num_ledger_entries': stats['num_ledger_entries'],
        }
        for provider in timing_dict['subs']:
            row[provider['name']] = provider['duration']
            if provider['name'] == 'FixtureElementProvider':
                for fixture in provider['subs']:
                    fixture_names.add(fixture['name'])
                    row[fixture['name']] = fixture['duration']
        rows.append(row)
        print("Restore for '{}' took {} seconds to generate".format(
            user.username, timing_dict['duration']))

    headers = [
        'username',
        'timestamp',
        'total_duration',
        'num_cases',
        'num_locations',
        'num_v1_reports',
        'num_v2_reports',
        'num_ledger_entries',
        'RegistrationElementProvider',
        'CasePayloadProvider',
        'SyncElementProvider',
        'FixtureElementProvider',
    ] + sorted(fixture_names)

    return headers, rows
Esempio n. 8
0
     branches_on_staging,
     name="branches_on_staging"),
 url(r'^mass_email/$', mass_email, name="mass_email"),
 # Same view supported with three possible urls to support tracking
 # username and domain in the url via audit
 url(r'^auth_as/$', AuthenticateAs.as_view(), name=AuthenticateAs.urlname),
 url(r'^auth_as/(?P<username>[^/]*)/$',
     AuthenticateAs.as_view(),
     name=AuthenticateAs.urlname),
 url(r'^auth_as/(?P<username>[^/]*)/(?P<domain>{})/$'.format(new_domain_re),
     AuthenticateAs.as_view(),
     name=AuthenticateAs.urlname),
 url(r'^superuser_management/$',
     SuperuserManagement.as_view(),
     name=SuperuserManagement.urlname),
 url(r'^phone/restore/$', AdminRestoreView.as_view(), name="admin_restore"),
 url(r'^phone/restore/(?P<app_id>[\w-]+)/$',
     AdminRestoreView.as_view(),
     name='app_aware_admin_restore'),
 url(r'^stats_data/$', stats_data, name="admin_stats_data"),
 url(r'^admin_reports_stats_data/$',
     admin_reports_stats_data,
     name="admin_reports_stats_data"),
 url(r'^do_pillow_op/$', pillow_operation_api, name="pillow_operation_api"),
 url(r'^web_user_lookup/$', web_user_lookup, name='web_user_lookup'),
 url(r'^disable_two_factor/$',
     DisableTwoFactorView.as_view(),
     name=DisableTwoFactorView.urlname),
 url(r'^disable_account/$',
     DisableUserView.as_view(),
     name=DisableUserView.urlname),
Esempio n. 9
0
 url(r'^system/$', SystemInfoView.as_view(), name=SystemInfoView.urlname),
 url(r'^system/recent_changes/$', RecentCouchChangesView.as_view(),
     name=RecentCouchChangesView.urlname),
 url(r'^system/recent_changes/download/$', download_recent_changes, name="download_recent_changes"),
 url(r'^system/system_ajax$', system_ajax, name="system_ajax"),
 url(r'^system/check_services$', check_services, name="check_services"),
 url(r'^system/autostaging/$', branches_on_staging, name="branches_on_staging"),
 url(r'^mass_email/$', mass_email, name="mass_email"),
 # Same view supported with three possible urls to support tracking
 # username and domain in the url via audit
 url(r'^auth_as/$', AuthenticateAs.as_view(), name=AuthenticateAs.urlname),
 url(r'^auth_as/(?P<username>[^/]*)/$', AuthenticateAs.as_view(), name=AuthenticateAs.urlname),
 url(r'^auth_as/(?P<username>[^/]*)/(?P<domain>{})/$'.format(new_domain_re),
     AuthenticateAs.as_view(), name=AuthenticateAs.urlname),
 url(r'^superuser_management/$', SuperuserManagement.as_view(), name=SuperuserManagement.urlname),
 url(r'^phone/restore/$', AdminRestoreView.as_view(), name="admin_restore"),
 url(r'^phone/restore/(?P<app_id>[\w-]+)/$', AdminRestoreView.as_view(), name='app_aware_admin_restore'),
 url(r'^app_build_timings/$', AppBuildTimingsView.as_view(), name="app_build_timings"),
 url(r'^stats_data/$', stats_data, name="admin_stats_data"),
 url(r'^admin_reports_stats_data/$', admin_reports_stats_data, name="admin_reports_stats_data"),
 url(r'^do_pillow_op/$', pillow_operation_api, name="pillow_operation_api"),
 url(r'^web_user_lookup/$', web_user_lookup, name='web_user_lookup'),
 url(r'^disable_two_factor/$', DisableTwoFactorView.as_view(), name=DisableTwoFactorView.urlname),
 url(r'^disable_account/$', DisableUserView.as_view(), name=DisableUserView.urlname),
 url(r'^doc_in_es/$', doc_in_es, name='doc_in_es'),
 url(r'^raw_couch/$', raw_couch, name='raw_couch'),
 url(r'^raw_doc/$', raw_doc, name='raw_doc'),
 url(r'^api/', include(admin_api_urlpatterns)),
 url(r'^callcenter_ucr_check/$', CallcenterUCRCheck.as_view(), name=CallcenterUCRCheck.urlname),
 url(r'^download_malt/$',
     DownloadMALTView.as_view(), name=DownloadMALTView.urlname),
Esempio n. 10
0
 url(r'^system/$', SystemInfoView.as_view(), name=SystemInfoView.urlname),
 url(r'^system/recent_changes/$', RecentCouchChangesView.as_view(),
     name=RecentCouchChangesView.urlname),
 url(r'^system/recent_changes/download/$', download_recent_changes, name="download_recent_changes"),
 url(r'^system/system_ajax$', system_ajax, name="system_ajax"),
 url(r'^system/check_services$', check_services, name="check_services"),
 url(r'^system/autostaging/$', branches_on_staging, name="branches_on_staging"),
 url(r'^mass_email/$', mass_email, name="mass_email"),
 # Same view supported with three possible urls to support tracking
 # username and domain in the url via audit
 url(r'^auth_as/$', AuthenticateAs.as_view(), name=AuthenticateAs.urlname),
 url(r'^auth_as/(?P<username>[^/]*)/$', AuthenticateAs.as_view(), name=AuthenticateAs.urlname),
 url(r'^auth_as/(?P<username>[^/]*)/(?P<domain>{})/$'.format(new_domain_re),
     AuthenticateAs.as_view(), name=AuthenticateAs.urlname),
 url(r'^superuser_management/$', SuperuserManagement.as_view(), name=SuperuserManagement.urlname),
 url(r'^phone/restore/$', AdminRestoreView.as_view(), name="admin_restore"),
 url(r'^phone/restore/(?P<app_id>[\w-]+)/$', AdminRestoreView.as_view(), name='app_aware_admin_restore'),
 url(r'^app_build_timings/$', AppBuildTimingsView.as_view(), name="app_build_timings"),
 url(r'^do_pillow_op/$', pillow_operation_api, name="pillow_operation_api"),
 url(r'^web_user_lookup/$', web_user_lookup, name='web_user_lookup'),
 url(r'^disable_two_factor/$', DisableTwoFactorView.as_view(), name=DisableTwoFactorView.urlname),
 url(r'^disable_account/$', DisableUserView.as_view(), name=DisableUserView.urlname),
 url(r'^doc_in_es/$', doc_in_es, name='doc_in_es'),
 url(r'^raw_couch/$', raw_doc, name='raw_couch'),
 url(r'^raw_doc/$', raw_doc, name='raw_doc'),
 url(r'^api/', include(admin_api_urlpatterns)),
 url(r'^callcenter_ucr_check/$', CallcenterUCRCheck.as_view(), name=CallcenterUCRCheck.urlname),
 url(r'^download_malt/$',
     DownloadMALTView.as_view(), name=DownloadMALTView.urlname),
 url(r'^download_gir', DownloadGIRView.as_view(), name=DownloadGIRView.urlname),
 url(r'^reprocess_messaging_case_updates/$', ReprocessMessagingCaseUpdatesView.as_view(),