def test_latest_installed_but_outdated(monkeypatch): monkeypatch.setattr( NPM, 'run', build_run( fixture_subpath='npm', command_mappings=[ CommandMapping( command=[ 'npm', 'list', '--json', '--depth 0', '--prefix', '/Users/fots/project', 'express' ], stdout_filename='npm_list_installed_but_outdated.stdout'), CommandMapping( command=['npm', 'view', '--json', 'express'], stdout_filename='npm_view_installed_but_outdated.stdout'), CommandMapping(command=[ 'npm', 'install', '--prefix', '/Users/fots/project', 'express' ]) ])) npm = NPM(name='express', state='latest', executable='npm', path='/Users/fots/project') assert npm.process() == ActionResponse(changed=True)
def test_global_install(monkeypatch): monkeypatch.setattr( NPM, 'run', build_run( fixture_subpath='npm', command_mappings=[ CommandMapping(command=[ 'npm', 'list', '--json', '--depth 0', '--global', 'express' ], stdout_filename='npm_list_installed.stdout') ])) npm = NPM(name='express', state='present', executable='npm', mode='global') assert npm.process() == ActionResponse(changed=False)
def test_executable_unspecified(monkeypatch): monkeypatch.setattr( NPM, 'run', build_run(fixture_subpath='npm', command_mappings=[ CommandMapping( command=[ 'npm', 'list', '--json', '--depth 0', '--prefix', '/Users/fots/project', 'express' ], stdout_filename='npm_list_installed.stdout') ])) npm = NPM(name='express', state='present', path='/Users/fots/project') assert npm.process() == ActionResponse(changed=False)
def test_list_command_invalid(monkeypatch): monkeypatch.setattr( NPM, 'run', build_run(fixture_subpath='npm', command_mappings=[ CommandMapping(command=[ 'npm', 'list', '--json', '--depth 0', '--prefix', '/Users/fots/project', 'express' ], returncode=2) ])) npm = NPM(name='express', state='present', executable='npm', path='/Users/fots/project') with pytest.raises(ActionError): npm.process()
def test_present_with_version_installed_different(monkeypatch): monkeypatch.setattr( NPM, 'run', build_run(fixture_subpath='npm', command_mappings=[ CommandMapping( command=[ 'npm', 'list', '--json', '--depth 0', '--prefix', '/Users/fots/project', 'express' ], stdout_filename='npm_list_installed.stdout'), CommandMapping(command=[ 'npm', 'install', '--prefix', '/Users/fots/project', '[email protected]' ]) ])) npm = NPM(name='express', version='4.15.5', state='present', executable='npm', path='/Users/fots/project') assert npm.process() == ActionResponse(changed=True)
def test_argument_state_invalid(): with pytest.raises(ValueError): NPM(name='express', state='hmmm', path='/Users/fots/project')
def test_argument_path_after_init_invalid(): npm = NPM(name='express', mode='local', path='/Users/fots/project') with pytest.raises(ValueError): npm.path = None
def test_argument_mode_after_init_invalid(): npm = NPM(name='express', mode='global') with pytest.raises(ValueError): npm.mode = 'local'
def test_argument_mode_path_combination_invalid(): with pytest.raises(ValueError): NPM(name='express', mode='local')
def test_argument_state_after_init_invalid(): npm = NPM(name='express', version='4.16.3', path='/Users/fots/project') with pytest.raises(ValueError): npm.state = 'latest'
def test_argument_version_state_combination_invalid(): with pytest.raises(ValueError): NPM(name='express', state='latest', version='4.16.3', path='/Users/fots/project')