Exemplo n.º 1
0
    def test_get_item_returns_user_if_id_exists(self):
        self.setup_test_data()
        user = User.newest()

        request = testing.DummyRequest()
        user = UserFactory(request).__getitem__(user.id)
        self.assertIsInstance(user, User)
Exemplo n.º 2
0
 def test_newest_returns_newest_record_by_id_desc(self):
     user1 = User(id=1)
     user2 = User(id=2)
     with transaction.manager:
         DBSession.add_all([user1, user2])
     user = User.newest()
     self.assertEqual(user.id, 2)
Exemplo n.º 3
0
    def test_national_official_can_list_states(self):
        self._create_dash_user("national", "national", "*****@*****.**",
                               groups.NATIONAL_OFFICIAL)
        user = User.newest()

        url = self.request.route_path('states', traverse=())
        headers = self._login_dashboard_user(user)

        with patch('whoahqa.models.reporting_period.get_current_date') as mock:
            mock.return_value = datetime.date(2015, 6, 1)
            response = self.testapp.get(url, headers=headers)
            self.assertEqual(response.status_code, 200)
Exemplo n.º 4
0
 def test_get_item_returns_reporting_period(self):
     self.setup_test_data()
     period = ReportingPeriod(title="2013/2014",
                              start_date=datetime.datetime(2013, 3, 13),
                              end_date=datetime.datetime(2014, 3, 13))
     DBSession.add(period)
     DBSession.flush()
     period = ReportingPeriod.newest()
     user = User.newest()
     selected_period = user.__getitem__(period.id)
     self.assertIsInstance(selected_period, ReportingPeriod)
     self.assertEqual(selected_period, period)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    def test_create_clinic_from_submission(self):
        # create user with matching id
        DBSession.add(User())
        user = User.newest()

        payload = self.clinic_registrations[0]
        raw_data = json.loads(payload)
        raw_data[constants.USER_ID] = user.id
        submission = Submission(raw_data=raw_data)
        count = Clinic.count()
        ClinicRegistrationHandler(submission).handle_submission()

        # check that a clinic_submission record was created
        self.assertEqual(Clinic.count(), count + 1)

        clinic = Clinic.newest()
        self.assertEqual(clinic.code, '1A2B')
Exemplo n.º 7
0
    def test_redirects_to_states_for_national_official(self):
        self.setup_test_data()
        self._create_dash_user("national", "national", "*****@*****.**",
                               groups.NATIONAL_OFFICIAL)
        user = User.newest()

        url = self.request.route_url('default')
        headers = self._login_dashboard_user(user)
        response = self.testapp.get(url, headers=headers)

        period = get_period_from_request(self.request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            self.request.route_url('states',
                                   traverse=(),
                                   _query={'period': period.id}),
            response.location)
Exemplo n.º 8
0
 def test_raise_key_error_when_invalid_period_id(self):
     self.setup_test_data()
     user = User.newest()
     self.assertRaises(KeyError, user.__getitem__, "abc")