def test_path_doesnt_crash_without_addon(self): guid = model.FigShareGuidFile(node=self.project, path='/baz/foo/bar') self.project.delete_addon('figshare', Auth(self.user)) assert_is(self.project.get_addon('figshare'), None) assert_true(guid.path) assert_true(guid.waterbutler_path)
def test_mfr_test_path(self): self.node_addon.figshare_type = 'fileset' self.node_addon.save() self.node_addon.reload() guid = model.FigShareGuidFile(file_id=2, article_id=4, node=self.project) assert_equal(guid.waterbutler_path, '/2')
def test_correct_path_article(self): guid = model.FigShareGuidFile(file_id=2, article_id=4, node=self.project) guid._metadata_cache = {'name': 'shigfare.io'} tpath = guid.mfr_temp_path cpath = guid.mfr_cache_path assert_not_equal(tpath, cpath)
def test_path_doesnt_crash_nonconfig_addon(self): guid = model.FigShareGuidFile(node=self.project, path='/baz/foo/bar') self.node_addon.figshare_type = None self.node_addon.figshare_id = None self.node_addon.save() self.node_addon.reload() assert_true(guid.path) assert_true(guid.waterbutler_path)
def test_exception_from_response(self): mock_response = mock.Mock() mock_response.json.return_value = { 'data': { 'name': 'Morty', 'extra': { 'status': 'drafts' } } } guid = model.FigShareGuidFile(file_id=2, article_id=4) with assert_raises(exceptions.FigshareIsDraftError): guid._exception_from_response(mock_response) assert_equal(guid.name, 'Morty')
def test_enrich_works(self, mock_get): mock_response = mock.Mock(ok=True, status_code=200) mock_get.return_value = mock_response mock_response.json.return_value = { 'data': { 'name': 'Morty', 'extra': { 'status': 'Rick' } } } guid = model.FigShareGuidFile(file_id=2, article_id=4, node=self.project) guid.enrich() assert_equal(guid.name, 'Morty')
def test_enrich_raises(self, mock_get): mock_response = mock.Mock(ok=True, status_code=200) mock_get.return_value = mock_response mock_response.json.return_value = { 'data': { 'name': 'Morty', 'extra': { 'status': 'drafts' } } } guid = model.FigShareGuidFile(file_id=2, article_id=4, node=self.project) with assert_raises(exceptions.FigshareIsDraftError): guid.enrich() assert_equal(guid.name, 'Morty')
def test_unique_identifier(self): guid = model.FigShareGuidFile(file_id=2, article_id=4) assert_equal(guid.unique_identifier, '42')
def test_correct_path_project(self): guid = model.FigShareGuidFile(file_id=2, article_id=4, node=self.project) assert_equal(guid.waterbutler_path, '/4/2')
def test_provider(self): assert_equal('figshare', model.FigShareGuidFile().provider)