Skip to content

Commit

Permalink
#21 upload: failing when using REST and specifying version explicitly [
Browse files Browse the repository at this point in the history
…closes #21]
  • Loading branch information
stardust85 committed May 11, 2016
1 parent 1c63e5a commit 3a8ba70
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
28 changes: 0 additions & 28 deletions repository-tools.spec

This file was deleted.

11 changes: 9 additions & 2 deletions repositorytools/lib/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ class LocalArtifact(Artifact):
def __init__(self, group, local_path, artifact='', version='', classifier='', extension=''):
self.local_path = local_path

if not artifact and not version and not extension:
artifact, version, extension = self.detect_name_ver_ext()
artifact_detected, version_detected, extension_detected = self.detect_name_ver_ext()

if not artifact:
artifact = artifact_detected

if not version:
version = version_detected

if not extension:
extension = extension_detected

super(LocalArtifact, self).__init__(group=group, artifact=artifact, version=version, classifier=classifier,
extension=extension)
Expand Down
24 changes: 15 additions & 9 deletions repositorytools/lib/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,28 @@ def _upload_artifact(self, local_artifact, path_prefix, repo_id, hostname_for_do

self._send('service/local/artifact/maven/content', method='POST', data=m, headers=headers)

result = RemoteArtifact(group=local_artifact.group, artifact=local_artifact.artifact,
version=local_artifact.version, classifier=local_artifact.classifier,
extension=local_artifact.extension, repo_id=repo_id)
self.resolve_artifact(result)
return result

else:
headers = {'Content-Type': 'application/x-rpm'}
remote_path = '{path_prefix}/{rgavf}'.format(path_prefix=path_prefix, rgavf=rgavf)
self._send(remote_path, method='POST', headers=headers, data=f)

# if not specified, use repository url
hostname_for_download = hostname_for_download or self._repository_url
url = '{hostname}/content/repositories/{rgavf}'.format(hostname=hostname_for_download, rgavf=rgavf)
# if not specified, use repository url
hostname_for_download = hostname_for_download or self._repository_url
url = '{hostname}/content/repositories/{rgavf}'.format(hostname=hostname_for_download, rgavf=rgavf)

# get classifier and extension from nexus
path = 'service/local/repositories/{repo_id}/content/{gavf}?describe=maven2'.format(repo_id=repo_id, gavf=gavf)
maven_metadata = self._send_json(path)['data']
# get classifier and extension from nexus
path = 'service/local/repositories/{repo_id}/content/{gavf}?describe=maven2'.format(repo_id=repo_id, gavf=gavf)
maven_metadata = self._send_json(path)['data']

return RemoteArtifact(group=maven_metadata['groupId'], artifact=maven_metadata['artifactId'],
version=maven_metadata['version'], classifier=maven_metadata.get('classifier', ''),
extension=maven_metadata.get('extension', ''), url=url, repo_id=repo_id)
return RemoteArtifact(group=maven_metadata['groupId'], artifact=maven_metadata['artifactId'],
version=maven_metadata['version'], classifier=maven_metadata.get('classifier', ''),
extension=maven_metadata.get('extension', ''), url=url, repo_id=repo_id)

def delete_artifact(self, url):
"""
Expand Down
11 changes: 10 additions & 1 deletion tests/system/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,21 @@ def test_upload_resolve_and_delete(self):
os.environ['REPOSITORY_USER'] = config.USER
self.artifact_cli.run(['delete', remote_artifact.url])

def test_upload_explicit_version(self):
# upload
remote_artifacts = self.artifact_cli.run(['upload', '--version', '2.0.0', ARTIFACT_LOCAL_PATH, config.REPO, GROUP])
self.assertEquals(len(remote_artifacts), 1)
remote_artifact = remote_artifacts[0]

# delete
self.artifact_cli.run(['delete', remote_artifact.url])

def test_metadata(self):
remote_artifacts = cli.ArtifactCLI().run(['upload', ARTIFACT_LOCAL_PATH, config.REPO, GROUP])
self.assertEquals(len(remote_artifacts), 1)
remote_artifact = remote_artifacts[0]

self.artifact_cli.run(['set-metadata', '{s}'.format(s=json.dumps(METADATA)), remote_artifact.repo_id,
self.artifact_cli.run(['-D', 'set-metadata', '{s}'.format(s=json.dumps(METADATA)), remote_artifact.repo_id,
remote_artifact.get_coordinates_string()])
metadata_received_serialized = self.artifact_cli.run(['get-metadata', remote_artifact.repo_id,
remote_artifact.get_coordinates_string()])
Expand Down

0 comments on commit 3a8ba70

Please sign in to comment.