def test_main_success_ss_upload_call(self, mock_create_dip, mock_ss_upload):
     """Test that an upload to AtoM is performed."""
     with TmpDir(TMP_DIR), TmpDir(OUTPUT_DIR):
         self.args.update(
             {
                 "upload_type": "ss-upload",
                 "pipeline_uuid": "",
                 "cp_location_uuid": "",
                 "ds_location_uuid": "",
                 "shared_directory": "",
                 "delete_local_copy": True,
             }
         )
         create_dips_job.main(**self.args)
         assert mock_ss_upload.called
 def test_main_success_atom_upload_call(self, mock_create_dip, mock_atom_upload):
     """Test that an upload to AtoM is performed."""
     with TmpDir(TMP_DIR), TmpDir(OUTPUT_DIR):
         self.args.update(
             {
                 "upload_type": "atom-upload",
                 "atom_url": "",
                 "atom_email": "",
                 "atom_password": "",
                 "atom_slug": "",
                 "rsync_target": "",
                 "delete_local_copy": True,
             }
         )
         create_dips_job.main(**self.args)
         assert mock_atom_upload.called
 def test_main_fail_request(self):
     """Test a fail when an SS connection can't be established."""
     with TmpDir(TMP_DIR):
         ret = create_dips_job.main(SS_URL, SS_USER_NAME, 'bad_api_key',
                                    LOCATION_UUID, TMP_DIR, OUTPUT_DIR,
                                    DATABASE_FILE)
         assert ret == 2
 def test_main_success(self):
     """Test a success where one DIP is created."""
     with TmpDir(TMP_DIR), TmpDir(OUTPUT_DIR):
         ret = create_dips_job.main(**self.args)
         assert ret is None
         dip_path = os.path.join(
             OUTPUT_DIR, "test_B-3ea465ac-ea0a-4a9c-a057-507e794de332"
         )
         assert os.path.isdir(dip_path)
 def test_main_success(self):
     """Test a success where one DIP is created."""
     with TmpDir(TMP_DIR), TmpDir(OUTPUT_DIR):
         ret = create_dips_job.main(SS_URL, SS_USER_NAME, SS_API_KEY,
                                    LOCATION_UUID, TMP_DIR, OUTPUT_DIR,
                                    DATABASE_FILE)
         assert ret is None
         dip_path = os.path.join(
             OUTPUT_DIR, 'test_B_3ea465ac-ea0a-4a9c-a057-507e794de332_DIP')
         assert os.path.isdir(dip_path)
 def test_main_fail_db(self):
     """Test a fail when a database can't be created."""
     ret = create_dips_job.main(
         SS_URL,
         SS_USER_NAME,
         SS_API_KEY,
         LOCATION_UUID,
         TMP_DIR,
         OUTPUT_DIR,
         "/this/should/be/a/wrong/path/to.db",
     )
     assert ret == 1
 def test_main_fail_request(self):
     """Test a fail when an SS connection can't be established."""
     with TmpDir(TMP_DIR):
         ret = create_dips_job.main(
             SS_URL,
             SS_USER_NAME,
             "bad_api_key",
             LOCATION_UUID,
             TMP_DIR,
             OUTPUT_DIR,
             DATABASE_FILE,
         )
         assert ret == 2
 def test_main_success_no_dip_creation(self):
     """Test a success where one AIP was already processed."""
     effect = exc.IntegrityError({}, [], '')
     session_add_patch = mock.patch('sqlalchemy.orm.Session.add',
                                    side_effect=effect)
     with TmpDir(TMP_DIR), TmpDir(OUTPUT_DIR), session_add_patch:
         ret = create_dips_job.main(SS_URL, SS_USER_NAME, SS_API_KEY,
                                    LOCATION_UUID, TMP_DIR, OUTPUT_DIR,
                                    DATABASE_FILE)
         assert ret is None
         dip_path = os.path.join(
             OUTPUT_DIR, 'test_B_3ea465ac-ea0a-4a9c-a057-507e794de332_DIP')
         assert not os.path.isdir(dip_path)
 def test_main_success(self):
     """Test a success where one DIP is created."""
     with TmpDir(TMP_DIR), TmpDir(OUTPUT_DIR):
         ret = create_dips_job.main(
             SS_URL,
             SS_USER_NAME,
             SS_API_KEY,
             LOCATION_UUID,
             TMP_DIR,
             OUTPUT_DIR,
             DATABASE_FILE,
         )
         assert ret is None
         dip_path = os.path.join(
             OUTPUT_DIR, "test_B_3ea465ac-ea0a-4a9c-a057-507e794de332_DIP"
         )
         assert os.path.isdir(dip_path)
 def test_main_success_no_dip_creation(self):
     """Test a success where one AIP was already processed."""
     effect = exc.IntegrityError({}, [], "")
     session_add_patch = mock.patch("sqlalchemy.orm.Session.add", side_effect=effect)
     with TmpDir(TMP_DIR), TmpDir(OUTPUT_DIR), session_add_patch:
         ret = create_dips_job.main(
             SS_URL,
             SS_USER_NAME,
             SS_API_KEY,
             LOCATION_UUID,
             TMP_DIR,
             OUTPUT_DIR,
             DATABASE_FILE,
         )
         assert ret is None
         dip_path = os.path.join(
             OUTPUT_DIR, "test_B_3ea465ac-ea0a-4a9c-a057-507e794de332_DIP"
         )
         assert not os.path.isdir(dip_path)
 def test_main_fail_request(self):
     """Test a fail when an SS connection can't be established."""
     with TmpDir(TMP_DIR):
         self.args["ss_api_key"] = "bad_api_key"
         ret = create_dips_job.main(**self.args)
         assert ret == 2
 def test_main_fail_db(self):
     """Test a fail when a database can't be created."""
     self.args["database_file"] = "/this/should/be/a/wrong/path/to.db"
     ret = create_dips_job.main(**self.args)
     assert ret == 1
 def test_main_dip_creation_failed(self, mock_create_dip, mock_atom_upload):
     """Test that a fail on DIP creation doesn't trigger an upload."""
     with TmpDir(TMP_DIR), TmpDir(OUTPUT_DIR):
         self.args["upload_type"] = "atom-upload"
         create_dips_job.main(**self.args)
         assert not mock_atom_upload.called
 def test_main_fail_db(self):
     """Test a fail when a database can't be created."""
     ret = create_dips_job.main(SS_URL, SS_USER_NAME, SS_API_KEY,
                                LOCATION_UUID, TMP_DIR, OUTPUT_DIR,
                                '/this/should/be/a/wrong/path/to.db')
     assert ret == 1