コード例 #1
0
 def test_aspera_does_not_work(self, mock_isfile):
     mock_isfile.return_value = True
     with capture(empiar_depositor_main, [
             "ABC123", self.json_path, "-aascp.exe",
             "img/entry_thumbnail.gif", "-ppassword"
     ]) as output:
         self.assertTrue("The specified ascp does not work." in output)
コード例 #2
0
 def test_wrong_aspera_executable(self):
     with capture(empiar_depositor_main, [
             "ABC123", self.json_path, "-a" + self.thumbnail_path,
             "img/entry_thumbnail.gif", "-ppassword"
     ]) as output:
         self.assertTrue(
             "Please specify the correct path to ascp executable" in output)
コード例 #3
0
    def test_non_int_entry_id_stdout(self, mock_put):
        mock_put = mock_response(
            mock_put,
            headers={'content-type': 'application/json'},
            json={'deposition': True, 'directory': 'DIR', 'entry_id': 'ID'}
        )

        emp_dep = EmpiarDepositor("ABC123", self.json_path, "")

        with capture(emp_dep.redeposit) as output:
            self.assertTrue('Error occurred while trying to update an EMPIAR deposition. Returned entry id is not an '
                            'integer number' in output)
コード例 #4
0
    def test_unauthorized_stdout(self, mock_post):
        mock_post = mock_response(mock_post,
                                  status_code=401,
                                  headers={'content-type': 'application/json'},
                                  json={'detail': 'Invalid token.'})

        emp_dep = EmpiarDepositor("ABC123", self.json_path, "")

        with capture(emp_dep.create_new_deposition) as output:
            self.assertTrue(
                'The creation of an EMPIAR deposition was not successful. Returned response:'
                in output and 'Status code: 401' in output)
コード例 #5
0
    def test_no_rights_granting_input_stdout(self, mock_post):
        mock_post = mock_response(
            mock_post,
            status_code=403,
            headers={'content-type': 'application/json'},
            json={'detail': 'You do not have permission to perform this action.'}
        )

        emp_dep = EmpiarDepositor("ABC123", self.json_path, "", entry_id=1)

        with capture(emp_dep.grant_rights) as output:
            self.assertTrue('The granting rights for EMPIAR deposition was not successful.' in output)
コード例 #6
0
    def test_no_permission_stdout(self, mock_put):
        mock_put = mock_response(
            mock_put,
            status_code=403,
            headers={'content-type': 'application/json'},
            json={'detail': 'You do not have permission to perform this action.'}
        )

        emp_dep = EmpiarDepositor("ABC123", self.json_path, "")

        with capture(emp_dep.redeposit) as output:
            self.assertTrue('The update of an EMPIAR deposition was not successful. Returned response:' in output and
                            'Status code: 403' in output)
コード例 #7
0
    def test_no_permission_stdout(self, mock_post):
        mock_post = mock_response(
            mock_post,
            status_code=403,
            headers={'content-type': 'application/json'},
            json={'detail': 'You do not have permission to perform this action.'}
        )

        emp_dep = EmpiarDepositor("ABC123", self.json_path, "", entry_id=1,
                                  grant_rights_usernames=self.grant_rights_usernames)

        with capture(emp_dep.grant_rights) as output:
            self.assertTrue('You do not have permission to perform this action.' in output and
                            'Status code: 403' in output)
コード例 #8
0
    def test_aspera_does_work_globus_login_does_not(self, mock_popen,
                                                    mock_isfile):
        mock_isfile.return_value = True

        mock_popen.return_value.communicate.return_value = (b'Usage: ascp',
                                                            b'')
        mock_popen.return_value.returncode = 112

        with capture(empiar_depositor_main, [
                "ABC123", self.json_path, "-aascp.exe",
                "img/entry_thumbnail.gif", "-ppassword", "-gtest"
        ]) as output:
            self.assertTrue(
                "Logging in to Globus...\nError while logging in into Globus"
                in output)
コード例 #9
0
    def test_failed_init_stdout(self, mock_popen):
        mock_popen.return_value.communicate.return_value = ("Task ID: 123", "")
        mock_popen.return_value.returncode = 1

        emp_dep = EmpiarDepositor("ABC123",
                                  self.json_path,
                                  "globus_obj",
                                  "",
                                  "globusid", {
                                      "is_dir": False,
                                      "obj_name": "globus_obj"
                                  },
                                  entry_id=1,
                                  entry_directory="entry_dir")

        with capture(emp_dep.globus_upload) as output:
            self.assertTrue(
                'Globus transfer initiation was not successful. Return code:'
                in output)
コード例 #10
0
    def test_missing_id_json_return(self, mock_popen):
        mock_popen.return_value.communicate.return_value = (
            missing_id_json_str, None)
        mock_popen.return_value.returncode = 0

        emp_dep = EmpiarDepositor("ABC123",
                                  self.json_path,
                                  "globus_obj",
                                  "",
                                  "globusid", {
                                      "is_dir": False,
                                      "obj_name": "globus_obj"
                                  },
                                  entry_id=1,
                                  entry_directory="entry_dir")

        with capture(emp_dep.globus_upload) as output:
            self.assertTrue(
                'Globus JSON transfer initiation result does not have a valid structure of '
                'JSON[\'task_id\']. Return code:' in output)
コード例 #11
0
    def test_invalid_json_return(self, mock_popen):
        mock_popen.return_value.communicate.return_value = (
            b'The transfer has been accepted and a task has been '
            b'created and queued for execution. Task ID: 123', None)
        mock_popen.return_value.returncode = 0

        emp_dep = EmpiarDepositor("ABC123",
                                  self.json_path,
                                  "globus_obj",
                                  "",
                                  "globusid", {
                                      "is_dir": False,
                                      "obj_name": "globus_obj"
                                  },
                                  entry_id=1,
                                  entry_directory="entry_dir")

        with capture(emp_dep.globus_upload) as output:
            self.assertTrue(
                'Error while processing transfer initiation result - the string does not contain a valid '
                'JSON. Return code' in output)
コード例 #12
0
 def test_json_input_does_not_exist(self, ):
     with capture(empiar_depositor_main,
                  ["ABC123", "THIS DOES NOT EXIST", ""]) as output:
         self.assertEqual(output,
                          'The specified JSON file does not exist\n')
コード例 #13
0
 def test_ascp_does_not_exist(self):
     with capture(
             empiar_depositor_main,
         ["ABC123", self.json_path, "", "-aascp", "-ppassword"]) as output:
         self.assertEqual(
             output, "The specified Aspera executable does not exist\n")
コード例 #14
0
 def test_json_input_does_exists(self):
     with capture(empiar_depositor_main,
                  ["ABC123", self.json_path, ""]) as output:
         self.assertNotEqual(output,
                             'The specified JSON file does not exist\n')
コード例 #15
0
    def test_no_entry_id_stdout(self, mock_post):
        emp_dep = EmpiarDepositor("ABC123", self.json_path, "")

        with capture(emp_dep.grant_rights) as output:
            self.assertTrue('Please provide an entry ID.' in output)