示例#1
0
 def setUpClass(self):
     self.red_bag = Lootbag('red')
     self.Amy = Kid('Amy', 1)
     self.Bruce = Kid('Bruce', 0)
     self.red_bag.kids.add(self.Amy)
     self.red_bag.kids.add(self.Bruce)
     self.Amy.add_toy('bike')
     self.Amy.add_toy('ball')
     self.Amy.add_toy('calculator')
示例#2
0
class TestBagOLoot(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.bag = Lootbag()

    def test_can_list_toys_from_bag_for_child(self):
        toy = 'ball'
        jake_toys = self.bag.list_toys_for_child('Jake')

        self.assertIn(toy, jake_toys)

    def test_add_toy_to_bag(self):
        bag = Lootbag()
        toy = 'ball'
        self.assertEqual(bag.add_toy_to_bag(toy, 'Jake'), 'Toy added to bag')
示例#3
0
 def test_0_setup_class(self):
     self.lootbag = Lootbag()
示例#4
0
class lootTest(unittest.TestCase):
    @classmethod
    def test_0_setup_class(self):
        self.lootbag = Lootbag()

    def test_1_list_children_bag(self):
        self.assertEqual(set(), self.lootbag.list_children())

    def test_2_add_toy(self):
        self.lootbag.add_toy("ball", "matt")
        self.assertEqual("matt is receiving: ['ball']",
                         self.lootbag.list_childs_loot("matt"))

    def test_3_list_children(self):
        self.assertEqual(set(["matt"]), self.lootbag.list_children())

    def test_4_list_null_childs_loot(self):
        self.assertEqual(None, self.lootbag.list_childs_loot("lucy"))

    def test_5_remove_child_toy(self):
        self.lootbag.delete_toy("matt", "ball")
        self.assertEqual(set(["matt"]), self.lootbag.list_children())

    def test_6_remove_all_toys(self):
        self.lootbag.add_toy("ball", "matt")
        self.lootbag.add_toy("legos", "matt")
        self.lootbag.delete_toy("matt", "all")
        self.assertEqual(None, self.lootbag.list_childs_loot("matt"))
示例#5
0
 def setUpClass(self):
     self.lootbag = Lootbag('../bag_o_loot.db')
示例#6
0
class Testing(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.lootbag = Lootbag('../bag_o_loot.db')

# ==================================================================

# 1. test if items can be added to bag, and assigned to a child.

    def test01_add_toy(self):
        # function returns same ID that is passed in
        self.assertEqual(self.lootbag.add("Hotwheels", 1), 1)
        # database table will have toyID of 1
        self.assertEqual(self.lootbag.get_toyID("Hotwheels"), 1)
        # database table will return childID of 1 when toy name passed in
        self.assertEqual(self.lootbag.ls(1, True), "Hotwheels")

# ==================================================================

# 2. Items can be removed from bag, per child.
# Removing a toy from the bag should not be allowed. A child's name must be specified.

    def test02_remove_toy(self):
        # database has a toy with the name Hotwheels, and its ID is 1
        self.assertEqual(self.lootbag.get_toyID("Hotwheels"), 1)
        # database has a child "Brendan" with an ID of 1
        self.assertEqual(self.lootbag.get_childID("Brendan"), 1)
        # removing a toy without child name specified will throw error
        self.assertEqual(self.lootbag.remove(-1, 1), "No child specified")
        # removing the toy results in database response of toyID = None
        self.lootbag.remove(1)
        self.assertEqual(self.lootbag.get_toyID("Hotwheels"), None)

# 3. Must be able to list all children who are getting a toy.
# 4. Must be able to list all toys for a given child's name.

    def test03_child_list(self):
        # Three children receive are added in this example
        self.lootbag.add("Rocket", 1)
        self.lootbag.add("Robot", 2)
        self.lootbag.add("Plane", 5)
        # list function will fail to execute if child arg is not specified
        self.assertEqual(self.lootbag.ls(None, False), "No child ID specified")
        # a list of three names is returned if listing all children (id = false for a list of multiple children) - note delivered status of TRUE is required
        self.lootbag.update_child_delivery_status(True, 1)
        self.lootbag.update_child_delivery_status(True, 2)
        self.lootbag.update_child_delivery_status(True, 5)
        self.assertEqual(self.lootbag.ls(False, False),
                         ["Brendan", "Zac", "Brad"])
        # a child's toys are displayed when child ID is explicitly provided
        self.assertEqual(self.lootbag.ls(1, False), "Rocket")


# 5. Must be able to set the delivered property of a child's toys -- which defaults to false-- to true.

    def test04_update_delivered(self):
        # add item for user with ID = 4
        self.lootbag.add("Skateboard", 4)
        # update user 4 delivered status yields
        self.lootbag.delivered(4)
        # childID 4 ("Richard") toy appears in list all method
        self.assertEqual(self.lootbag.ls(False, False),
                         ["Brendan", "Zac", "Richard", "Brad"])
 def setUpClass(cls):
     print('Setup class')
     cls.lootbag = Lootbag('../lootbag.db')
示例#8
0
 def setUpClass(self):
     self.bag = Lootbag()
示例#9
0
 def test_add_toy_to_bag(self):
     bag = Lootbag()
     toy = 'ball'
     self.assertEqual(bag.add_toy_to_bag(toy, 'Jake'), 'Toy added to bag')
示例#10
0
import sys
from lootbag import Lootbag
from kid import Kid

Yellow_Bag = Lootbag('yellow')
Candace = Kid('candace', 1)
Derek = Kid('derek', 0)
Yellow_Bag.kids.add(Candace)
Yellow_Bag.kids.add(Derek)
Candace.add_toy('crayons')

# Requirements
# 1. Add a toy: (3 args): the word "add", the name of the gift, the name of the child (lootbag.py add kite suzy)
# remove suzy kite
# list children currently receiving presents (using the ls command)
# list all toys for a specific child (ls suzy)
# mark all of a child's toys delivered (delivered suzy)

if len(sys.argv) > 1 and sys.argv[1] == "add":
    # add kite suzy
    # !This looks like it works, but it doesn't. Can't figure out why. It says the toy is added to the list, but printing the list shows that it isn't added. Unit testing shows that the toy DOES get added so IDFK.
    for k in Yellow_Bag.kids:
        if (sys.argv[3]).capitalize() == k.name:
            k.add_toy(sys.argv[2])
            k.toy_list()
elif len(sys.argv) > 1 and sys.argv[1] == "remove":
    # remove suzy kite
    # !Because the add command doesn't work, this one doesn't work. You can't remove a toy if it isn't in there in the first place.
    for k in Yellow_Bag.kids:
        if (sys.argv[2]) == k.name:
            k.remove_toy(sys.argv[3])
示例#11
0
 def setUpClass(self):
     print('Set up class')
     self.Loot = Lootbag()