import pytest

from dcicutils.qa_utils import notice_pytest_fixtures
from .workbook_fixtures import app_settings, workbook
# from ..utils import delay_rerun


notice_pytest_fixtures(app_settings, workbook)

# https://stackoverflow.com/a/42512169
if pytest.__version__ < "3.0.0":
  pytest.skip()
else:
  pytestmark = pytest.mark.skip

# pytestmark = [
#     pytest.mark.working, pytest.mark.indexing,
#     # pytest.mark.flaky(rerun_filter=delay_rerun),
# ]

def test_validation_err_facet(workbook, testapp):
    res = testapp.get('/search/?type=ExperimentSetReplicate').json
    val_err_facets = [facet for facet in res['facets'] if facet['title'] == 'Validation Errors']
    assert len(val_err_facets) == 1
    assert val_err_facets[0]['aggregation_type'] == 'terms'


def test_validation_err_itemview(workbook, testapp):
    res = testapp.get('/experiment-set-replicates/4DNESAAAAAA1/').json
    assert 'validation-errors' in res.keys()


def test_validation_err_view(workbook, testapp):
    res = testapp.get('/experiment-set-replicates/4DNESAAAAAA1/@@validation-errors').json
    assert res['@id'] == '/experiment-set-replicates/4DNESAAAAAA1/'
    assert 'validation_errors' in res

import pytest

from dcicutils.qa_utils import notice_pytest_fixtures
from .workbook_fixtures import app_settings, workbook
# from ..utils import delay_rerun


notice_pytest_fixtures(app_settings, workbook)

# skip the tests since validation_errors removed in search.py
# workaround: pytest.mark.skip fails in GithubActions: https://stackoverflow.com/a/42512169
if pytest.__version__ < "3.0.0":
  pytest.skip()
else:
  pytestmark = pytest.mark.skip

# pytestmark = [
#     pytest.mark.working, pytest.mark.indexing,
#     # pytest.mark.flaky(rerun_filter=delay_rerun),
# ]

def test_validation_err_facet(workbook, testapp):
    res = testapp.get('/search/?type=ExperimentSetReplicate').json
    val_err_facets = [facet for facet in res['facets'] if facet['title'] == 'Validation Errors']
    assert len(val_err_facets) == 1
    assert val_err_facets[0]['aggregation_type'] == 'terms'


def test_validation_err_itemview(workbook, testapp):
    res = testapp.get('/experiment-set-replicates/4DNESAAAAAA1/').json
    assert 'validation-errors' in res.keys()


def test_validation_err_view(workbook, testapp):
    res = testapp.get('/experiment-set-replicates/4DNESAAAAAA1/@@validation-errors').json
    assert res['@id'] == '/experiment-set-replicates/4DNESAAAAAA1/'
    assert 'validation_errors' in res

update test_validation_errors unit test - 3