Skip to content
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

Creating orders.html, presenting orders history #95

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

OfirMatasas
Copy link
Collaborator

@OfirMatasas OfirMatasas commented Apr 28, 2022

A page on Hotails, where the user can watch the history of all of his
orders, cancel the orders which havn't started yet, and approve orders
as a daycare.

Signed-off-by: Ofir Matasas [email protected]

Desired Outcome

A page on Hotails, where the user can watch the history of all of his orders, cancel the orders which haven't started yet, and approve orders as a daycare.

Implemented Changes

  • Create orders.html + orders.css files
  • Added logic in getting to the orders page and presenting orders information (base_template navbar, main.urls, orders.views)
  • added 3 methods in Orders:
    1. Check if the order is approvable
    2. Check if the order is cancelable
    3. Get the status of the order

Connected Issue/Story

Closes #94

Definition of Done

All the options mentioned in the desired outcome are available to the users.

Picture of the orders page

Untitled

Copy link
Collaborator

@ErezCohenn ErezCohenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @OfirMatasas!
take a look at the comment I left.

main/views.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
orders/templates/orders/orders.html Show resolved Hide resolved
main/tests.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
@OfirMatasas OfirMatasas requested a review from ErezCohenn May 4, 2022 07:22
@OfirMatasas OfirMatasas force-pushed the orders-page branch 2 times, most recently from 7bb5e24 to 5264358 Compare May 4, 2022 08:20
Copy link
Collaborator

@Yuval-Vino Yuval-Vino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job ofir! orders HTML looks good , I left 1 comment tell me what you think

main/tests.py Show resolved Hide resolved
tamirmatok added a commit to tamirmatok/Hotails that referenced this pull request May 4, 2022
Capacity dates check for show only available daycares in dates range.
"get_capacity_of_daycare_in_dates_range" function took from redhat-beyond#95 .
waiting for approval.

Signed-off-by: tamirmatok <[email protected]>
tamirmatok added a commit to tamirmatok/Hotails that referenced this pull request May 4, 2022
Capacity dates check for show only available daycares in dates range.
"get_capacity_of_daycare_in_dates_range" function took from redhat-beyond#95 .
waiting for approval.

Signed-off-by: tamirmatok <[email protected]>
tamirmatok added a commit to tamirmatok/Hotails that referenced this pull request May 4, 2022
Capacity dates check for show only available daycares in dates range.
"get_capacity_of_daycare_in_dates_range" function took from redhat-beyond#95 .
waiting for approval.

Signed-off-by: tamirmatok <[email protected]>
Copy link
Collaborator

@tamirmatok tamirmatok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @OfirMatasas !!
I left some comments let me know what u think.

main/tests.py Outdated Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
@OfirMatasas OfirMatasas force-pushed the orders-page branch 2 times, most recently from 322dfc1 to 453b3a4 Compare May 6, 2022 10:56
@OfirMatasas OfirMatasas requested a review from Yuval-Vino May 6, 2022 10:56
main/tests.py Outdated Show resolved Hide resolved
main/tests.py Outdated Show resolved Hide resolved
ErezCohenn pushed a commit that referenced this pull request May 8, 2022
Capacity dates check for show only available daycares in dates range.
"get_capacity_of_daycare_in_dates_range" function took from #95 .
waiting for approval.

Signed-off-by: tamirmatok <[email protected]>
@OfirMatasas OfirMatasas requested a review from Yuval-Vino May 10, 2022 06:21
main/views.py Outdated Show resolved Hide resolved
main/tests.py Outdated Show resolved Hide resolved
main/tests.py Outdated Show resolved Hide resolved
main/tests.py Show resolved Hide resolved
main/tests.py Show resolved Hide resolved
main/tests.py Show resolved Hide resolved
orders/models.py Outdated Show resolved Hide resolved
create_order.status = new_status
assert create_order.get_order_status() == expected_result

def test_get_daycare_capacity_in_dates_range(self, create_order):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not how you should test this function. it has a lot of logic; you need to test different cases and see that you get the capacity you expect in each case

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that checking the current capacity of a daycare before and after approving an order will check if the method is working correctly.
Also, some of the other tests are testing this method too (like "test_order_is_approvable_according_to_daycare_capacity").

Do you have any example for a case that I should test for this method? Or another way for testing it?

Copy link
Contributor

@Omeramsc Omeramsc May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first of all - test names should follow the method they're testing (but not only the method name).
as an example:
if the method name is: check_capacity_of_daycare
possible test names are:
test_check_capacity_of_daycare
test_check_capacity_of_daycare_raise_value_error_when_something_happends
test_check_capacity_of_daycare_reduced_after_an_order
etc.

otherwise, it is very confusing to understand what is testing what.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

second:
the test above test if order can be approved, according to its overall calculated capacity
this test should be a specific unit-test for get_capacity_of_daycare_in_dates_range it doesn't test the overall logic your app will go through, but it is testing this method specifically, and should pass even if in the future you'll decide to change the way the process works.

this method has a lot of cases. think of each if statement as at least two possible test-cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OfirMatasas are you going to address these?


return capacity_per_day

def are_order_dates_available(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made "test_order_is_approvable_according_to_daycare_capacity" for this method. Should I test it in another way?

Copy link
Contributor

@Omeramsc Omeramsc May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it testing this function alone?
if it does, it deserves a name change :)

Otherwise, we need a test to test this only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing this function does is check if specific dates are available due to capacity. the test you wrote deal with the whole process your application does. What we need for this function is a unit test, as it tests this unit specifically, without dependencies from other processes.

ErezCohenn pushed a commit that referenced this pull request May 12, 2022
Capacity dates check for show only available daycares in dates range.
"get_capacity_of_daycare_in_dates_range" function took from #95 .
waiting for approval.

Signed-off-by: tamirmatok <[email protected]>
ErezCohenn pushed a commit that referenced this pull request May 12, 2022
Capacity dates check for show only available daycares in dates range.
"get_capacity_of_daycare_in_dates_range" function took from #95 .
waiting for approval.

Signed-off-by: tamirmatok <[email protected]>
@OfirMatasas OfirMatasas requested a review from Omeramsc May 16, 2022 20:02
tamirmatok added a commit to tamirmatok/Hotails that referenced this pull request May 18, 2022
Capacity dates check for show only available daycares in dates range.
"get_capacity_of_daycare_in_dates_range" function took from redhat-beyond#95 .
waiting for approval.

Signed-off-by: tamirmatok <[email protected]>
tamirmatok added a commit to tamirmatok/Hotails that referenced this pull request May 18, 2022
Capacity dates check for show only available daycares in dates range.
"get_capacity_of_daycare_in_dates_range" function took from redhat-beyond#95 .
waiting for approval.

Signed-off-by: tamirmatok <[email protected]>
tamirmatok added a commit to tamirmatok/Hotails that referenced this pull request May 18, 2022
Capacity dates check for show only available daycares in dates range.
"get_capacity_of_daycare_in_dates_range" function took from redhat-beyond#95 .
waiting for approval.

Signed-off-by: tamirmatok <[email protected]>
A page on Hotails, where the user can watch the history of all of his
orders, cancel the orders which havn't started yet, and approve orders
as a daycare.

Signed-off-by: Ofir Matasas <[email protected]>
Copy link
Contributor

@ormergi ormergi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ofir, please see my inline comments

Comment on lines +76 to +85
def get_order_status(self):
if self.status == StatusOptions.Pending:
return "Pending"
elif self.status == StatusOptions.Approved:
return "Approved"
elif self.status == StatusOptions.Canceled:
return "Canceled"
elif self.status == StatusOptions.OnGoing:
return "Ongoing"
return "Finished"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified to

statusOptionsNameIdx=1
reuturn self.status[statusOptionsNameIdx]

WDYT?

return "Finished"

@staticmethod
def get_capacity_of_daycare_in_dates_range(daycare_id: DayCare, start_datetime: datetime, end_datetime: datetime):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is capacity?

start_date = datetime.date(year=start_datetime.year, month=start_datetime.month, day=start_datetime.day)
end_date = datetime.date(year=end_datetime.year, month=end_datetime.month, day=end_datetime.day)
relevant_orders = Order.objects.filter(daycare_id=daycare_id,
status__in=['A', 'O'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use full names?

create_order.status = new_status
assert create_order.get_order_status() == expected_result

def test_get_daycare_capacity_in_dates_range(self, create_order):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OfirMatasas are you going to address these?

def orders(request):
if DogOwner.objects.filter(user=request.user).exists():
context = {
'orders': Order.objects.filter(dog_owner_id__user=request.user),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary to fillter by authenticated user, is it possible to use request.user directly?

@Omeramsc
Copy link
Contributor

There are conflicts and a bunch of unresolved comments. Sorry, it won't be ready for the demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create orders page, filled with user's orders history
6 participants