This file contains 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
#!/usr/bin/env bash | |
set -e | |
REPO_URL="https://github.com/klement97/venue" | |
clone_repo() { | |
git clone $REPO_URL --depth 1 ~/venue_management | |
} | |
setup() { |
This file contains 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
import calendar | |
import datetime | |
from math import ceil | |
def get_week_number(date: datetime.date) -> int: | |
""" | |
Credits goes to:https://stackoverflow.com/a/66176965/9309611 | |
""" | |
return (date.day - 1 + (date.weekday() - date.day + 1) % 7) // 7 + 1 |
This file contains 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
def create_order() -> Order: | |
order = baker.make('order.Order') | |
baker.make('order.PizzaOrder', order=order) | |
order.save() | |
return order |
This file contains 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
@pytest.mark.django_db | |
def test_order_save(monkeypatch): | |
def mock_post(*args, **kwargs): | |
return MockResponse() | |
monkeypatch.setattr(requests, 'post', mock_post) | |
order = create_order() | |
assert order.price is not None |
This file contains 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
class MockResponse: | |
# mock json() method always returns a specific testing dictionary | |
@staticmethod | |
def json(): | |
return {"mock_key": "mock_response"} |
This file contains 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
@pytest.mark.django_db | |
def test_order_save(monkeypatch): | |
def mock_post(*args, **kwargs): | |
return None | |
monkeypatch.setattr(requests, 'post', mock_post) | |
order = create_order() | |
assert order.price is not None |
This file contains 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
def print_receipt(self): | |
requests.post( | |
url=settings.RECEIPT_MICROSERVICE, | |
data=prepare_receipt_data(order=self) | |
) | |
def save(self, *args, **kwargs): | |
self.price = self.total_price | |
self.print_receipt() | |
super().save(*args, **kwargs) |
This file contains 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
@pytest.mark.django_db | |
@pytest.mark.parametrize('number_of_toppings', list(range(0, 10))) | |
def test_pizza_price(number_of_toppings): | |
# Preparation phase | |
pizza = create_pizza(number_of_toppings=number_of_toppings) | |
# Calculating results | |
actual_price = pizza.total_price | |
expected_price = Decimal(sum([t.price for t in pizza.toppings.all()])) |
This file contains 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
@pytest.mark.django_db | |
def test_pizza_price_with_toppings(): | |
# Preparation phase | |
pizza = create_pizza(number_of_toppings=2) | |
# Calculating results | |
actual_price = pizza.total_price | |
expected_price = sum([t.price for t in pizza.toppings.all()]) | |
# Assertion |
This file contains 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
def create_pizza(number_of_toppings: int, **kwargs) -> Pizza: | |
pizza = baker.make('order.Pizza', **kwargs) | |
for _ in range(number_of_toppings): | |
pizza.toppings.add(baker.make('order.Topping')) | |
return pizza |
NewerOlder