Exemplo n.º 1
0
    def test_make_a_person_with_a_fav_drink(self):
        expected_name, expected_drink = "Brad", Drink("milkshake")
        expected_person = Person(expected_name, expected_drink)

        actual_person = Person("brad", Drink("milkshake"))

        self.assertEqual(expected_person, actual_person)
Exemplo n.º 2
0
    def test_change_fav_drink_for_person(self):
        expected_person = Person("Meatloaf", Drink("Orange Juice"))

        actual_person = Person("Meatloaf", Drink("Hot chocolate"))
        actual_person.favourite_drink = Drink("Orange juice")

        self.assertEqual(expected_person, actual_person)
Exemplo n.º 3
0
    def test_people_get_names(self):
        expected_names = ["Bob", "Wendy"]

        people = People()
        people.add_person(Person("Bob"))
        people.add_person(Person("Wendy"))

        self.assertEqual(people.get_names(), expected_names)
Exemplo n.º 4
0
 def get_person(person_id):
     person = Person("")
     query = "SELECT person_name, drink_name FROM people JOIN drinks ON favourite_drink_id = drink_id WHERE person_id=%s"
     try:
         results = DbManager.execute_select(query, (person_id))
         person = Person(results[0], Drink(results[1]))
     except Exception as e:
         print(e)
     return person
Exemplo n.º 5
0
    def test_add_multiple_people(self):
        expected_people = People()
        expected_people.all_people = {
            "Bob": Person("Bob"),
            "Wendy": Person("Wendy")
        }

        actual_people = People()
        actual_people.add_people([Person("Bob"), Person("Wendy")])

        self.assertEqual(expected_people, actual_people)
Exemplo n.º 6
0
 def get_people_from_file(self):
     people = People()
     rows = FileManager.read_file(self)
     for row in rows:
         new_row = [x.strip() for x in row.split(',')]
         people.add_person(Person(new_row[0], Drink(new_row[1])))
     return people
Exemplo n.º 7
0
Arquivo: brIW1.py Projeto: krulys/BrIW
    def take_list_input(list_to_update, update_preferences=False):
        updated = False
        while True:
            item = input().strip().capitalize()
            if item == "":
                break

            if len(item) > max_table_width - 6:
                print(
                    f"Item not added - cannot be more than {max_table_width-6} characters. Try again."
                )
            else:
                if update_preferences:
                    try:
                        list_to_update.add_person(Person(item, Drink("")))
                    except Exception as e:
                        print(str(e))
                        print("\nHit ENTER to return to menu")
                        break
                else:
                    list_to_update.add_drink(Drink(item))
                updated = True
                os.system("clear")
                print(
                    f"{item} successfully added. Enter another or hit ENTER to return to menu."
                )
        os.system("clear")
        return list_to_update, updated
Exemplo n.º 8
0
    def test_make_a_person_with_no_fav_drink(self):
        expected_name, expected_drink = "Janet", Drink("")

        person = Person("janet")

        self.assertEqual(expected_name, person.name)
        self.assertEqual(expected_drink, person.favourite_drink)
Exemplo n.º 9
0
    def test_make_empty_person(self):
        # Arrange
        expected_name, expected_drink = "", Drink("")

        # Act
        person = Person("")

        # Assert
        self.assertEqual(expected_name, person.name)
        self.assertEqual(expected_drink, person.favourite_drink)
Exemplo n.º 10
0
 def get_all_people():
     people = []
     try:
         results = DbManager.execute_select(
             "SELECT person_name, drink_name FROM people LEFT JOIN drinks ON people.favourite_drink_id=drinks.drink_id"
         )
         for row in results:
             # print(row)
             people.append(Person(row[0], Drink(row[1])))
     except Exception as e:
         # TODO: improve this sad message
         print(
             "Something went wrong getting all people from the database...")
         print(e)
     return people
Exemplo n.º 11
0
    def get_people_from_db(self, drinks):
        people = People()
        try:
            results = FileManager.execute_query(
                self,
                "SELECT person_name, drink_name FROM people LEFT JOIN drinks ON people.favourite_drink_id=drinks.drink_id"
            )
        except Exception as e:
            # TODO: improve this sad message
            print("Something went wrong...")
            print(e)
        for row in results:
            print(row)
            people.add_person(Person(row[0], drinks.get_drink(row[1])))

        return people
Exemplo n.º 12
0
    def test_make_a_person_with_whitespace_lower_name(self):
        expected_name = "Janet"

        person = Person("      janet     ")
        self.assertEqual(expected_name, person.name)
Exemplo n.º 13
0
 def test_make_a_person_with_a_str_drink(self):
     with self.assertRaises(TypeError):
         Person("Rocky", "Jam")
Exemplo n.º 14
0
 def test_make_a_person_without_args(self):
     with self.assertRaises(Exception):
         Person()