示例#1
0
    def test_date_db_populate(self):
        """
        Sessions Validate Date - Tests if validation works on values stored in db and not given in 'data'
        :return:
        """
        with app.test_request_context():
            schema = SessionSchema()
            obj = SessionFactory()
            save_to_db(obj)

            original_data = {'data': {'id': 1}}
            data = {}
            SessionSchema.validate_date(schema, data, original_data)
示例#2
0
 def test_date_pass(self):
     """
     Sessions Validate Date - Tests if the function runs without an exception
     :return:
     """
     schema = SessionSchema()
     original_data = {'data': {}}
     data = {
         'starts_at':
         datetime(2099, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
         'ends_at':
         datetime(2099, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC'))
     }
     SessionSchema.validate_date(schema, data, original_data)
 def test_date_pass(self):
     """
     Sessions Validate Date - Tests if the function runs without an exception
     :return:
     """
     schema = SessionSchema()
     original_data = {
         'data': {}
     }
     data = {
         'starts_at': datetime(2003, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
         'ends_at': datetime(2003, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC'))
     }
     SessionSchema.validate_date(schema, data, original_data)
示例#4
0
 def test_date_start_gt_end(self):
     """
     Sessions Validate Date - Tests if exception is raised when ends_at is before starts_at
     :return:
     """
     schema = SessionSchema()
     original_data = {'data': {}}
     data = {
         'starts_at':
         datetime(2099, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
         'ends_at':
         datetime(2099, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC'))
     }
     with self.assertRaises(UnprocessableEntity):
         SessionSchema.validate_date(schema, data, original_data)
 def test_date_start_gt_end(self):
     """
     Sessions Validate Date - Tests if exception is raised when ends_at is before starts_at
     :return:
     """
     schema = SessionSchema()
     original_data = {
         'data': {}
     }
     data = {
         'starts_at': datetime(2003, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
         'ends_at': datetime(2003, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC'))
     }
     with self.assertRaises(UnprocessableEntity):
         SessionSchema.validate_date(schema, data, original_data)
    def test_date_db_populate(self):
        """
        Sessions Validate Date - Tests if validation works on values stored in db and not given in 'data'
        :return:
        """
        with app.test_request_context():
            schema = SessionSchema()
            obj = SessionFactory()
            db.session.add(obj)
            db.session.commit()

            original_data = {
                'data': {
                    'id': 1
                }
            }
            data = {}
            SessionSchema.validate_date(schema, data, original_data)