def test_get_active_characteristics_filters_by_period(self): self.setup_test_data() period_1 = ReportingPeriod.get(ReportingPeriod.title == 'Period 1') clinic_a = Clinic.get(Clinic.name == 'Clinic A') period2 = ReportingPeriod( title='Period 2', start_date=datetime.datetime(2014, 1, 1), end_date=datetime.datetime(2014, 1, 1)) DBSession.add(period2) DBSession.flush() clinic_char1 = ClinicCharacteristics( clinic_id=clinic_a.id, characteristic_id='one', period_id=period_1.id) clinic_char2 = ClinicCharacteristics( clinic_id=clinic_a.id, characteristic_id='one', period_id=period2.id) DBSession.add_all([clinic_char1, clinic_char2]) characteristics = clinic_a.get_active_characteristics(period_1) self.assertEqual(len(characteristics), 1)
def test_get_period_submissions(self): self.setup_test_data() self.create_submissions() clinic = Clinic.get(Clinic.name == 'Clinic A') period = ReportingPeriod.get(ReportingPeriod.title == "Period 1") submissions = clinic.get_period_clinic_submissions(period.form_xpath) self.assertEqual(len(submissions), 50)
def test_clinic_report_is_generated_if_none_existent_v3(self): count = ClinicReport.count() clinic = Clinic.get(Clinic.id == 4) period = ReportingPeriod.get(ReportingPeriod.title == 'Period 2017') ClinicReport.get_or_generate(clinic, period) self.assertEqual(ClinicReport.count(), count + 1)
def get_period_from_request(request): try: period = ReportingPeriod.get( ReportingPeriod.id == request.GET.get('period', 0)) except NoResultFound: period = ReportingPeriod.get_current_period() return period
def test_clinic_show_allows_owner(self): period = ReportingPeriod.get(ReportingPeriod.title == 'Period 1') clinic = Clinic.get(Clinic.name == "Clinic A") url = self.request.route_path('clinics', traverse=(clinic.id, period.id)) headers = self._login_user('manager_a') response = self.testapp.get(url, headers=headers) self.assertEqual(response.status_code, 200)
def test_characteristics_returns_200(self): clinic = Clinic.get(Clinic.name == "Clinic A") period = ReportingPeriod.get(ReportingPeriod.title == 'Period 1') url = self.request.route_path('clinics', traverse=(clinic.id, period.id, 'characteristics')) headers = self._login_user('super') response = self.testapp.get(url, headers=headers) self.assertEqual(response.status_code, 200)
def __getitem__(self, item): # retrieve the reporting period try: period_id = int(item) period = ReportingPeriod.get(ReportingPeriod.id == period_id) except (ValueError, NoResultFound): raise KeyError else: period.__parent__ = self period.__name__ = item return period
def test_render_unauthorized_when_forbidden_and_authenticated(self): # TODO: move setup_test_data call to setUp self.setup_test_data() self._create_user('john') clinic = Clinic.get(Clinic.name == "Clinic A") period = ReportingPeriod.get(ReportingPeriod.title == "Period 1") url = self.request.route_url('clinics', traverse=(clinic.id, period.id)) headers = self._login_user('john') response = self.testapp.get(url, headers=headers, status=403) self.assertEqual(response.status_code, 403)
def test_national_official_can_view_clinics(self): self._create_dash_user("national", "national", "*****@*****.**", groups.NATIONAL_OFFICIAL) user = User.newest() period = ReportingPeriod.get(ReportingPeriod.title == 'Period 1') clinic = Clinic.get(Clinic.name == "Clinic A") url = self.request.route_path('clinics', traverse=(clinic.id, period.id)) headers = self._login_dashboard_user(user) response = self.testapp.get(url, headers=headers) self.assertEqual(response.status_code, 200)
def test_show(self): period = ReportingPeriod.get(ReportingPeriod.title == 'Period 1') clinic = Clinic.get(Clinic.id == 1) period.__parent__ = clinic self.request.context = period response = self.clinic_views.show() self.assertIsInstance(response['clinic'], Clinic) self.assertEqual(response['clinic'].id, clinic.id) self.assertIn('client_tools', response) self.assertEqual( response['characteristics'], tuple_to_dict_list(("id", "description", "number"), constants.CHARACTERISTICS))
def test_select_characteristics(self): period = ReportingPeriod.get(ReportingPeriod.title == 'Period 1') clinic = Clinic.get(Clinic.id == 1) period.__parent__ = clinic self.request.context = period params = MultiDict([('characteristic_id', 'one'), ('characteristic_id', 'two'), ('characteristic_id', 'three')]) self.request.POST = params response = self.clinic_views.select_characteristics() self.assertIsInstance(response, HTTPFound) self.assertEqual( response.location, self.request.route_url('clinics', traverse=(clinic.id, period.id)))
def test_characteristics_list_with_characteristic_type_filter(self): period = ReportingPeriod.get(ReportingPeriod.title == 'Period 1') clinic = Clinic.get(Clinic.id == 1) period.__parent__ = clinic self.request.context = period params = MultiDict({'char_type': 'equitable'}) self.request.GET = params response = self.clinic_views.characteristics_list() self.assertIsInstance(response['period'], ReportingPeriod) self.assertIsInstance(response['clinic'], Clinic) self.assertEqual(response['clinic'].id, clinic.id) self.assertEqual(len(response['characteristics']), 3), self.assertEqual(response['indicator_labels'], dict(constants.INDICATOR_LABELS)), self.assertEqual(response['characteristic_indicator_mapping'], constants.CHARACTERISTIC_INDICATOR_MAPPING)
def test_characteristics_list(self): period = ReportingPeriod.get(ReportingPeriod.title == 'Period 1') clinic = Clinic.get(Clinic.id == 1) period.__parent__ = clinic self.request.context = period response = self.clinic_views.characteristics_list() self.assertIsInstance(response['period'], ReportingPeriod) self.assertIsInstance(response['clinic'], Clinic) self.assertEqual(response['clinic'].id, clinic.id) self.assertEqual( response['characteristics'], tuple_to_dict_list(("id", "description", "number"), constants.CHARACTERISTICS)), self.assertEqual(response['indicator_labels'], dict(constants.INDICATOR_LABELS)), self.assertEqual(response['characteristic_indicator_mapping'], constants.CHARACTERISTIC_INDICATOR_MAPPING)
def create_clinic_report_v3(self): clinic = Clinic.get(Clinic.id == 4) period = ReportingPeriod.get(ReportingPeriod.title == 'Period 2017') with transaction.manager: ClinicReport.get_or_generate(clinic, period)