Exemple #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)
Exemple #2
0
class AddMetadataTest(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.client = Client(True, good_token)

    def test_success(self):
        self.client.add_metadata(self.deposition_id, self.good_metadata)

    def test_bad_data(self):
        with self.assertRaises(Exception):
            self.client.add_metadata(self.deposition_id, {})

    def test_bad_id(self):
        with self.assertRaises(Exception):
            self.client.add_metadata('1010101', self.good_metadata)