コード例 #1
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]))
コード例 #2
0
    def test_list(self):
        # test list
        jobs = JobModel.list()
        self.assertEqual(len(jobs), 3)
        self.assertDictEqual(jobs[0].dict(), test_job_dict)

        # test list limit
        jobs = JobModel.list(limit=1)
        self.assertEqual(len(jobs), 1)

        # test list offset
        jobs = JobModel.list(offset=1)
        self.assertEqual(len(jobs), 2)

        # test list filter_by
        jobs = JobModel.list(filter_by={'id': 1})
        self.assertEqual(len(jobs), 1)
        self.assertEqual(jobs[0].dict(), test_job_dict)
コード例 #3
0
ファイル: test_job.py プロジェクト: hz-heng/webspider
    def test_list(self):
        # test list
        jobs = JobModel.list()
        self.assertEqual(len(jobs), 2)
        self.assertDictEqual(jobs[0].dict(), test_job_data)

        # test list limit
        jobs = JobModel.list(limit=1)
        self.assertEqual(len(jobs), 1)

        # test list offset
        jobs = JobModel.list(offset=1)
        self.assertEqual(len(jobs), 1)

        # test list filter_by
        jobs = JobModel.list(filter_by={'id': 4789})
        self.assertEqual(len(jobs), 1)
        self.assertEqual(jobs[0].dict(), test_job_data)

        jobs = JobModel.list(filter_by={'id': 1})
        self.assertEqual(len(jobs), 0)

        # test list order_by
        jobs = JobModel.list(order_by=JobModel.id.desc())
        self.assertEqual(jobs[1].dict(), test_job_data)