2014-11-25 10:51:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-12-02 04:36:27 +00:00
|
|
|
|
2014-12-02 04:49:46 +00:00
|
|
|
# Import pytohn libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2014-12-02 04:36:27 +00:00
|
|
|
# Import Salt testing libs
|
2017-02-20 13:39:35 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
2017-02-20 13:39:35 +00:00
|
|
|
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
2014-12-02 04:36:27 +00:00
|
|
|
|
|
|
|
# Import Salt libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.artifactory as artifactory
|
2014-12-02 04:36:27 +00:00
|
|
|
|
2014-11-25 10:51:43 +00:00
|
|
|
|
2014-12-02 04:49:46 +00:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-02-20 13:39:35 +00:00
|
|
|
class ArtifactoryTestCase(TestCase, LoaderModuleMockMixin):
|
2017-03-22 12:12:36 +00:00
|
|
|
|
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {artifactory: {}}
|
2014-11-04 10:16:30 +00:00
|
|
|
|
|
|
|
def test_artifact_get_metadata(self):
|
2017-02-20 13:39:35 +00:00
|
|
|
with patch('salt.modules.artifactory._get_artifact_metadata_xml', MagicMock(return_value='''<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<metadata>
|
|
|
|
<groupId>com.company.sampleapp.web-module</groupId>
|
|
|
|
<artifactId>web</artifactId>
|
|
|
|
<versioning>
|
|
|
|
<latest>1.1_RC11</latest>
|
|
|
|
<release>1.0.1</release>
|
|
|
|
<versions>
|
|
|
|
<version>1.0_RC20</version>
|
|
|
|
<version>1.0_RC22</version>
|
|
|
|
</versions>
|
|
|
|
<lastUpdated>20140623120632</lastUpdated>
|
|
|
|
</versioning>
|
|
|
|
</metadata>
|
|
|
|
''')):
|
|
|
|
metadata = artifactory._get_artifact_metadata(artifactory_url='http://artifactory.example.com/artifactory',
|
|
|
|
repository='libs-releases',
|
|
|
|
group_id='com.company.sampleapp.web-module',
|
|
|
|
artifact_id='web',
|
|
|
|
headers={})
|
|
|
|
self.assertEqual(metadata['latest_version'], '1.1_RC11')
|
2014-11-04 10:16:30 +00:00
|
|
|
|
|
|
|
def test_snapshot_version_get_metadata(self):
|
2017-02-20 13:39:35 +00:00
|
|
|
with patch('salt.modules.artifactory._get_snapshot_version_metadata_xml', MagicMock(return_value='''<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<metadata>
|
|
|
|
<groupId>com.company.sampleapp.web-module</groupId>
|
|
|
|
<artifactId>web</artifactId>
|
|
|
|
<version>1.1_RC8-SNAPSHOT</version>
|
|
|
|
<versioning>
|
|
|
|
<snapshot>
|
|
|
|
<timestamp>20140418.150212</timestamp>
|
|
|
|
<buildNumber>1</buildNumber>
|
|
|
|
</snapshot>
|
|
|
|
<lastUpdated>20140623104055</lastUpdated>
|
|
|
|
<snapshotVersions>
|
|
|
|
<snapshotVersion>
|
|
|
|
<extension>pom</extension>
|
|
|
|
<value>1.1_RC8-20140418.150212-1</value>
|
|
|
|
<updated>20140418150212</updated>
|
|
|
|
</snapshotVersion>
|
|
|
|
<snapshotVersion>
|
|
|
|
<extension>war</extension>
|
|
|
|
<value>1.1_RC8-20140418.150212-1</value>
|
|
|
|
<updated>20140418150212</updated>
|
|
|
|
</snapshotVersion>
|
|
|
|
</snapshotVersions>
|
|
|
|
</versioning>
|
|
|
|
</metadata>
|
|
|
|
''')):
|
|
|
|
metadata = artifactory._get_snapshot_version_metadata(artifactory_url='http://artifactory.example.com/artifactory',
|
|
|
|
repository='libs-releases',
|
|
|
|
group_id='com.company.sampleapp.web-module',
|
|
|
|
artifact_id='web',
|
|
|
|
version='1.1_RC8-SNAPSHOT',
|
|
|
|
headers={})
|
|
|
|
self.assertEqual(metadata['snapshot_versions']['war'], '1.1_RC8-20140418.150212-1')
|
2014-11-04 10:16:30 +00:00
|
|
|
|
|
|
|
def test_artifact_metadata_url(self):
|
2016-01-12 20:37:09 +00:00
|
|
|
metadata_url = artifactory._get_artifact_metadata_url(artifactory_url='http://artifactory.example.com/artifactory',
|
2014-11-04 10:16:30 +00:00
|
|
|
repository='libs-releases',
|
|
|
|
group_id='com.company.sampleapp.web-module',
|
|
|
|
artifact_id='web')
|
|
|
|
|
2016-01-12 20:37:09 +00:00
|
|
|
self.assertEqual(metadata_url, "http://artifactory.example.com/artifactory/libs-releases/com/company/sampleapp/web-module/web/maven-metadata.xml")
|
2014-11-04 10:16:30 +00:00
|
|
|
|
|
|
|
def test_snapshot_version_metadata_url(self):
|
2016-01-12 20:37:09 +00:00
|
|
|
metadata_url = artifactory._get_snapshot_version_metadata_url(artifactory_url='http://artifactory.example.com/artifactory',
|
2014-11-04 10:16:30 +00:00
|
|
|
repository='libs-snapshots',
|
|
|
|
group_id='com.company.sampleapp.web-module',
|
|
|
|
artifact_id='web',
|
|
|
|
version='1.0_RC10-SNAPSHOT')
|
|
|
|
|
2016-01-12 20:37:09 +00:00
|
|
|
self.assertEqual(metadata_url, "http://artifactory.example.com/artifactory/libs-snapshots/com/company/sampleapp/web-module/web/1.0_RC10-SNAPSHOT/maven-metadata.xml")
|
2014-11-04 10:16:30 +00:00
|
|
|
|
|
|
|
def test_construct_url_for_released_version(self):
|
|
|
|
artifact_url, file_name = artifactory._get_release_url(repository='libs-releases',
|
|
|
|
group_id='com.company.sampleapp.web-module',
|
|
|
|
artifact_id='web',
|
|
|
|
packaging='war',
|
2016-01-12 20:37:09 +00:00
|
|
|
artifactory_url='http://artifactory.example.com/artifactory',
|
2014-11-04 10:16:30 +00:00
|
|
|
version='1.0_RC20')
|
|
|
|
|
2016-01-12 20:37:09 +00:00
|
|
|
self.assertEqual(artifact_url, "http://artifactory.example.com/artifactory/libs-releases/com/company/sampleapp/web-module/web/1.0_RC20/web-1.0_RC20.war")
|
2014-11-04 10:16:30 +00:00
|
|
|
self.assertEqual(file_name, "web-1.0_RC20.war")
|
|
|
|
|
|
|
|
def test_construct_url_for_snapshot_version(self):
|
2017-02-20 13:39:35 +00:00
|
|
|
with patch('salt.modules.artifactory._get_snapshot_version_metadata', MagicMock(return_value={'snapshot_versions': {'war': '1.0_RC10-20131127.105838-2'}})):
|
|
|
|
|
|
|
|
artifact_url, file_name = artifactory._get_snapshot_url(artifactory_url='http://artifactory.example.com/artifactory',
|
|
|
|
repository='libs-snapshots',
|
|
|
|
group_id='com.company.sampleapp.web-module',
|
|
|
|
artifact_id='web',
|
|
|
|
version='1.0_RC10-SNAPSHOT',
|
|
|
|
packaging='war',
|
|
|
|
headers={})
|
|
|
|
|
|
|
|
self.assertEqual(artifact_url, "http://artifactory.example.com/artifactory/libs-snapshots/com/company/sampleapp/web-module/web/1.0_RC10-SNAPSHOT/web-1.0_RC10-20131127.105838-2.war")
|
|
|
|
self.assertEqual(file_name, "web-1.0_RC10-20131127.105838-2.war")
|