Exemplo n.º 1
0
    def test_update(self):
        init_job_data_dict = JobModel.get_by_pk(pk=4789).dict()
        to_update_data_dict = dict(title=u'后端吃饭工程师',
                                   work_year=2,
                                   city_id=1,
                                   company_id=11,
                                   department='飞天面条神教招聘',
                                   salary='20k-30k',
                                   education=2,
                                   description=u'日常工作:吃饭!')

        affect_rows = JobModel.update(filter_by={'id': 4789}, values=to_update_data_dict)
        self.assertEqual(affect_rows, 1)

        # 更新后预期的结果
        init_job_data_dict.update(**to_update_data_dict)
        expected_job_data_dict = init_job_data_dict
        init_updated_at = init_job_data_dict.pop('updated_at')

        new_job_data_dict = JobModel.get_by_pk(pk=4789).dict()
        self.assertDictContainsSubset(expected_job_data_dict, new_job_data_dict)
        self.assertGreater(new_job_data_dict.updated_at, init_updated_at)

        # 其他记录不受影响
        self.assertEqual(JobModel.get_by_pk(pk=6814).title, u'web前端')

        # 批量更改
        affect_rows = JobModel.update(filter_by={'company_id': 11}, values={'title': '测试'})
        self.assertEqual(affect_rows, 2)
        self.assertEqual(JobModel.get_by_pk(pk=6814).title, u'测试')
        self.assertEqual(JobModel.get_by_pk(pk=4789).title, u'测试')
Exemplo n.º 2
0
    def test_update(self):
        init_job_data_dict = JobModel.get_by_pk(pk=1).dict()
        to_update_data_dict = dict(title=u'后端吃饭工程师',
                                   work_year=1,
                                   city_id=1,
                                   company_id=1,
                                   department='飞天面条神教招聘',
                                   salary='20k-32k',
                                   education=2,
                                   description=u'日常工作:吃饭!')

        affect_rows = JobModel.update(filter_by={'id': 1},
                                      values=to_update_data_dict)
        self.assertEqual(affect_rows, 1)

        # 更新后预期的结果
        init_job_data_dict.update(**to_update_data_dict)
        predictive_job_data_dict = init_job_data_dict
        init_updated_at = init_job_data_dict.pop('updated_at')

        new_job_data_dict = JobModel.get_by_pk(pk=1).dict()
        self.assertDictContainsSubset(predictive_job_data_dict,
                                      new_job_data_dict)
        self.assertGreater(new_job_data_dict.updated_at, init_updated_at)

        # 其他记录不受影响
        self.assertEqual(JobModel.get_by_pk(pk=2).title, u'前端开发工程师')

        # 批量更改
        affect_rows = JobModel.update(filter_by={'city_id': 4},
                                      values={'title': '测试'})
        self.assertEqual(affect_rows, 2)
        jobs = JobModel.list(filter_by={'city_id': 4})
        self.assertTrue(all([job.title == u'测试' for job in jobs]))