-
Notifications
You must be signed in to change notification settings - Fork 52
add color to category #228
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
Changes from all commits
91eb35f
4eb3ca8
168c619
93e25ea
a91f350
758ef50
51ec154
c7c0b86
c3583c7
fdfeb8c
81a1a7e
fb76b71
a22b981
07a88aa
62cbf73
aaa1960
0096011
82abccb
35d7b46
134e4e9
c447e89
3fcbeb6
a6ecc5f
301b34e
5024f01
68d00d3
7b5de86
1d3ac9d
7dd98e9
df0f8b6
2a271bc
6d3f31e
2002615
ff9225f
489869e
6c89cd2
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,32 @@ | ||
|
||
|
||
body { | ||
color: #333; | ||
margin: auto; | ||
font: 1.2em / 1.2 Arial, Helvetica, sans-serif; | ||
} | ||
|
||
h1 { | ||
color: black; | ||
font-size: 150%; | ||
text-align: center; | ||
} | ||
|
||
form { | ||
text-align: center; | ||
} | ||
|
||
input { | ||
border-radius: 0.5em; | ||
color: plum; | ||
padding: 0.5em; | ||
} | ||
|
||
input[type="color"].custom { | ||
padding: 0; | ||
border: none; | ||
height: 1.875em; | ||
width: 9.375em; | ||
vertical-align: middle; | ||
border-radius: 0.5em; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block head %} | ||
{{ super() }} | ||
<link href="{{ url_for('static', path='/categories_style.css') }}" rel="stylesheet"> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous"> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="container mt-4"> | ||
<h1>It's time to make some decisions</h1> | ||
<h1> | ||
Here you can create your unique categories and choose your favorite color | ||
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. Add |
||
</h1> | ||
|
||
<form action="/categories" method="POST" required> | ||
<label for="category_name">Name your category:</label> | ||
<p><input type="text" id ="name" name="name"></p> | ||
<label for="category_color">Choose your favorite color:</label> | ||
<p><input type="color" class="custom" id ="color", name="color"></p> | ||
<p><button type="submit" class="btn btn-success" value="submit">Submit</button></p> | ||
</form> | ||
</div> | ||
{% if message %} | ||
<div class="container mt-4"> | ||
<p>{{ message }}</p> | ||
</div> | ||
{% endif %} | ||
|
||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import pytest | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.testing import mock | ||
|
||
from starlette import status | ||
from starlette.datastructures import ImmutableMultiDict | ||
|
||
|
@@ -11,7 +12,8 @@ | |
|
||
|
||
class TestCategories: | ||
CATEGORY_ALREADY_EXISTS_MSG = "category is already exists for" | ||
CATEGORY_ALREADY_EXISTS_MSG = b"Category already exists" | ||
CREATE_CATEGORY = b"You have created" | ||
UNALLOWED_PARAMS = "contains unallowed params" | ||
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. If you add |
||
BAD_COLOR_FORMAT = "if not from expected format" | ||
|
||
|
@@ -20,28 +22,30 @@ def test_get_categories_logic_succeeded(session, user, category): | |
assert get_user_categories(session, category.user_id) == [category] | ||
|
||
@staticmethod | ||
def test_creating_new_category(client, user): | ||
response = client.post("/categories/", | ||
json={"user_id": user.id, "name": "Foo", | ||
"color": "eecc11"}) | ||
def test_creating_new_category(categories_test_client, session, user): | ||
CORRECT_ADD_CATEGORY_DATA = {"user_id": user.id, | ||
"name": "Foo", | ||
"color": "eecc11"} | ||
response = categories_test_client.post("/categories/", | ||
data=CORRECT_ADD_CATEGORY_DATA) | ||
assert response.ok | ||
assert {("user_id", user.id), ("name", "Foo"), | ||
("color", "eecc11")}.issubset( | ||
set(response.json()['category'].items())) | ||
assert TestCategories.CREATE_CATEGORY in response.content | ||
|
||
@staticmethod | ||
def test_creating_not_unique_category_failed(client, sender, category): | ||
response = client.post("/categories/", json={"user_id": sender.id, | ||
"name": "Guitar Lesson", | ||
"color": "121212"}) | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
assert TestCategories.CATEGORY_ALREADY_EXISTS_MSG in \ | ||
response.json()["detail"] | ||
def test_create_not_unique_category_failed(categories_test_client, sender, | ||
category): | ||
CATEGORY_ALREADY_EXISTS = {"name": "Guitar Lesson", | ||
"color": "121212", | ||
"user_id": sender.id} | ||
response = categories_test_client.post("/categories/", | ||
data=CATEGORY_ALREADY_EXISTS) | ||
assert response.ok | ||
assert TestCategories.CATEGORY_ALREADY_EXISTS_MSG in response.content | ||
|
||
@staticmethod | ||
def test_creating_new_category_bad_color_format(client, user): | ||
response = client.post("/categories/", | ||
json={"user_id": user.id, "name": "Foo", | ||
data={"user_id": user.id, "name": "Foo", | ||
"color": "bad format"}) | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
assert TestCategories.BAD_COLOR_FORMAT in response.json()["detail"] | ||
|
@@ -62,7 +66,8 @@ def test_update_event_with_category(today_event, category): | |
|
||
@staticmethod | ||
def test_get_user_categories(client, category): | ||
response = client.get(f"/categories/?user_id={category.user_id}" | ||
response = client.get(f"/categories/user/?" | ||
f"user_id={category.user_id}" | ||
f"&name={category.name}&color={category.color}") | ||
assert response.ok | ||
assert len(response.json()) == 1 | ||
|
@@ -72,7 +77,8 @@ def test_get_user_categories(client, category): | |
|
||
@staticmethod | ||
def test_get_category_by_name(client, sender, category): | ||
response = client.get(f"/categories/?user_id={category.user_id}" | ||
response = client.get(f"/categories/user/?" | ||
f"user_id={category.user_id}" | ||
f"&name={category.name}") | ||
assert response.ok | ||
assert len(response.json()) == 1 | ||
|
@@ -82,7 +88,8 @@ def test_get_category_by_name(client, sender, category): | |
|
||
@staticmethod | ||
def test_get_category_by_color(client, sender, category): | ||
response = client.get(f"/categories/?user_id={category.user_id}&" | ||
response = client.get(f"/categories/user/?" | ||
f"user_id={category.user_id}&" | ||
f"color={category.color}") | ||
assert response.ok | ||
assert len(response.json()) == 1 | ||
|
@@ -92,10 +99,15 @@ def test_get_category_by_color(client, sender, category): | |
|
||
@staticmethod | ||
def test_get_category_bad_request(client): | ||
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. Why did you remove this one? |
||
response = client.get("/categories/") | ||
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. This should be probably |
||
response = client.get("/categories/user") | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
assert TestCategories.UNALLOWED_PARAMS in response.json()["detail"] | ||
|
||
@staticmethod | ||
def test_get_category_ok_request(client): | ||
response = client.get("/categories") | ||
assert response.ok | ||
|
||
@staticmethod | ||
def test_repr(category): | ||
assert category.__repr__() == \ | ||
|
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.
Add indentation please