def setUp(self): super(TestStateViewsFunctional, self).setUp() with transaction.manager: state = State(name="Sao Paolo") municipality1 = Municipality(name="Brasillia", parent=state) municipality2 = Municipality(name="Brasil", parent=state) user_group = Group(name="state_official") user = User() user.group = user_group user.location = state ona_user = OnaUser(username="******", user=user, refresh_token="1239khyackas") ona_user.save() reporting_period = ReportingPeriod( title='Period 1', start_date=datetime.datetime(2015, 5, 1), end_date=datetime.datetime(2015, 7, 31)) reporting_period.save() DBSession.add_all([state, municipality1, municipality2])
def setUp(self): super(TestStateViews, self).setUp() self.request = testing.DummyRequest() self._create_user('state-official') with transaction.manager: reporting_period = ReportingPeriod( title='Period 1', start_date=datetime.datetime(2015, 5, 1), end_date=datetime.datetime(2015, 7, 31)) reporting_period.save() state = State(name="Sao Paolo") municipality1 = Municipality(name="Brasillia", parent=state) municipality2 = Municipality(name="Brasil", parent=state) DBSession.add_all([state, municipality1, municipality2]) for i in range(5): clinic = Clinic(name="Clinic {}".format(i), code="{}BCDE".format(i), municipality=municipality1) DBSession.add(clinic) self.request.user = OnaUser.get( OnaUser.username == 'state-official').user self.view = StateViews(self.request)
def setUp(self): super(TestMunicipalityViews, self).setUp() self.request = testing.DummyRequest() self._create_user('municipality-manager') with transaction.manager: reporting_period = ReportingPeriod( title='Period 1', start_date=datetime.datetime(2015, 5, 1), end_date=datetime.datetime(2015, 7, 31)) reporting_period.save() municipality = Municipality(name="Brasillia") DBSession.add(municipality) for i in range(5): clinic = Clinic(name="Clinic {}".format(i), code="{}BCDE".format(i), municipality=municipality) DBSession.add(clinic) self.request.user = OnaUser.get( OnaUser.username == 'municipality-manager').user self.view = MunicipalityViews(self.request)
def test_push_report_periods_with_data(self): reporting_period1 = ReportingPeriod( title='Period 1', form_xpath='2017', start_date=datetime.datetime(2017, 1, 1), end_date=datetime.datetime(2017, 12, 31)) reporting_period2 = ReportingPeriod( title='Period 2', form_xpath='2018', start_date=datetime.datetime(2018, 1, 1), end_date=datetime.datetime(2018, 12, 31)) reporting_period3 = ReportingPeriod( title='Period 3', form_xpath='2019', start_date=datetime.datetime(2019, 1, 1), end_date=datetime.datetime(2019, 12, 31)) reporting_period1.save() reporting_period2.save() reporting_period3.save() response = push_report_periods(self.request) self.assertEqual(3, len(response['rows'])) self.assertEqual(['2017'], response['rows'][0]) self.assertEqual(['2018'], response['rows'][1]) self.assertEqual(['2019'], response['rows'][2])