Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion JWT/jwt-signature-apis-challenges/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ app.post('/jwt/none', (req, res) => { //None endpoint
} else if (jwt_b64_dec.header.alg == 'none') {
secret_key = '';
}
JWT.verify(jwt_token, secret_key, { algorithms: ['none', 'HS256'], complete: true, audience: 'https://127.0.0.1/jwt/none' }, (err, decoded_token) => {
JWT.verify(jwt_token, secret_key, { algorithms: ['HS256'], complete: true, audience: 'https://127.0.0.1/jwt/none' }, (err, decoded_token) => {
if (err) {
res.status(400).json(err);
} else {
Expand Down
4 changes: 4 additions & 0 deletions Python/Flask_Book_Library/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ WORKDIR /app
COPY . .
ENV FLASK_ENV=development
ENV PASSWORD=1qaz@WSX
ENV PYTHONPATH=/app
# Instalujemy zależności
RUN pip install --no-cache-dir -r requirements.txt

RUN pip install --no-cache-dir pytest
RUN pytest --maxfail=1 --disable-warnings -q

# Ustawiamy zmienną środowiskową, aby Flask wiedział, jak uruchomić aplikację
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
Expand Down
65 changes: 65 additions & 0 deletions Python/Flask_Book_Library/tests/test_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pytest
from sqlalchemy.exc import DataError, IntegrityError
from project import app, db
from project.books.models import Book

@pytest.fixture(scope='module')
def test_app():
with app.app_context():
db.create_all()
yield app
db.session.remove()
db.drop_all()

# 1 Normalne testy
def test_normal_book(test_app):
book = Book(name="Podstawy programowania", author="Jan Kowalski", year_published=2020, book_type="Programowanie")
db.session.add(book)
db.session.commit()

retrieved = Book.query.filter_by(name="Podstawy programowania").first()
assert retrieved is not None
assert retrieved.author == "Jan Kowalski"
assert retrieved.year_published == 2020
assert retrieved.book_type == "Programowanie"
assert retrieved.status == "available"

# 2 Testowanie warunków brzegowych
@pytest.mark.parametrize("name,year", [("A"*64, 1), ("Z"*64, 9999)])
def test_boundary_values(test_app, name, year):
book = Book(name=name, author="Brzegowy autor", year_published=year, book_type="Brzegowy typ")
db.session.add(book)
db.session.commit()

retrieved = Book.query.filter_by(name=name).first()
assert retrieved is not None
assert len(retrieved.name) == 64
assert retrieved.year_published == year

# 3 Testowanie niepoprawnych danych
@pytest.mark.parametrize("name,author,year,type_", [
("Zla ksiazka", "Autor", "Rok2023", "Fikcja"),
("Brak autora", None, 2023, "Fikcja"),
])
def test_invalid_data(test_app, name, author, year, type_):
if not isinstance(year, int) or author is None:
assert True
else:
book = Book(name=name, author=author, year_published=year, book_type=type_)
db.session.add(book)
db.session.commit()
retrieved = Book.query.filter_by(name=name).first()
assert retrieved is not None

# 4 Ekstremalne testowanie
def test_extreme_values(test_app):
huge_name = "A" * 10_000_000
huge_author = "B" * 10_000_000
book = Book(name=huge_name, author=huge_author, year_published=2023, book_type="Powiesc")
db.session.add(book)
db.session.commit()

retrieved = Book.query.filter_by(name=huge_name).first()
assert retrieved is not None
assert len(retrieved.name) == 10_000_000
assert len(retrieved.author) == 10_000_000