TestManifestGenerator.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python2.6
  2. '''
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. '''
  17. import os
  18. from unittest import TestCase
  19. from ambari_agent import manifestGenerator
  20. import ambari_agent.AmbariConfig
  21. import tempfile
  22. import json
  23. import shutil
  24. from ambari_agent.AmbariConfig import AmbariConfig
  25. from mock.mock import patch, MagicMock, call
  26. class TestManifestGenerator(TestCase):
  27. def setUp(self):
  28. self.dir = tempfile.mkdtemp()
  29. self.config = AmbariConfig()
  30. jsonCommand = file('../../main/python/ambari_agent/test.json').read()
  31. self.parsedJson = json.loads(jsonCommand)
  32. pass
  33. def tearDown(self):
  34. shutil.rmtree(self.dir)
  35. pass
  36. def testWriteImports(self):
  37. tmpFileName = tempfile.mkstemp(dir=self.dir, text=True)[1]
  38. print tmpFileName
  39. tmpFile = file(tmpFileName, 'r+')
  40. manifestGenerator.writeImports(tmpFile, '../../main/puppet/modules', self.config.getImports())
  41. tmpFile.seek(0)
  42. print tmpFile.read()
  43. tmpFile.close()
  44. pass
  45. @patch.object(manifestGenerator, 'writeImports')
  46. @patch.object(manifestGenerator, 'writeNodes')
  47. @patch.object(manifestGenerator, 'writeParams')
  48. @patch.object(manifestGenerator, 'writeTasks')
  49. def testGenerateManifest(self, writeTasksMock, writeParamsMock, writeNodesMock, writeImportsMock):
  50. tmpFileName = tempfile.mkstemp(dir=self.dir, text=True)[1]
  51. manifestGenerator.generateManifest(self.parsedJson, tmpFileName, '../../main/puppet/modules', self.config.getConfig())
  52. self.assertTrue(writeParamsMock.called)
  53. self.assertTrue(writeNodesMock.called)
  54. self.assertTrue(writeImportsMock.called)
  55. self.assertTrue(writeTasksMock.called)
  56. print file(tmpFileName).read()
  57. pass