Skip to content

Commit

Permalink
[QOLDEV-1005] sync test config with other repos
Browse files Browse the repository at this point in the history
- Update scenario test assertions to handle CKAN 2.11 markup changes
- Speed up test init by running database setup alongside container start
  • Loading branch information
ThrawnCA committed Dec 18, 2024
1 parent 1eb5125 commit 5cf8437
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
10 changes: 6 additions & 4 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ commands:
ahoy clean
ahoy build-network
ahoy up -- --build --force-recreate
ahoy install-site
ahoy title "Build complete"
ahoy doctor
ahoy info 1
Expand All @@ -38,7 +37,9 @@ commands:
cmd: |
ahoy title "Building and starting Docker containers"
sh bin/docker-compose.sh up -d "$@"
sleep 10
echo "Initialising database schema"
ahoy cli '"${APP_DIR}"/bin/init.sh'
echo "Waiting for containers to start listening..."
ahoy cli "dockerize -wait tcp://ckan:5000 -timeout 1m"
if sh bin/docker-compose.sh logs | grep -q "\[Error\]"; then exit 1; fi
if sh bin/docker-compose.sh logs | grep -q "Exception"; then exit 1; fi
Expand Down Expand Up @@ -91,7 +92,7 @@ commands:
usage: Install test site data.
cmd: |
ahoy title "Installing a fresh site"
ahoy cli '"${APP_DIR}"/bin/init.sh'
ahoy cli '"${APP_DIR}"/bin/init.sh && "${APP_DIR}"/bin/create-test-data.sh'
clean:
usage: Remove containers and all build files.
Expand Down Expand Up @@ -144,7 +145,8 @@ commands:
ahoy start-ckan-job-worker &
ahoy start-mailmock &
sleep 5
ahoy cli "behave --junit -k ${*:-test/features} --tags=-format_autocomplete --junit-directory=test/junit/" || \
JUNIT_OUTPUT="--junit --junit-directory=test/junit/"
ahoy cli "behave $JUNIT_OUTPUT -k ${*:-test/features} --tags=-format_autocomplete" || \
[ "${ALLOW_BDD_FAIL:-0}" -eq 1 ]
ahoy stop-mailmock
ahoy stop-ckan-job-worker
Expand Down
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ ALLOW_BDD_FAIL=0
# Disable amazeeio based health checks
DOCTOR_CHECK_WEBSERVER=0
DOCTOR_CHECK_BOOTSTRAP=0
DOCTOR_CHECK_PYGMY=0
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
run: echo HOME=/root >> "$GITHUB_ENV"

- uses: actions/checkout@v4
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 2

- name: Build
Expand All @@ -59,22 +60,26 @@ jobs:
- name: Retrieve logs
if: always()
run: ahoy logs
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 1

- name: Retrieve results
if: always()
run: bin/process-artifacts.sh
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 1

- name: Test Summary
uses: test-summary/action@v2
continue-on-error: ${{ matrix.experimental }}
with:
paths: "/tmp/artifacts/junit/*.xml"
if: always()

- name: Upload screenshots
if: always()
uses: actions/upload-artifact@v4
continue-on-error: ${{ matrix.experimental }}
with:
name: CKAN ${{ matrix.ckan-version }} screenshots
path: /tmp/artifacts/behave/screenshots
Expand Down
8 changes: 4 additions & 4 deletions bin/create-test-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ add_user_if_needed () {
password="${4:-Password123!}"
}

api_call () {
wget -O - --header="Authorization: ${API_KEY}" --post-data "$1" ${CKAN_ACTION_URL}/$2
}

add_user_if_needed "$CKAN_USER_NAME" "$CKAN_DISPLAY_NAME" "$CKAN_USER_EMAIL"
ckan_cli sysadmin add "${CKAN_USER_NAME}"

Expand All @@ -43,10 +47,6 @@ add_user_if_needed test_org_member "Test Member" test_org_member@localhost

echo "Creating ${TEST_ORG_TITLE} organisation:"

api_call () {
wget -O - --header="Authorization: ${API_KEY}" --post-data "$1" ${CKAN_ACTION_URL}/$2
}

TEST_ORG=$( \
api_call '{"name": "'"${TEST_ORG_NAME}"'", "title": "'"${TEST_ORG_TITLE}"'",
"description": "Organisation for testing issues"}' organization_create
Expand Down
3 changes: 0 additions & 3 deletions bin/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ ckan_cli db upgrade
# Initialise report tables
ckan_cli report initdb
ckan_cli report generate tagless-datasets

# Create some base test data
. "${APP_DIR}"/bin/create-test-data.sh
24 changes: 19 additions & 5 deletions test/features/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def request_reset(context):
@when(u'I fill in "{name}" with "{value}" if present')
def fill_in_field_if_present(context, name, value):
context.execute_steps(u"""
When I execute the script "field = document.getElementById('field-{0}'); if (field) field.value = '{1}';"
When I execute the script "field = $('#{0}'); if (!field.length) field = $('[name={0}]'); if (!field.length) field = $('#field-{0}'); field.val('{1}'); field.keyup();"
""".format(name, value))


Expand All @@ -119,10 +119,24 @@ def add_resource(context, name, url):

@when(u'I fill in title with random text')
def title_random_text(context):
assert context.persona
context.execute_steps(u"""
When I fill in "title" with "Test Title {0}"
""".format(uuid.uuid4()))
When I fill in title with random text starting with "Test Title "
""")


@when(u'I fill in title with random text starting with "{prefix}"')
def title_random_text_with_prefix(context, prefix):
random_text = str(uuid.uuid4())
title = prefix + random_text
name = prefix.lower().replace(" ", "-") + random_text
assert context.persona
context.execute_steps(f"""
When I fill in "title" with "{title}"
And I fill in "name" with "{name}" if present
And I set "last_generated_title" to "{title}"
And I set "last_generated_name" to "{name}"
And I take a debugging screenshot
""")


@when(u'I go to dataset page')
Expand Down Expand Up @@ -268,7 +282,7 @@ def go_to_admin_config(context):
@when(u'I log out')
def log_out(context):
context.execute_steps(u"""
When I press the element with xpath "//*[@title='Log out']"
When I press the element with xpath "//*[@title='Log out' or @data-bs-title='Log out']"
Then I should see "Log in"
""")

Expand Down

0 comments on commit 5cf8437

Please sign in to comment.