diff --git a/app.py b/app.py index b8b17ea..c38cc6c 100644 --- a/app.py +++ b/app.py @@ -31,6 +31,10 @@ def app_page(name): abort(404) if app.name != name: return redirect(f"/{app.name}") + + site = Site(app.name) + status = site.get_status() + app.update_status(status) return render_template("app.html", app=app, tasks=TASKS) @app.route("//deploy", methods=["POST"]) @@ -52,4 +56,4 @@ def app_deploy(name): return jsonify(status) if __name__ == "__main__": - app.run() + app.run(port=5050) diff --git a/db.py b/db.py index 533bfa4..450b75f 100644 --- a/db.py +++ b/db.py @@ -64,7 +64,7 @@ def _update(self, **kwargs): db.update("app", **kwargs, where="id=$id", vars={"id": self.id}) def update_score(self): - rows = db.where("task", app_id=self.id).list() + rows = db.where("task", app_id=self.id, status='pass').list() score = len(rows) self._update(score=score) diff --git a/tasks.py b/tasks.py index d0bc7b5..8357993 100644 --- a/tasks.py +++ b/tasks.py @@ -75,7 +75,8 @@ def login(self, email): def sync(self): try: - hamr.sync_app(self.name) + #hamr.sync_app(self.name) + pass except HamrError as e: return HamrResponse(ok=False, message=str(e)) @@ -167,6 +168,8 @@ def validate(self, site): except CheckFailed as e: return status.fail(str(e)) except Exception as e: + import traceback + traceback.print_exc() return status.error(str(e)) def do_validate(self, site): @@ -327,12 +330,26 @@ def do_validate(self, site): response = site.post("/book-ticket", data=data) response.raise_for_status() + + q = """SELECT * FROM booking ORDER BY id DESC LIMIT 1""" + result = site.query(q) + if not result: + raise CheckFailed("Could not find any bookings") + + row = result[0] + + + for k in "train_number ticket_class date passenger_name passenger_email".split(): + if k not in row: + raise CheckFailed(f"Missing {k!r} column in table booking") + q = """ SELECT - train_number, ticket_class, date, - from_station_code, to_station_code, - passenger_name, passenger_email - FROM booking + b.train_number, b.ticket_class, b.date, + b.passenger_name, b.passenger_email, + t.from_station_code, t.to_station_code + FROM booking b + JOIN train t ON b.train_number=t.number ORDER BY id DESC LIMIT 1 """ @@ -389,7 +406,7 @@ def __init__(self, bookings): self.passenger_email = "evaluator@example.com" def get_bookings_from_html(self, html): - soup = BeautifulSoup(html) + soup = BeautifulSoup(html, "lxml") booking_cards = soup.find_all("div", class_="card") for card in booking_cards: card_header = card.find("div", class_="card-header").get_text() diff --git a/tasks.yml b/tasks.yml index d291f28..f082f45 100644 --- a/tasks.yml +++ b/tasks.yml @@ -282,9 +282,6 @@ description: | and passenger details and books a ticket by adding an entry in the database table. - After booking a ticket, the number of available seats for that - train in the booked ticket class should be reduced by one. - File: `rajdhani/db.py`
Function: `book_ticket` checks: @@ -300,35 +297,6 @@ checks: date: "2022-12-01" ---- -name: email-conformation -title: Send an email to confirm the successful booking -description: | - Send an email to the passenger confirming the reservation. - You can use the SMTP credentials from `config.py` to do that. - - The booking argument is a dict with keys: `id`, `passenger_name`, - `passenger_email`, `train_number`, `train_name`, `ticket_class`, and `date`. - - Note: For testing locally, you can install the - [aiosmtpd](https://aiosmtpd.readthedocs.io/en/latest/) package with pip - and start an SMTP server on port 8025 with `python3 -m aiosmtpd -n`. - - File: `rajdhani/notifications.py`
- Function: `send_booking_confirmation` -checks: - - check_ticket_confirmation_email: - train: "12028" - ticket_class: "CC" - date: "2022-09-30" - passenger_name: "Eva Lu Ator" - passenger_email: "evaluator@example.com" - - check_ticket_confirmation_email: - train: "16227" - ticket_class: "FC" - date: "2022-09-28" - passenger_name: "Lem E Tweakit" - passenger_email: "lemetweakit@example.com" --- name: login-and-trips title: Enable login and show trips for the user diff --git a/templates/app.html b/templates/app.html index ad77f2c..b0dc1fa 100644 --- a/templates/app.html +++ b/templates/app.html @@ -34,7 +34,9 @@

{{app.name}}

Visit website +
{{app.score}} tasks completed | Current Task: {{ app.current_task }} | Last updated {{datestr(app.last_updated) }}
@@ -93,7 +95,7 @@
Checks

Change Log

- {% for entry in app.get_changelog() %} + {% for entry in app.get_changelog()[:10] %}
{{datestr(entry.timestamp)}} - {{entry.type}} - {{entry.message}}
{% endfor %}