Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
class DeleteFilesFailTest(unittest.TestCase):
    def setUp(self):
        good_token = TEST_API_TOKEN
        self.client = Client(True, good_token)

    def test_bad_id(self):
        with self.assertRaises(Exception):
            self.client.delete_deposition_files('1010101', ['1'])
Ejemplo n.º 3
0
class CreateDepositionTest(unittest.TestCase):
    def test_success(self):
        token = TEST_API_TOKEN
        self.client = Client(True, token)
        self.client.create_deposition()

    def test_bad_token(self):
        token = 'notatoken'
        self.client = Client(True, token)
        with self.assertRaises(UserMistake):
            self.client.create_deposition()
Ejemplo n.º 4
0
class GetFilesTest(unittest.TestCase):
    def setUp(self):
        good_token = TEST_API_TOKEN
        self.client = Client(True, good_token)

    # FIXME: don't hardcode record ID
    # def test_success(self):
    #     new_id = self.client.new_deposition_version('355162')
    #     file_ids = self.client.get_deposition_files(new_id)
    #     self.assertNotEqual(len(file_ids), 0)

    def test_bad_id(self):
        with self.assertRaises(Exception):
            self.client.get_deposition_files('1010101')
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
class NewDepositionVersionTest(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_success(self):
        new_record_id = self.client.new_deposition_version(self.deposition_id)
        self.assertIsNotNone(new_record_id)

    def test_bad_id(self):
        with self.assertRaises(Exception):
            self.client.new_deposition_version('1010101')
Ejemplo n.º 7
0
 def test_bad_token(self):
     token = 'notatoken'
     self.client = Client(True, token)
     with self.assertRaises(UserMistake):
         self.client.create_deposition()
Ejemplo n.º 8
0
 def setUp(self):
     good_token = TEST_API_TOKEN
     self.client = Client(True, good_token)
Ejemplo n.º 9
0
 def test_success(self):
     token = TEST_API_TOKEN
     self.client = Client(True, token)
     self.client.create_deposition()