Ejemplo n.º 1
0
def new(animal_id):
    animal = animal_repository.select(animal_id)
    dh = DateHelper()
    current_time = dh.print_datetime_local(datetime.datetime.now())
    return render_template(
        "records/new.html",
        title="New Record",
        animal=animal,
        current_time=current_time,
    )
Ejemplo n.º 2
0
 def total(self, duration):
     dh = DateHelper()
     times = dh.list_delta(duration)
     string = ""
     if times[0] > 0:
         string += f"{times[0]} days"
     if times[1] > 0:
         if string != "":
             string += ", "
         string += f"{times[1]} hrs"
     if string != "":
         string += ", "
     string += f"{times[2]} mins"
     return string
Ejemplo n.º 3
0
 def setUp(self):
     self.dh = DateHelper()
     self.vet = Vet("Mark", "Bridges", 3)
     self.address = Address("9", "Big Road", "Vatican City", "PO1 1PE")
     self.owner = Owner("Kevin", "Stevens", self.address, "015825536874",
                        "*****@*****.**")
     self.animal = Animal(
         "Fluff",
         self.dh.make_date("2018-01-04"),
         "Dog",
         "Greyhound",
         self.owner,
         self.vet,
         self.dh.make_datetime("2020-08-09 13:52:01"),
     )
     self.now = self.dh.make_datetime("2020-08-10 12:20:52")
Ejemplo n.º 4
0
 def where(self, treatment):
     dh = DateHelper()
     now = dh.now()
     if treatment is None:
         self.checked_in = False
         self.location = ""
         return
     elif now < treatment.start + treatment.duration:
         self.checked_in = True
         self.location = "treatment"
         return
     elif now < treatment.start + treatment.duration + treatment.recovery:
         self.checked_in = True
         self.location = "recovery"
         return
     else:
         self.checked_in = False
         self.location = ""
         return
Ejemplo n.º 5
0
class TestDateHelper(unittest.TestCase):
    def setUp(self):
        self.dh = DateHelper()
        self.date_str = "1999-08-01"
        self.datetime_str = "1998-05-02 14:08:00"
        self.date_obj = self.dh.make_date(self.date_str)
        self.datetime_obj = self.dh.make_datetime(self.datetime_str)

    def test_print_date(self):
        expected = "01 Aug 1999"
        actual = self.dh.print_date(self.date_obj)
        self.assertEqual(expected, actual)

    def test_print_datetime(self):
        expected = "14:08:00 02 May 1998"
        actual = self.dh.print_datetime(self.datetime_obj)
        self.assertEqual(expected, actual)

    def test_print_nice(self):
        expected = "2:08pm, 2 May 1998"
        actual = self.dh.print_nice(self.datetime_obj)
        self.assertEqual(expected, actual)
Ejemplo n.º 6
0
from flask import Flask, Blueprint, render_template, request, redirect
import datetime

from models.treatment import Treatment
from models.date_helper import DateHelper

import repositories.treatment_repository as treatment_repository
import repositories.owner_repository as owner_repository
import repositories.animal_repository as animal_repository

dh = DateHelper()
treatment_blueprint = Blueprint("treatments", __name__)

# don't need index


@treatment_blueprint.route("/treatments/<id>")
def show(id):
    treatment = treatment_repository.select(id)
    return render_template("treatments/show.html",
                           title="Treatment",
                           treatment=treatment)


@treatment_blueprint.route("/treatments/new/<animal_id>")
def new(animal_id):
    animal = animal_repository.select(animal_id)
    return render_template("treatments/new.html",
                           title="New Treatment",
                           animal=animal)
Ejemplo n.º 7
0
 def print_date(self, which):
     dh = DateHelper()
     return getattr(dh, which)(self.date)
Ejemplo n.º 8
0
 def print_recovery(self):
     dh = DateHelper()
     recovery_time = self.start + self.duration + self.recovery
     return dh.print_nice(recovery_time)
Ejemplo n.º 9
0
 def print_duration(self):
     dh = DateHelper()
     treatment_time = self.start + self.duration
     return dh.print_nice(treatment_time)
Ejemplo n.º 10
0
 def print_start(self):
     dh = DateHelper()
     start_time = dh.print_nice(self.start)
     return start_time
Ejemplo n.º 11
0
 def start_treatment(self, time=None):
     if time is None:
         dh = DateHelper()
         self.start = dh.now()
     else:
         self.start = time
Ejemplo n.º 12
0
 def print_registered(self, which):
     dh = DateHelper()
     return getattr(dh, which)(self.date_registered)
Ejemplo n.º 13
0
class TestAnimal(unittest.TestCase):
    def setUp(self):
        self.dh = DateHelper()
        self.vet = Vet("Mark", "Bridges", 3)
        self.address = Address("9", "Big Road", "Vatican City", "PO1 1PE")
        self.owner = Owner("Kevin", "Stevens", self.address, "015825536874",
                           "*****@*****.**")
        self.animal = Animal(
            "Fluff",
            self.dh.make_date("2018-01-04"),
            "Dog",
            "Greyhound",
            self.owner,
            self.vet,
            self.dh.make_datetime("2020-08-09 13:52:01"),
        )
        self.now = self.dh.make_datetime("2020-08-10 12:20:52")

    def test_animal_has_name(self):
        expected = "Fluff"
        actual = self.animal.name
        self.assertEqual(expected, actual)

    def test_animal_has_dob(self):
        expected = "04 Jan 2018"
        actual = self.dh.print_date(self.animal.dob)
        self.assertEqual(expected, actual)

    def test_animal_species(self):
        expected = "Dog"
        actual = self.animal.species
        self.assertEqual(expected, actual)

    def test_animal_breed(self):
        expected = "Greyhound"
        actual = self.animal.breed
        self.assertEqual(expected, actual)

    def test_animal_has_owner(self):
        expected = "*****@*****.**"
        actual = self.animal.owner.email
        self.assertEqual(expected, actual)

    def test_animal_has_vet(self):
        expected = "Mark"
        actual = self.animal.vet.first_name
        self.assertEqual(expected, actual)

    def test_registered_date(self):
        expected = "13:52:01 09 Aug 2020"
        actual = self.dh.print_datetime(self.animal.date_registered)
        self.assertEqual(expected, actual)

    def test_checked_in_default(self):
        expected = False
        actual = self.animal.checked_in
        self.assertEqual(expected, actual)

    def test_animal_has_None_id(self):
        actual = self.animal.id
        self.assertIsNone(actual)

    def test_animal_can_get_id(self):
        self.animal.id = 7816
        expected = 7816
        actual = self.animal.id
        self.assertEqual(expected, actual)

    def test_animal_has_num_records(self):
        expected = 0
        actual = self.animal.records
        self.assertEqual(expected, actual)

    def test_set_num_records(self):
        self.animal.set_records(5)
        expected = 5
        actual = self.animal.records
        self.assertEqual(expected, actual)

    def test_set_num_records_different_number(self):
        self.animal.set_records(10)
        expected = 10
        actual = self.animal.records
        self.assertEqual(expected, actual)

    def test_printable_age(self):
        expected = "2 years old"
        actual = self.animal.get_age(self.now)
        self.assertEqual(expected, actual)

    def test_printed_dob(self):
        expected = "04 Jan 2018"
        actual = self.animal.print_dob("print_date")
        self.assertEqual(expected, actual)

    def test_nice_printed_date_registered(self):
        expected = "1:52pm, 9 Aug 2020"
        actual = self.animal.print_registered("print_nice")
        self.assertEqual(expected, actual)
Ejemplo n.º 14
0
 def setUp(self):
     self.dh = DateHelper()
     self.date_str = "1999-08-01"
     self.datetime_str = "1998-05-02 14:08:00"
     self.date_obj = self.dh.make_date(self.date_str)
     self.datetime_obj = self.dh.make_datetime(self.datetime_str)