コード例 #1
0
    def setUpClass(cls):
        """Set up class-wide resources like submissions and jobs."""
        super(UserTests, cls).setUpClass()

        with create_app().app_context():
            sess = GlobalDB.db().session

            # Add submissions for agency user
            sess.query(Submission).filter(Submission.user_id == cls.agency_user_id).delete()
            sess.commit()
            for i in range(0, 6):
                sub = Submission(user_id=cls.agency_user_id)
                sub.reporting_start_date = datetime(2015, 10, 1)
                sub.reporting_end_date = datetime(2015, 12, 31)
                sub.cgac_code = cls.admin_cgac_code
                sess.add(sub)
                sess.commit()
                if i == 0:
                    cls.submission_id = sub.submission_id

            # Add job to first submission
            job = Job(
                submission_id=cls.submission_id,
                job_status_id=JOB_STATUS_DICT['running'],
                job_type_id=JOB_TYPE_DICT['file_upload'],
                file_type_id=FILE_TYPE_DICT['appropriations']
            )
            sess.add(job)
            sess.commit()
            cls.uploadId = job.job_id
コード例 #2
0
    def setUpClass(cls):
        """Set up class-wide resources like submissions and jobs."""
        super(UserTests, cls).setUpClass()

        with create_app().app_context():
            sess = GlobalDB.db().session

            # Add submissions for agency user
            sess.query(Submission).filter(Submission.user_id == cls.agency_user_id).delete()
            sess.commit()
            for i in range(0, 6):
                sub = Submission(user_id=cls.agency_user_id)
                sub.reporting_start_date = datetime(2015, 10, 1)
                sub.reporting_end_date = datetime(2015, 12, 31)
                sub.cgac_code = cls.admin_cgac_code
                sess.add(sub)
                sess.commit()
                if i == 0:
                    cls.submission_id = sub.submission_id

            # Add job to first submission
            job = Job(
                submission_id=cls.submission_id,
                job_status_id=JOB_STATUS_DICT['running'],
                job_type_id=JOB_TYPE_DICT['file_upload'],
                file_type_id=FILE_TYPE_DICT['appropriations']
            )
            sess.add(job)
            sess.commit()
            cls.uploadId = job.job_id
コード例 #3
0
 def test_skip_guide(self):
     """ Set skip guide to True and check value in DB """
     self.login_user()
     params = {"skip_guide": True}
     response = self.app.post_json("/v1/set_skip_guide/", params, headers={"x-session-id": self.session_id})
     self.check_response(response, StatusCode.OK, "skip_guide set successfully")
     self.assertTrue(response.json["skip_guide"])
     with create_app().app_context():
         sess = GlobalDB.db().session
         user = sess.query(User).filter(User.email == self.test_users['agency_user']).one()
     self.assertTrue(user.skip_guide)
コード例 #4
0
 def test_skip_guide(self):
     """ Set skip guide to True and check value in DB """
     self.login_user()
     params = {"skip_guide": True}
     response = self.app.post_json("/v1/set_skip_guide/", params, headers={"x-session-id": self.session_id})
     self.check_response(response, StatusCode.OK, "skip_guide set successfully")
     self.assertTrue(response.json["skip_guide"])
     with create_app().app_context():
         sess = GlobalDB.db().session
         user = sess.query(User).filter(User.email == self.test_users['agency_user']).one()
     self.assertTrue(user.skip_guide)
コード例 #5
0
    def setUpClass(cls):
        """ Set up class-wide resources (test data) """
        super(DetachedUploadTests, cls).setUpClass()
        # TODO: refactor into a pytest fixture

        with create_app().app_context():
            # get the submission test users
            sess = GlobalDB.db().session
            cls.session = sess
            admin_user = sess.query(User).filter(
                User.email == cls.test_users['admin_user']).one()
            agency_user = sess.query(User).filter(
                User.email == cls.test_users['agency_user']).one()
            cls.admin_user_id = admin_user.user_id
            cls.agency_user_id = agency_user.user_id

            # setup submission/jobs data for test_check_status
            cls.d2_submission = cls.insert_submission(sess,
                                                      cls.admin_user_id,
                                                      cgac_code="SYS",
                                                      start_date="10/2015",
                                                      end_date="12/2015",
                                                      is_quarter=True)

            cls.d2_submission_2 = cls.insert_submission(sess,
                                                        cls.agency_user_id,
                                                        cgac_code="SYS",
                                                        start_date="10/2015",
                                                        end_date="12/2015",
                                                        is_quarter=True)

            cls.published_submission = cls.insert_submission(
                sess,
                cls.admin_user_id,
                cgac_code="SYS",
                start_date="10/2015",
                end_date="12/2015",
                is_quarter=True,
                publish_status_id=PUBLISH_STATUS_DICT["published"])

            cls.other_submission = cls.insert_submission(sess,
                                                         cls.admin_user_id,
                                                         cgac_code="SYS",
                                                         start_date="07/2015",
                                                         end_date="09/2015",
                                                         is_quarter=True,
                                                         d2_submission=False)
コード例 #6
0
 def test_finalize_wrong_user(self):
     """Test finalizing a job as the wrong user."""
     # Jobs were submitted with the id for "approved user," so lookup
     # as "admin user" should fail.
     self.logout()
     self.login_user(self.test_users['agency_user_2'])
     post_json = {"upload_id": self.uploadId}
     response = self.app.post_json("/v1/finalize_job/",
                                   post_json, expect_errors=True, headers={"x-session-id": self.session_id})
     self.check_response(response, StatusCode.CLIENT_ERROR, "Cannot finalize a job for a different agency")
     # Give submission this user's cgac code
     with create_app().app_context():
         sess = GlobalDB.db().session
         submission = sess.query(Submission).filter(Submission.submission_id == self.submission_id).one()
         user = sess.query(User).filter_by(email=self.test_users['agency_user_2']).one()
         submission.cgac_code = user.affiliations[0].cgac.cgac_code
         sess.commit()
     response = self.app.post_json("/v1/finalize_job/",
                                   post_json, expect_errors=True, headers={"x-session-id": self.session_id})
     self.check_response(response, StatusCode.OK)
     self.logout()
コード例 #7
0
    def setUpClass(cls):
        """Set up class-wide resources (test data)"""
        super(DetachedUploadTests, cls).setUpClass()
        # TODO: refactor into a pytest fixture

        with create_app().app_context():
            # get the submission test user
            sess = GlobalDB.db().session
            cls.session = sess
            submission_user = sess.query(User).filter(User.email == cls.test_users['admin_user']).one()
            cls.submission_user_id = submission_user.user_id

            # setup submission/jobs data for test_check_status
            cls.d2_submission = cls.insert_submission(sess, cls.submission_user_id, cgac_code="SYS",
                                                      start_date="10/2015", end_date="12/2015", is_quarter=True)

            cls.published_submission = cls.insert_submission(sess, cls.submission_user_id, cgac_code="SYS",
                                                             start_date="10/2015", end_date="12/2015", is_quarter=True,
                                                             publish_status_id=PUBLISH_STATUS_DICT["published"])

            cls.other_submission = cls.insert_submission(sess, cls.submission_user_id, cgac_code="SYS",
                                                         start_date="07/2015", end_date="09/2015",
                                                         is_quarter=True, d2_submission=False)
コード例 #8
0
    def setUpClass(cls):
        """Set up class-wide resources like users."""
        super(DomainTests, cls).setUpClass()

        with create_app().app_context():
            sess = GlobalDB.db().session

            user = User()
            r_cgac = CGACFactory()
            w_cgac = CGACFactory()
            s_frec_cgac = CGACFactory()
            s_frec = FRECFactory(cgac=s_frec_cgac)
            e_frec_cgac = CGACFactory()
            e_frec = FRECFactory(cgac=e_frec_cgac)
            f_cgac = CGACFactory()
            user.affiliations = [
                UserAffiliation(cgac=r_cgac,
                                frec=None,
                                permission_type_id=PERMISSION_SHORT_DICT['r']),
                UserAffiliation(cgac=w_cgac,
                                frec=None,
                                permission_type_id=PERMISSION_SHORT_DICT['w']),
                UserAffiliation(cgac=None,
                                frec=s_frec,
                                permission_type_id=PERMISSION_SHORT_DICT['s']),
                UserAffiliation(cgac=None,
                                frec=e_frec,
                                permission_type_id=PERMISSION_SHORT_DICT['e']),
                UserAffiliation(cgac=f_cgac,
                                frec=None,
                                permission_type_id=PERMISSION_SHORT_DICT['f'])
            ]
            sess.add_all([
                r_cgac, w_cgac, s_frec_cgac, s_frec, e_frec_cgac, e_frec,
                f_cgac
            ])
            sess.commit()
コード例 #9
0
    def setUpClass(cls):
        """ Set up class-wide resources (test data) """
        super(FABSUploadTests, cls).setUpClass()
        # TODO: refactor into a pytest fixture

        with create_app().app_context():
            # get the submission test users
            sess = GlobalDB.db().session
            cls.session = sess
            admin_user = sess.query(User).filter(
                User.email == cls.test_users['admin_user']).one()
            agency_user = sess.query(User).filter(
                User.email == cls.test_users['agency_user']).one()
            editfabs_user = sess.query(User).filter(
                User.email == cls.test_users['editfabs_user']).one()
            cls.admin_user_id = admin_user.user_id
            cls.agency_user_id = agency_user.user_id
            cls.agency_user_email = agency_user.email
            cls.editfabs_email = editfabs_user.email

            # setup submission/jobs data for test_check_status
            cls.fabs_submission = cls.insert_submission(sess,
                                                        cls.admin_user_id,
                                                        cgac_code="SYS",
                                                        start_date="10/2015",
                                                        end_date="12/2015",
                                                        is_quarter=True)

            cls.fabs_submission_2 = cls.insert_submission(sess,
                                                          cls.agency_user_id,
                                                          cgac_code="SYS",
                                                          start_date="10/2015",
                                                          end_date="12/2015",
                                                          is_quarter=True)

            cls.published_submission = cls.insert_submission(
                sess,
                cls.admin_user_id,
                cgac_code="SYS",
                start_date="10/2015",
                end_date="12/2015",
                is_quarter=True,
                publish_status_id=PUBLISH_STATUS_DICT["published"])

            cls.other_submission = cls.insert_submission(sess,
                                                         cls.admin_user_id,
                                                         cgac_code="SYS",
                                                         start_date="07/2015",
                                                         end_date="09/2015",
                                                         is_quarter=True,
                                                         is_fabs=False)

            cls.running_submission = cls.insert_submission(
                sess,
                cls.admin_user_id,
                cgac_code="SYS",
                start_date="10/2015",
                end_date="12/2015",
                is_quarter=True)
            cls.insert_job(sess, cls.running_submission,
                           JOB_STATUS_DICT['running'],
                           JOB_TYPE_DICT['csv_record_validation'])

            cls.test_agency_user_submission_id = cls.insert_submission(
                sess,
                cls.agency_user_id,
                cgac_code="NOT",
                start_date="10/2015",
                end_date="12/2015",
                is_quarter=True,
                is_fabs=True)
            cls.insert_agency_user_submission_data(
                sess, cls.test_agency_user_submission_id)