Disable webhook for testlocation, add test to seed

This commit is contained in:
midgard 2019-10-01 20:57:23 +02:00 committed by Midgard
parent 7c88e8270f
commit f41817a5dd
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 46 additions and 11 deletions

View file

@ -0,0 +1,24 @@
from app import db
from models import Location, Product
STUFFS = [
("Broodje zever", 540),
("Broodje aap", 0),
("Broodje goud", 500000),
]
def add() -> None:
testlocation = Location()
testlocation.configure(
"Testlocation",
"Please ignore!",
"0469 69 69 69",
"http://localhost:8000/",
)
db.session.add(testlocation)
for stuff in STUFFS:
entry = Product()
entry.configure(testlocation, *stuff)
db.session.add(entry)

View file

@ -3,10 +3,12 @@ import add_fitchen
import add_oceans_garden
import add_primadonna
import add_simpizza
import add_testlocation
from app import db, create_app
entry_sets = {
"Admins": add_admins.add,
"Testlocation": add_testlocation.add,
"Ocean's Garden": add_oceans_garden.add,
"SimPizza": add_simpizza.add,
"Primadonna": add_primadonna.add,

View file

@ -1,29 +1,38 @@
import json
import typing
from datetime import datetime
from threading import Thread
import requests
from flask import current_app as app
from flask import url_for
from models.order import Order
def post_order_to_webhook(order_item) -> None:
message = ""
def webhook_text(order_item: Order) -> typing.Optional[str]:
if "Testlocation" in order_item.location.name:
return None
if order_item.courrier is not None:
message = "<!channel|@channel> {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format(
return "<!channel|@channel> {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format(
url_for("order_bp.order", id=order_item.id, _external=True),
order_item.location.name,
remaining_minutes(order_item.stoptime),
order_item.courrier.username.title(),
)
else:
message = "<!channel|@channel> New order for {}. Deadline in {} minutes. <{}|Open here.>".format(
order_item.location.name,
remaining_minutes(order_item.stoptime),
url_for("order_bp.order", id=order_item.id, _external=True),
)
webhookthread = WebhookSenderThread(message, app.config["SLACK_WEBHOOK"])
webhookthread.start()
return "<!channel|@channel> New order for {}. Deadline in {} minutes. <{}|Open here.>".format(
order_item.location.name,
remaining_minutes(order_item.stoptime),
url_for("order_bp.order", id=order_item.id, _external=True),
)
def post_order_to_webhook(order_item: Order) -> None:
message = webhook_text(order_item)
if message:
webhookthread = WebhookSenderThread(message, app.config["SLACK_WEBHOOK"])
webhookthread.start()
class WebhookSenderThread(Thread):