from unittest import mock import os import datetime import unittest from kojihub import _write_maven_repo_metadata class TestWriteMavenRepoMetadata(unittest.TestCase): # Show long diffs in error output... maxDiff = None @mock.patch('kojihub.kojihub._generate_maven_metadata') def test_write_maven_repo_metadata(self, gendata_mock): destdir = '/tmp' artifacts = set() # group_id, artifact_id, version artifacts.add(('0', '1', '1.2')) artifacts.add(('0', '1', '1.3')) artifacts.add(('0', '1', '1.1')) artifacts.add(('0', '1', '1.3.1')) artifacts.add(('0', '1', '1.3.15')) artifacts.add(('0', '1', '1.3.3')) artifacts.add(('0', '1', '1.3.6')) artifacts.add(('0', '1', '1.3.11')) now = datetime.datetime.now() with mock.patch('kojihub.kojihub.open', create=True) as openf_mock: with mock.patch('datetime.datetime') as datetime_mock: datetime_mock.now.return_value = now _write_maven_repo_metadata(destdir, artifacts) openf_mock.assert_called_with( os.path.join(destdir, 'maven-metadata.xml'), 'wt', encoding='utf-8') handle = openf_mock().__enter__() expected = """\ 0 1 1.3.15 1.3.15 1.1 1.2 1.3 1.3.1 1.3.3 1.3.6 1.3.11 1.3.15 %s """ % now.strftime('%Y%m%d%H%M%S') handle.write.assert_called_with(expected)