def test_sync_invalid_model(sync_model_mock):
    """
    Test that if an invalid value is used with --model, nothing gets synced.
    """
    management.call_command(sync_es.Command(), model='invalid')

    assert sync_model_mock.apply_async.call_count == 0
def test_sync_all_models(sync_model_mock):
    """
    Test that if --model is not used, all the search apps are synced.
    """
    management.call_command(sync_es.Command())

    assert sync_model_mock.apply_async.call_count == len(get_search_apps())
def test_sync_one_model(sync_model_mock, search_model):
    """
    Test that --model can be used to specify what we want to sync.
    """
    management.call_command(sync_es.Command(), model=[search_model])

    assert sync_model_mock.apply_async.call_count == 1
Example #4
0
def test_sync_es(get_search_apps_by_name_mock, sync_es_mock):
    """Tests syncing app to Elasticsearch."""
    management.call_command(sync_es.Command(), batch_size=1)

    sync_es_mock.assert_called_once_with(
        batch_size=1,
        search_apps=get_search_apps_by_name_mock.return_value,
    )
def test_sync_synchronously(sync_model_mock):
    """
    Test that --foreground can be used to run the command in a synchronous (blocking) fashion.
    """
    app = get_search_apps()[0]
    management.call_command(sync_es.Command(),
                            model=[app.name],
                            foreground=True)

    assert sync_model_mock.apply.call_count == 1
    assert not sync_model_mock.apply_async.called
def test_fails_if_index_doesnt_exist():
    """Tests that if the index doesn't exist, sync_es fails."""
    with pytest.raises(CommandError):
        management.call_command(sync_es.Command())