def test_it_cannot_remove_a_git_module_not_present_in_the_puppetfile():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     puppetfile = Puppetfile(github_repository, 'env', sha='shasha')
     with pytest.raises(ModuleNotFoundException):
         puppetfile.remove_git_module('apache')
 def test_it_cannot_update_a_missing_module():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     puppetfile = Puppetfile(github_repository, 'env', sha='shasha')
     assert puppetfile.forge_modules == []
     with pytest.raises(ModuleNotFoundException):
         puppetfile.update_forge_module('puppetlabs/apache', '0.1.2')
 def test_it_cannot_add_an_existing_git_module():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     puppetfile = Puppetfile(github_repository,
                             'env',
                             sha='shasha',
                             git_modules=[GIT_MODULE_APACHE])
     with pytest.raises(ModuleAlreadyPresentException):
         puppetfile.add_git_module('apache', 'https://url/git/apache')
 def test_it_cannot_add_an_existing_module():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     forge_module_apache = ForgeModule('puppetlabs/apache')
     puppetfile = Puppetfile(github_repository,
                             'env',
                             sha='shasha',
                             forge_modules=[forge_module_apache])
     with pytest.raises(ModuleAlreadyPresentException):
         puppetfile.add_forge_module('puppetlabs/apache')
 def test_it_update_a_git_module_reference_and_reference_type():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     puppetfile = Puppetfile(github_repository,
                             'env',
                             sha='shasha',
                             git_modules=[deepcopy(GIT_MODULE_APACHE)])
     assert puppetfile.git_modules[0].reference == 'ed19f'
     puppetfile.update_git_module('apache',
                                  'master',
                                  reference_type='branch')
     assert puppetfile.git_modules[0].reference == 'master'
     assert puppetfile.git_modules[0].reference_type == 'branch'
 def test_it_remove_a_git_module_from_the_puppetfile():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     puppetfile = Puppetfile(github_repository,
                             'env',
                             sha='shasha',
                             git_modules=[GIT_MODULE_APACHE])
     assert GIT_MODULE_APACHE in puppetfile.git_modules
     puppetfile.remove_git_module('apache')
     assert puppetfile.git_modules == []
     github_repository.update_file.assert_called_once_with(
         "Puppetfile", "Puppetfile - Remove git module apache", "",
         "shasha")
 def test_it_remove_a_forge_module_from_the_puppetfile():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     forge_module_apache = ForgeModule('puppetlabs/apache', '0.1.10')
     puppetfile = Puppetfile(github_repository,
                             'env',
                             sha='shasha',
                             forge_modules=[forge_module_apache])
     assert forge_module_apache in puppetfile.forge_modules
     puppetfile.remove_forge_module('puppetlabs/apache')
     assert puppetfile.forge_modules == []
     github_repository.update_file.assert_called_once_with(
         "Puppetfile", "Puppetfile - Remove forge module puppetlabs/apache",
         "", "shasha")
 def test_it_returns_the_list_of_modules():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     git_module_custommod = GitModule('custommod',
                                      'https://url/git/custommod')
     forge_module_apache = ForgeModule('puppetlabs/apache', '0.1.10')
     forge_module_vcsrepo = ForgeModule('puppetlabs/vcsrepo', '0.2.10')
     puppetfile = Puppetfile(
         github_repository,
         'env',
         sha='shasha',
         forge_modules=[forge_module_apache, forge_module_vcsrepo],
         git_modules=[git_module_custommod])
     assert sorted(puppetfile.list_modules()) == sorted(
         ['custommod', 'puppetlabs/apache', 'puppetlabs/vcsrepo'])
 def test_it_add_a_module_to_the_puppetfile():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     puppetfile = Puppetfile(github_repository,
                             'env',
                             sha='shasha',
                             forge_modules=[FORGE_MODULE_NGINX])
     assert puppetfile.forge_modules == [FORGE_MODULE_NGINX]
     puppetfile.add_forge_module('puppetlabs/apache', '0.1.10')
     forge_module_apache = ForgeModule('puppetlabs/apache', '0.1.10')
     assert forge_module_apache in puppetfile.forge_modules
     github_repository.update_file.assert_called_once_with(
         "Puppetfile", "Puppetfile - Add forge module puppetlabs/apache",
         f"{str(FORGE_MODULE_NGINX)}mod 'puppetlabs/apache', '0.1.10'\n",
         "shasha")
 def test_it_update_a_module_in_the_puppetfile():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     forge_module_apache = ForgeModule('puppetlabs/apache', '0.1.1')
     puppetfile = Puppetfile(github_repository,
                             'env',
                             sha='shasha',
                             forge_modules=[forge_module_apache])
     assert puppetfile.forge_modules[0].version == '0.1.1'
     puppetfile.update_forge_module('puppetlabs/apache', version='0.1.2')
     assert puppetfile.forge_modules[0].version == '0.1.2'
     github_repository.update_file.assert_called_once_with(
         "Puppetfile",
         ("Puppetfile - Update forge module puppetlabs/apache "
          "from 0.1.1 to 0.1.2"), "mod 'puppetlabs/apache', '0.1.2'\n",
         "shasha")
 def test_it_update_a_git_module_in_the_puppetfile():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     puppetfile = Puppetfile(github_repository,
                             'env',
                             sha='shasha',
                             git_modules=[deepcopy(GIT_MODULE_APACHE)])
     assert puppetfile.git_modules[0].reference == 'ed19f'
     puppetfile.update_git_module('apache', 'a76f6fb')
     assert puppetfile.git_modules[0].reference == 'a76f6fb'
     github_repository.update_file.assert_called_once_with(
         "Puppetfile",
         "Puppetfile - Update git module apache from ed19f to a76f6fb",
         ("mod 'apache',\n"
          "  :git => 'https://url/git/apache',\n"
          "  :ref => 'a76f6fb'\n"), "shasha")
 def test_it_add_a_git_module_to_the_puppetfile():
     github_repository = MagicMock()
     content = github_repository.get_file_contents()
     content.decoded_content.decode.return_value = ('')
     puppetfile = Puppetfile(github_repository,
                             'env',
                             sha='shasha',
                             git_modules=[GIT_MODULE_NGINX])
     assert puppetfile.git_modules == [GIT_MODULE_NGINX]
     puppetfile.add_git_module('apache',
                               'https://url/git/apache',
                               reference_type='ref',
                               reference='ed19f')
     assert GIT_MODULE_APACHE in puppetfile.git_modules
     github_repository.update_file.assert_called_once_with(
         "Puppetfile", "Puppetfile - Add git module apache",
         (f'{str(GIT_MODULE_NGINX)}'
          "mod 'apache',\n"
          "  :git => 'https://url/git/apache',\n"
          "  :ref => 'ed19f'\n"), "shasha")