123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- # -*- coding: utf-8 -*-
- # Import Python libs
- from __future__ import absolute_import, print_function, unicode_literals
- # Import Salt libs
- import salt.modules.nexus as nexus
- # Import Salt testing libs
- from tests.support.mixins import LoaderModuleMockMixin
- from tests.support.mock import MagicMock, patch
- from tests.support.unit import TestCase
- class nexusTestCase(TestCase, LoaderModuleMockMixin):
- def setup_loader_modules(self):
- return {nexus: {}}
- def test_artifact_get_metadata(self):
- with patch(
- "salt.modules.nexus._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>
- <release>0.1.0</release>
- <versions>
- <version>0.0.1</version>
- <version>0.0.2</version>
- <version>0.0.3</version>
- <version>0.1.0</version>
- </versions>
- <lastUpdated>20171010143552</lastUpdated>
- </versioning>
- </metadata>"""
- ),
- ):
- metadata = nexus._get_artifact_metadata(
- nexus_url="http://nexus.example.com/repository",
- repository="libs-releases",
- group_id="com.company.sampleapp.web-module",
- artifact_id="web",
- headers={},
- )
- self.assertEqual(metadata["latest_version"], "0.1.0")
- def test_snapshot_version_get_metadata(self):
- with patch(
- "salt.modules.nexus._get_snapshot_version_metadata_xml",
- MagicMock(
- return_value="""<?xml version="1.0" encoding="UTF-8"?>
- <metadata modelVersion="1.1.0">
- <groupId>com.company.sampleapp.web-module</groupId>
- <artifactId>web</artifactId>
- <version>0.0.2-SNAPSHOT</version>
- <versioning>
- <snapshot>
- <timestamp>20170920.212353</timestamp>
- <buildNumber>3</buildNumber>
- </snapshot>
- <lastUpdated>20171112171500</lastUpdated>
- <snapshotVersions>
- <snapshotVersion>
- <classifier>sans-externalized</classifier>
- <extension>jar</extension>
- <value>0.0.2-20170920.212353-3</value>
- <updated>20170920212353</updated>
- </snapshotVersion>
- <snapshotVersion>
- <classifier>dist</classifier>
- <extension>zip</extension>
- <value>0.0.2-20170920.212353-3</value>
- <updated>20170920212353</updated>
- </snapshotVersion>
- </snapshotVersions>
- </versioning>
- </metadata>"""
- ),
- ):
- metadata = nexus._get_snapshot_version_metadata(
- nexus_url="http://nexus.example.com/repository",
- repository="libs-releases",
- group_id="com.company.sampleapp.web-module",
- artifact_id="web",
- version="0.0.2-SNAPSHOT",
- headers={},
- )
- self.assertEqual(
- metadata["snapshot_versions"]["dist"], "0.0.2-20170920.212353-3"
- )
- def test_artifact_metadata_url(self):
- metadata_url = nexus._get_artifact_metadata_url(
- nexus_url="http://nexus.example.com/repository",
- repository="libs-releases",
- group_id="com.company.sampleapp.web-module",
- artifact_id="web",
- )
- self.assertEqual(
- metadata_url,
- "http://nexus.example.com/repository/libs-releases/com/company/sampleapp/web-module/web/maven-metadata.xml",
- )
- def test_snapshot_version_metadata_url(self):
- metadata_url = nexus._get_snapshot_version_metadata_url(
- nexus_url="http://nexus.example.com/repository",
- repository="libs-snapshots",
- group_id="com.company.sampleapp.web-module",
- artifact_id="web",
- version="0.0.2-SNAPSHOT",
- )
- self.assertEqual(
- metadata_url,
- "http://nexus.example.com/repository/libs-snapshots/com/company/sampleapp/web-module/web/0.0.2-SNAPSHOT/maven-metadata.xml",
- )
- def test_construct_url_for_released_version(self):
- artifact_url, file_name = nexus._get_release_url(
- repository="libs-releases",
- group_id="com.company.sampleapp.web-module",
- artifact_id="web",
- packaging="zip",
- nexus_url="http://nexus.example.com/repository",
- version="0.1.0",
- )
- self.assertEqual(
- artifact_url,
- "http://nexus.example.com/repository/libs-releases/com/company/sampleapp/web-module/web/0.1.0/web-0.1.0.zip",
- )
- self.assertEqual(file_name, "web-0.1.0.zip")
- def test_construct_url_for_snapshot_version(self):
- with patch(
- "salt.modules.nexus._get_snapshot_version_metadata",
- MagicMock(
- return_value={"snapshot_versions": {"zip": "0.0.2-20170920.212353-3"}}
- ),
- ):
- artifact_url, file_name = nexus._get_snapshot_url(
- nexus_url="http://nexus.example.com/repository",
- repository="libs-snapshots",
- group_id="com.company.sampleapp.web-module",
- artifact_id="web",
- version="0.2.0-SNAPSHOT",
- packaging="zip",
- headers={},
- )
- self.assertEqual(
- artifact_url,
- "http://nexus.example.com/repository/libs-snapshots/com/company/sampleapp/web-module/web/0.2.0-SNAPSHOT/web-0.0.2-20170920.212353-3.zip",
- )
- self.assertEqual(file_name, "web-0.0.2-20170920.212353-3.zip")
|