예제 #1
0
    def test_unauthorized_return(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, "")

        c = emp_dep.create_new_deposition()
        self.assertEqual(c, 1)
예제 #2
0
    def test_non_int_entry_id_return(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, "")

        c = emp_dep.redeposit()
        self.assertEqual(c, 1)
예제 #3
0
    def test_successful_upload(self, mock_post):
        mock_post = mock_response(
            mock_post,
            headers={'content-type': 'application/json'},
            json={'submission': True, 'empiar_id': 'EMPIAR-10001'}
        )

        emp_dep = EmpiarDepositor("ABC123", self.json_path, "")
  
        c = emp_dep.submit_deposition()
        self.assertEqual(c, 0)
예제 #4
0
    def test_no_permission_return(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, "")

        c = emp_dep.redeposit()
        self.assertEqual(c, 1)
예제 #5
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)
예제 #6
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)
예제 #7
0
    def test_no_rights_granting_input_return(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)

        c = emp_dep.grant_rights()
        self.assertEqual(c, 1)
예제 #8
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)
예제 #9
0
    def test_successful_upload(self, mock_post):
        mock_post = mock_response(mock_post,
                                  status_code=200,
                                  headers={'content-type': 'application/json'},
                                  json={'thumbnail_upload': True})

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

        c = emp_dep.thumbnail_upload()
        self.assertEqual(c, 0)
예제 #10
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)
예제 #11
0
    def test_successful_deposition(self, mock_post):
        mock_post = mock_response(mock_post,
                                  headers={'content-type': 'application/json'},
                                  json={
                                      'deposition': True,
                                      'directory': 'DIR',
                                      'entry_id': 1
                                  })

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

        c = emp_dep.create_new_deposition()
        self.assertEqual(c, 0)
예제 #12
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)
예제 #13
0
    def test_successful_rights_granting(self, mock_post):
        mock_post = mock_response(
            mock_post,
            status_code=200,
            headers={'content-type': 'application/json'},
            json={
                'test1': True,'test2': True,
                '*****@*****.**': True, '*****@*****.**': True,
                '0000-0000-0000-0000': True, '0000-0000-0000-0001': True
            }
        )

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

        c = emp_dep.grant_rights()
        self.assertEqual(c, 0)