Exemplo n.º 1
0
class PublishNewVersionTest(unittest.TestCase):
    def setUp(self):
        url_base = API_BASE_URL_DEV
        good_token = TEST_API_TOKEN

        r = requests.post(url_base + '/deposit/depositions',
                          params={'access_token': good_token},
                          json={},
                          headers={"Content-Type": "application/json"})
        # retrieve deposition id
        r_dict = r.json()
        self.deposition_id = r_dict['id']

        metadata = {
            'title': 'Sample Title',
            'upload_type': 'publication',
            'publication_type': 'workingpaper',
            'description': 'This is a description',
            'creators': [{
                'name': 'Some Name',
                'affiliation': 'Some Place'
            }],
        }
        filepath = test_filename

        self.client = Client(True, good_token)
        self.client.add_metadata(self.deposition_id, metadata)
        self.client.add_file(self.deposition_id, filepath)
        self.client.publish_deposition(self.deposition_id)

    def test_user_error(self):
        new_id = self.client.new_deposition_version(self.deposition_id)
        with self.assertRaises(UserMistake):
            self.client.publish_deposition(new_id)
Exemplo n.º 2
0
class AddFileTest(unittest.TestCase):
    def setUp(self):
        url_base = API_BASE_URL_DEV
        good_token = TEST_API_TOKEN

        r = requests.post(url_base + '/deposit/depositions',
                          params={'access_token': good_token},
                          json={},
                          headers={"Content-Type": "application/json"})
        # retrieve deposition id
        r_dict = r.json()
        self.deposition_id = r_dict['id']
        self.good_metadata = {
            'title': 'Sample Title',
            'upload_type': 'publication',
            'publication_type': 'workingpaper',
            'description': 'This is a description',
            'creators': [{
                'name': 'Some Name',
                'affiliation': 'Some Place'
            }],
        }

        self.good_filepath = test_filename
        self.client = Client(True, good_token)

    def test_success(self):
        file_id = self.client.add_file(self.deposition_id, self.good_filepath)
        self.assertIsNotNone(file_id)

    def test_bad_id(self):
        with self.assertRaises(Exception):
            self.client.add_file('1010101', self.good_filepath)

    def test_bad_file(self):
        with self.assertRaises(Exception):
            self.client.add_file(self.deposition_id, 'notafile')