示例#1
0
 def test_save_method(self):
     """
     The save() method should be able to update the parent order's 
     list of order_steps as well as that of the database
     """
     self.assertIsInstance(self.order_step, orderStep)
     self.order_step.save(self.db)
     length_of_db_order_step_keys = len(self.db.order_step_keys)
     length_of_order_steps = len(self.order.order_steps)
     self.assertIn(self.order_step.key, self.db.order_step_keys)
     self.assertEqual(self.order_step,
                      self.db.order_steps[self.order_step.key])
     self.assertIn(self.order_step.key, self.order.order_steps)
     # the order should exist in database
     invalid_data = utilities.replace_value_in_dict(self.order_step_data,
                                                    'order', 78)
     new_order_step = orderStep(**invalid_data)
     self.assertRaises(KeyError, new_order_step.save, self.db)
     # database parameter should be of type Database
     self.assertRaises(TypeError, self.order_step.save,
                       'string instead of Database object')
     # calling save more than once does not increase size of self.db.order_step_keys
     self.order_step.save(self.db)
     self.assertEqual(len(self.db.order_step_keys),
                      length_of_db_order_step_keys)
     # calling save more than once does not increase size of self.order.order_steps
     self.assertEqual(len(self.order.order_steps), length_of_order_steps)
示例#2
0
 def setUp(self):
     """Initiates variables to be used in most tests"""
     self.db = Database()
     self.user_data = {
         'key': 1,
         'first_name': 'John',
         'last_name': 'Doe',
         'email': '*****@*****.**',
         'password': '******',
     }
     self.user = User(**self.user_data)
     self.db = Database()
     self.user.save(self.db)
     self.category_data = {
         'key': 1,
         'name': 'cakes',
         'description': 'all orders cake!',
         'user': self.user.key,
     }
     self.category = orderCategory(**self.category_data)
     self.category.save(self.db)
     self.order_data = {
         'key': 1,
         'name': 'Banana cake',
         'description': 'yummy!',
         'category': self.category.key
     }
     self.order = order(**self.order_data)
     self.order.save(self.db)
     self.order_step_data = {
         'key': 1,
         'text_content': "Don't do anything",
         'order': self.order.key
     }
     self.order_step = orderStep(**self.order_step_data)
示例#3
0
    def test_get_all_steps(self):
        """The get_all_steps function should be able to retrieve all steps"""
        text_content_tuple = ('Chicken', 'Pizza', 'Mushroom Soup')
        # create three order steps
        created_order_steps = []
        # incase an order step is ever created in the Setup
        key = 2
        # save order in db
        self.order.save(self.db)
        for text_content in text_content_tuple:
            new_data = utilities.replace_value_in_dict(self.order_step_data,
                                                       'text_content',
                                                       text_content)
            new_order_step = orderStep(**new_data,
                                       key=key,
                                       order=self.order.key)
            new_order_step.save(self.db)
            created_order_steps.append(new_order_step)
            key += 1

        order_steps = self.order.get_all_steps(self.db)
        self.assertIsInstance(order_steps, list)
        self.assertEqual(len(self.order.order_steps), len(order_steps))
        self.assertListEqual(created_order_steps, order_steps)
        self.assertRaises(TypeError, self.order.get_all_steps,
                          'expected Database object not string')
示例#4
0
 def test_delete_object_for_orders(self):
     """delete_object should be able to remove the object passed to it from the database"""
     # setup
     self.user.save(self.db)
     category = orderCategory(**self.category_data)
     category.save(self.db)
     order = order(**self.order_data)
     order.save(self.db)
     # create step as child of order
     order_step = orderStep(**self.order_step_data)
     order_step.save(self.db)
     # delete order
     self.db.delete_object(order)
     # assert that the order step object is not in self.db.order_steps
     self.assertRaises(KeyError, utilities.return_value_from_dict,
                       self.db.order_steps, order_step.key)
     # assert that the order object is not in self.db.orders
     self.assertRaises(KeyError, utilities.return_value_from_dict,
                       self.db.orders, order.key)
     # assert that the order step key is not in self.db.order_step_keys
     self.assertNotIn(order_step.key, self.db.order_step_keys)
     # assert that the order key is not in self.db.order_keys
     self.assertNotIn(order.key, self.db.order_keys)
     # assert that the order name is not in self.db.order_name_key_map
     self.assertNotIn(order.name, self.db.order_name_key_map.keys())
     # try to delete a non existent object by deleting category again
     self.assertRaises(KeyError, self.db.delete_object, order)
示例#5
0
 def test_get_order_step(self):
     """A order step can be retrieved by key"""
     # setup
     self.user.save(self.db)
     category = orderCategory(**self.category_data)
     category.save(self.db)
     order = order(**self.order_data)
     order.save(self.db)
     order_step = orderStep(**self.order_step_data)
     order_step.save(self.db)
     # try retrieving the order step
     order_step_from_db = self.db.get_order_step(order_step.key)
     self.assertEqual(order_step, order_step_from_db)
     # try retrieving a non-existent order step
     self.assertIsNone(self.db.get_order_step(50))
     # try using a non-int key
     self.assertRaises(TypeError, self.db.get_order_step,
                       'string instead of int')