-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/getjoke #143
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
Merged
yammesicka
merged 43 commits into
PythonFreeCourse:develop
from
fandomario:feature/getjoke
Feb 20, 2021
Merged
Feature/getjoke #143
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
3067c2f
feat: add a joke generator to the online calendar.
fandomario cc9c58c
fix: according to flake8
fandomario 0823233
fix: seperate the js code to a different file in static
fandomario 779de2d
feat: add i18n support (#115)
Gonzom 6370ef2
Revert "feat: add i18n support (#115)" (#161)
yammesicka afaa4b2
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
fandomario fac77dd
Merge branch 'develop' into feature/getjoke
fandomario 0554c88
fix: flake8
fandomario 05d87c8
Merge branch 'main' of https://github.com/PythonFreeCourse/calendar i…
fandomario 40cfeee
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
fandomario ea08c94
Merge branch 'feature/getjoke' of https://github.com/fandomario/calen…
fandomario cd979eb
fix: flake8
fandomario 905eb0d
fix: add db tests
fandomario 4fd7a4e
fix: flake8
fandomario 7f38da9
Update our production site. (#209)
yammesicka 024cf85
feat: add a joke generator to the online calendar.
fandomario c730e26
Merge branch 'main' of https://github.com/PythonFreeCourse/calendar i…
fandomario 8f4ccad
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
fandomario 39fc16a
fix: trying to debug the test error
fandomario 5fb3333
fix: debug
fandomario 979f691
fix: debugging
fandomario f4ea217
fix: add a test
fandomario cc09511
fix: debug1
fandomario 3a71bc2
fix: debug2
fandomario 22c14ad
fix: debug3
fandomario f477a89
fix: debug4
fandomario f6cdb37
fix: add a test
fandomario 1c56f78
fix: debug5
fandomario 830d690
feat: add a joke generator to the online calendar.
fandomario 85bca46
fix: change to url_for
fandomario 67534af
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
fandomario 74a2e83
fix: flake8 1
fandomario 211cbad
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
fandomario b1f1b8b
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
fandomario 9a89069
fix: fixing tests
fandomario 745a533
fix: according to cr (wasn't the right file)
fandomario 7b1842d
fix: accordind to CR
fandomario 45eb8bc
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
fandomario 4a73725
fix: flake8
fandomario 483c4d5
fix: change "alert" to SweetAlert2
fandomario fb1109f
Merge branch 'develop' into feature/getjoke
fandomario 485715b
Merge branch 'feature/getjoke' of https://github.com/fandomario/calen…
fandomario 8a52104
fix: change the way jokes are loaded and use json_data_loader
fandomario File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Dict, Optional | ||
|
||
from sqlalchemy.orm import Session | ||
from sqlalchemy.sql.expression import func | ||
|
||
from app.database.models import Joke | ||
|
||
|
||
def get_joke(joke_: Dict[str, Optional[str]]) -> Joke: | ||
"""Returns a Joke object from the dictionary data. | ||
|
||
Args: | ||
joke_: A dictionary joke related information. | ||
|
||
Returns: | ||
A new Joke object. | ||
""" | ||
return Joke( | ||
text=joke_['text'], | ||
) | ||
|
||
|
||
def get_a_joke(session: Session): | ||
return session.query(Joke).order_by(func.random()).first() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from fastapi import APIRouter, Depends, Request | ||
from app.internal import jokes | ||
from sqlalchemy.orm import Session | ||
from app.dependencies import get_db | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/joke") | ||
async def joke(request: Request, db: Session = Depends(get_db)): | ||
return jokes.get_a_joke(db) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function makejoke() { | ||
fetch('/joke') | ||
.then(response => response.json()) | ||
.then(data => Swal.fire(data.text)); | ||
} | ||
|
||
|
||
function addEventsAfterPageLoaded() { | ||
const element = document.getElementById("a-joke"); | ||
element.addEventListener("click", makejoke, false); | ||
} | ||
|
||
|
||
document.addEventListener("DOMContentLoaded", addEventsAfterPageLoaded); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
from sqlalchemy.orm import Session | ||
|
||
from app.database.models import Joke | ||
from app.internal.utils import create_model, delete_instance | ||
|
||
|
||
def add_joke(session: Session, id_joke: int, text: str) -> Joke: | ||
joke = create_model(session, Joke, id=id_joke, text=text) | ||
yield joke | ||
delete_instance(session, joke) | ||
|
||
|
||
@pytest.fixture | ||
def joke(session: Session) -> Joke: | ||
yield from add_joke( | ||
session=session, | ||
id_joke=1, | ||
text='Chuck Norris can slam a revolving door.', | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from app.database.models import Joke | ||
from app.internal import jokes | ||
|
||
|
||
def get_jokes_amount(session): | ||
return session.query(Joke).count() | ||
|
||
|
||
def test_get_a_joke(session, joke): | ||
assert jokes.get_a_joke(session).text == joke.text | ||
|
||
|
||
def test_jokes_not_load_twice_to_db(session): | ||
jokes.get_a_joke(session) | ||
first_load_amount = get_jokes_amount(session) | ||
jokes.get_a_joke(session) | ||
assert first_load_amount == get_jokes_amount(session) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def test_joke(client, session): | ||
resp = client.get('/joke') | ||
assert resp.ok | ||
assert resp.json |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.