def test_batch_add(self): # 插入了其他的类实例 init_jobs_count = JobModel.count() model_instances = [ CityModel(name='你好'), JobModel(title='招聘资深前端工程师', city_id=1, company_id=2, lg_job_id=100056), JobModel(title='招聘资深中端工程师', city_id=1, company_id=2, lg_job_id=100055), ] with self.assertRaises(ValueError): JobModel.batch_add(model_instances) self.assertEqual(JobModel.count(), init_jobs_count) model_instances = [ JobModel(title='招聘资深前端工程师', city_id=1, company_id=2, lg_job_id=100056), JobModel(title='招聘资深中端工程师', city_id=1, company_id=2, lg_job_id=100055), ] JobModel.batch_add(model_instances) self.assertEqual(JobModel.count(), init_jobs_count + 2)
def test_count(self): job_quantitys = JobModel.count() self.assertEqual(job_quantitys, 2) # test count filter_by job_quantitys = JobModel.count(filter_by={'id': 4789}) self.assertEqual(job_quantitys, 1) job_quantitys = JobModel.count(filter_by={'id': 1}) self.assertEqual(job_quantitys, 0)
def test_count(self): jobs_count = JobModel.count() self.assertEqual(jobs_count, 3) jobs_count = JobModel.count(filter_by={'city_id': 4}) self.assertEqual(jobs_count, 2) jobs_count = JobModel.count( filter=(and_(JobModel.city_id == 4, JobModel.company_id == 3))) self.assertEqual(jobs_count, 1) jobs_count = JobModel.count(filter=(JobModel.id == 1)) self.assertEqual(jobs_count, 1)