|
| 1 | +"""Initialize objects from data models to generate in Database.""" |
| 2 | +from typing import Tuple |
| 3 | + |
| 4 | +from sqlalchemy_tutorial.part3_relationships.models import Comment, Post, User |
| 5 | + |
| 6 | + |
| 7 | +def create_user_objects() -> Tuple[User, User]: |
| 8 | + """ |
| 9 | + Set up an admin user to own a `Post`, and regular user to add comments. |
| 10 | +
|
| 11 | + :return: Tuple[User, User] |
| 12 | + """ |
| 13 | + admin_user = User( |
| 14 | + username="toddthebod", |
| 15 | + password="Password123lmao", |
| 16 | + |
| 17 | + first_name="Todd", |
| 18 | + last_name="Birchard", |
| 19 | + bio="I write tutorials on the internet.", |
| 20 | + avatar_url="https://storage.googleapis.com/hackersandslackers-cdn/authors/[email protected]", |
| 21 | + role="admin", |
| 22 | + ) |
| 23 | + regular_user = User( |
| 24 | + username="obnoxioustroll69", |
| 25 | + password="Password123rofl", |
| 26 | + |
| 27 | + first_name="Chad", |
| 28 | + last_name="Bowswick", |
| 29 | + bio="I leave hurtful comments on coding tutorials I find on the internet.", |
| 30 | + avatar_url="https://storage.googleapis.com/hackersandslackers-cdn/authors/[email protected]", |
| 31 | + ) |
| 32 | + return admin_user, regular_user |
| 33 | + |
| 34 | + |
| 35 | +def create_post_object(admin_user: User) -> Post: |
| 36 | + """ |
| 37 | + Set up post to add to database. |
| 38 | +
|
| 39 | + :param admin_user: User to serve as post author. |
| 40 | + :type admin_user: User |
| 41 | +
|
| 42 | + :return: Post |
| 43 | + """ |
| 44 | + return Post( |
| 45 | + author_id=admin_user.id, |
| 46 | + slug="fake-post-slug", |
| 47 | + title="Fake Post Title", |
| 48 | + status="published", |
| 49 | + summary="A fake post to have some fake comments.", |
| 50 | + feature_image="https://hackersandslackers-cdn.storage.googleapis.com/2021/01/[email protected]", |
| 51 | + body="Cheese slices monterey jack cauliflower cheese dolcelatte cheese and wine fromage frais rubber \ |
| 52 | + cheese gouda. Rubber cheese cheese and wine cheeseburger cheesy grin paneer paneer taleggio caerphilly. \ |
| 53 | + Edam mozzarella.", |
| 54 | + ) |
| 55 | + |
| 56 | + |
| 57 | +def create_comment_objects( |
| 58 | + regular_user: User, post: Post |
| 59 | +) -> Tuple[Comment, Comment, Comment]: |
| 60 | + """ |
| 61 | + Set up 3 comments to be added to published post. |
| 62 | +
|
| 63 | + :param regular_user: User to serve as comment author. |
| 64 | + :type regular_user: User |
| 65 | + :param post: Blog post to be created. |
| 66 | + :type post: Post |
| 67 | +
|
| 68 | + :return: Tuple[Comment, Comment, Comment] |
| 69 | + """ |
| 70 | + comment_1 = Comment( |
| 71 | + user_id=regular_user.id, |
| 72 | + post_id=post.id, |
| 73 | + body="This post about SQLAlchemy is awful. You didn't even bother to explain how to install Python, \ |
| 74 | + which is where I (and so many others) got stuck. Plus, your code doesn't even work!! \ |
| 75 | + I cloned your code and it keeps giving me `environment variable` errors... \ |
| 76 | + WTF are environment variables?!!?!?", |
| 77 | + upvotes=2, |
| 78 | + ) |
| 79 | + comment_2 = Comment( |
| 80 | + user_id=regular_user.id, |
| 81 | + post_id=post.id, |
| 82 | + body="By the way, you SUCK!!! I HATE you!!!! I have a project due tomorrow, how am I supposed to finish \ |
| 83 | + if you won't do my job for me, you selfish prick?!?!", |
| 84 | + upvotes=5, |
| 85 | + ) |
| 86 | + comment_3 = Comment( |
| 87 | + user_id=regular_user.id, |
| 88 | + post_id=post.id, |
| 89 | + body="YOU RUINED MY LIFE!!!!", |
| 90 | + upvotes=5, |
| 91 | + ) |
| 92 | + return comment_1, comment_2, comment_3 |
0 commit comments