Example #1
0
    def test_no_response(self, mock_post):
        mock_post.return_value = None

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

        c = emp_dep.submit_deposition()
        self.assertEqual(c, 1)
Example #2
0
    def test_no_response(self, mock_post):
        mock_post.return_value = None

        empDep = EmpiarDepositor("ABC123",
                                 "tests/deposition_json/working_example.json",
                                 "", "")

        with self.assertRaises(SystemExit) as cm:
            c = empDep.submit_deposition()
        self.assertEqual(cm.exception.args[0], 1)
Example #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)
Example #4
0
    def test_no_permission_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, "")

        c = emp_dep.submit_deposition()
        self.assertEqual(c, 1)
Example #5
0
    def test_successful_upload(self, mock_post):
        mock_post.return_value = Mock(ok=True, spec=Response)
        mock_post.return_value.json.return_value = {
            'submission': True,
            'empiar_id': 'EMPIAR-10001'
        }

        empDep = EmpiarDepositor("ABC123",
                                 "tests/deposition_json/working_example.json",
                                 "", "")

        c = empDep.submit_deposition()
        self.assertEqual(c, 0)
Example #6
0
    def test_no_permission(self, mock_post):
        mock_post.return_value = Mock(ok=True, spec=Response)
        mock_post.return_value.status_code = 403
        mock_post.return_value.json.return_value = {
            'detail': 'You do not have permission to perform this action.'
        }

        empDep = EmpiarDepositor("ABC123",
                                 "tests/deposition_json/working_example.json",
                                 "", "")

        with self.assertRaises(SystemExit) as cm:
            c = empDep.submit_deposition()
        self.assertTrue(
            'The submission of an EMPIAR deposition was not successful. Returned response:'
            in cm.exception.args[0]
            and 'Status code: 403' in cm.exception.args[0])