def test_pushapps_default(discover_apps_, hook, document_): ''' Test case for ``pushapps {path}`` with default flags Algo: 1. discover apps #. for each app 1. pre-push 2. add to list apps 3. post-push #. for each db 1. db.save_docs ''' conf = NonCallableMock(name='conf') dest = 'http://localhost:5984' doc = document_() db = Mock(name='db') dbs = MagicMock(name='dbs') dbs.__iter__.return_value = iter([db]) conf.get_dbs.return_value = dbs ret_code = commands.pushapps(conf, '/mock_dir', dest) assert ret_code == 0 conf.get_dbs.assert_called_with(dest) hook.assert_any_call(conf, 'foo', 'pre-push', dbs=dbs, pushapps=True) hook.assert_any_call(conf, 'foo', 'post-push', dbs=dbs, pushapps=True) assert db.save_docs.called
def test_pushapps_output_null(discover_apps_, hook, document_, write_json): ''' Test case for pushapps with ``--export --output file``, but no any apps discovered Algo: see :py:meth:`test_pushapps_output` ''' conf = NonCallableMock(name='conf') dest = None ret_code = commands.pushapps(conf, '/mock_dir', dest, export=True, output='file') assert ret_code == 0 discover_apps_.assert_called_with('/mock_dir') assert not hook.called assert not document_.called assert not write_json.called
def test_pushapps_noatomic(discover_apps_, hook, document_): ''' Test case for pushapps with ``--no-atomic`` Algo: 1. discover apps #. for each app 1. pre-push 2. push 3. post-push ''' conf = NonCallableMock(name='conf') dest = 'http://localhost:5984' doc = document_() dbs = conf.get_dbs() ret_code = commands.pushapps(conf, '/mock_dir', dest, no_atomic=True) assert ret_code == 0 conf.get_dbs.assert_called_with(dest) hook.assert_any_call(conf, 'foo', 'pre-push', dbs=dbs, pushapps=True) hook.assert_any_call(conf, 'foo', 'post-push', dbs=dbs, pushapps=True) doc.push.assert_called_with(dbs, True, False)
def test_pushapps_export(discover_apps_, hook, document_, dumps): ''' Test case for pushapps with ``--export``, Algo: 1. discover apps #. pre-push #. add app to a list ``apps`` #. post-push #. json.dumps from apps ''' conf = NonCallableMock(name='conf') dest = None ret_code = commands.pushapps(conf, '/mock_dir', dest, export=True) assert ret_code == 0 discover_apps_.assert_called_with('/mock_dir') hook.assert_any_call(conf, 'foo', 'pre-push', dbs=None, pushapps=True) hook.assert_any_call(conf, 'foo', 'post-push', dbs=None, pushapps=True) assert dumps.called
def test_pushapps_output(discover_apps_, hook, document_, write_json): ''' Test case for pushapps with ``--export --output file`` Algo: 1. discover apps #. pre-push #. add app to a list ``apps`` #. post-push #. write_json(apps) ''' conf = NonCallableMock(name='conf') dest = None ret_code = commands.pushapps(conf, '/mock_dir', dest, export=True, output='file') assert ret_code == 0 discover_apps_.assert_called_with('/mock_dir') hook.assert_any_call(conf, 'foo', 'pre-push', dbs=None, pushapps=True) hook.assert_any_call(conf, 'foo', 'post-push', dbs=None, pushapps=True) 'file' in write_json.call_args[0]