-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration tests #291
base: master
Are you sure you want to change the base?
Integration tests #291
Changes from all commits
ca7dc98
4578b2d
ace2d28
736881f
8e57d0b
80c02ac
a912261
5424aad
5166c92
ddf362c
bdaa657
3cf5bb0
9affb45
ddefdd4
3434be8
8bbfa90
fb892ba
119fbd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Integration tests | ||
run-name: Integration tests | ||
on: [push] | ||
jobs: | ||
integration-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: echo "Executing Integration tests" | ||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" | ||
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." | ||
- uses: browser-actions/setup-chrome@v1 | ||
- run: chrome --version | ||
- run: echo "🖥️ The workflow is now ready to test your code on the runner." | ||
- name: "Create python environment" | ||
run: | | ||
python3 -m venv calibre-web-env | ||
source calibre-web-env/bin/activate | ||
- name: Install Python dependencies for testing | ||
uses: py-actions/py-dependency-install@v4 | ||
with: | ||
path: "requirements.txt" | ||
- name: "Download dummy database" | ||
run: | | ||
wget -O app.db "https://github.com/iiab/iiab/raw/refs/heads/master/roles/calibre-web/files/app.db" | ||
- name: "Debugging line" | ||
run: | | ||
ls -la | ||
- name: "Execute calibre web in background" | ||
run: | | ||
nohup python3 cps.py & | ||
- name: "Verify local website" | ||
run: | | ||
curl -L localhost:8083 | ||
- name: Install Python dependencies for testing | ||
uses: py-actions/py-dependency-install@v4 | ||
with: | ||
path: "integration-tests-requirements.txt" | ||
- name: Execute PyTest for Integration Tests | ||
run: | | ||
HEADLESS=true pytest -s |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,4 @@ gdrive_credentials | |
client_secrets.json | ||
gmail.json | ||
/.key | ||
environments/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Feature: Basic behavior | ||
Testing basic behavior like showing home page and login | ||
|
||
Scenario: Home Page | ||
Given Calibre web is running | ||
When I go to the home page | ||
|
||
Then I should not see the error message | ||
And see homepage information | ||
|
||
Scenario: Login | ||
Given I visit the calibre web homepage | ||
When I login with valid credentials | ||
|
||
Then I should see the success message | ||
And see the information for logged users | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
attrs==24.2.0 | ||
certifi==2024.8.30 | ||
charset-normalizer==3.4.0 | ||
h11==0.14.0 | ||
idna==3.10 | ||
iniconfig==2.0.0 | ||
Mako==1.3.6 | ||
MarkupSafe==3.0.2 | ||
outcome==1.3.0.post0 | ||
packaging==24.1 | ||
parse==1.20.2 | ||
parse_type==0.6.4 | ||
pluggy==1.5.0 | ||
PySocks==1.7.1 | ||
pytest==8.3.3 | ||
pytest-bdd==7.3.0 | ||
pytest-splinter==3.3.2 | ||
python-dotenv==1.0.1 | ||
requests==2.32.3 | ||
selenium==4.25.0 | ||
setuptools==75.2.0 | ||
six==1.16.0 | ||
sniffio==1.3.1 | ||
sortedcontainers==2.4.0 | ||
splinter==0.21.0 | ||
trio==0.27.0 | ||
trio-websocket==0.11.1 | ||
typing_extensions==4.12.2 | ||
urllib3==2.2.3 | ||
webdriver-auto-update==1.2.1 | ||
webdriver-manager==4.0.2 | ||
websocket-client==1.8.0 | ||
wget==3.2 | ||
wsproto==1.2.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
bdd_features_base_dir = features/ |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||||
"""Basic behavior feature tests.""" | ||||||||
import pytest | ||||||||
from pytest_bdd import ( | ||||||||
given, | ||||||||
scenario, | ||||||||
then, | ||||||||
when, | ||||||||
) | ||||||||
|
||||||||
import os | ||||||||
import subprocess | ||||||||
from urllib.parse import urljoin | ||||||||
import time | ||||||||
|
||||||||
@pytest.fixture(scope='session') | ||||||||
def splinter_headless(): | ||||||||
"""Override splinter headless option.""" | ||||||||
if os.environ['HEADLESS'] == "true": | ||||||||
return True | ||||||||
else: | ||||||||
return False | ||||||||
|
||||||||
@pytest.fixture(scope='session') | ||||||||
def splinter_webdriver(): | ||||||||
"""Override splinter webdriver name.""" | ||||||||
return 'chrome' | ||||||||
|
||||||||
# Fixture to save information to use through steps | ||||||||
@pytest.fixture | ||||||||
def step_context(): | ||||||||
return {} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
@scenario('basic_behavior.feature', 'Home Page') | ||||||||
def test_home_page(): | ||||||||
"""Home Page.""" | ||||||||
|
||||||||
|
||||||||
@given('Calibre web is running') | ||||||||
def _(step_context): | ||||||||
"""Calibre web is running.""" | ||||||||
step_context['ip_address'] = 'localhost:8083' | ||||||||
|
||||||||
|
||||||||
@when('I go to the home page') | ||||||||
def _(browser, step_context): | ||||||||
"""I go to the home page.""" | ||||||||
url = urljoin("".join(['http://', str(step_context['ip_address'])]), '/') | ||||||||
browser.visit(url) | ||||||||
|
||||||||
|
||||||||
@then('I should not see the error message') | ||||||||
def _(browser, step_context): | ||||||||
"""I should not see the error message.""" | ||||||||
|
||||||||
@then('see homepage information') | ||||||||
def _(browser): | ||||||||
"""see homepage information.""" | ||||||||
print("!!!!!!!") | ||||||||
print(browser.title) | ||||||||
print(browser.url) | ||||||||
print("!!!!!!!") | ||||||||
assert browser.is_text_present('Books'), 'Book test' | ||||||||
|
||||||||
@scenario('basic_behavior.feature', 'Login') | ||||||||
def test_login(): | ||||||||
"""Login.""" | ||||||||
|
||||||||
|
||||||||
@given('I visit the calibre web homepage') | ||||||||
def _(browser, step_context): | ||||||||
"""I visit the calibre web homepage.""" | ||||||||
step_context['ip_address'] = 'localhost:8083' | ||||||||
url = urljoin("".join(['http://', str(step_context['ip_address'])]), '/') | ||||||||
browser.visit(url) | ||||||||
|
||||||||
|
||||||||
@when('I login with valid credentials') | ||||||||
def _(browser, step_context): | ||||||||
"""I login with valid credentials.""" | ||||||||
browser.fill('username', 'Admin') | ||||||||
browser.fill('password', 'changeme') | ||||||||
button = browser.find_by_name('submit') | ||||||||
# Interact with elements | ||||||||
button.click() | ||||||||
|
||||||||
|
||||||||
@then('I should see the success message') | ||||||||
def _(browser, step_context): | ||||||||
"""I should see the success message.""" | ||||||||
assert browser.is_text_present('You are now logged in as:'), 'Login successful' | ||||||||
|
||||||||
@then('see the information for logged users') | ||||||||
def _(browser): | ||||||||
"""see the information for logged users""" | ||||||||
assert browser.is_text_present('Books'), 'Book test' | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a more descriptive error message
Suggested change
|
||||||||
assert browser.is_text_present('Download to IIAB'), 'IIAB button' | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A more descriptive error message would be better here too
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thotmx is Line 175 supposed to be identical to Line 181?
(Can you clarify? If possible!)