def test_new_job_then_update(self): if os.path.isfile('/tmp/test.db'): os.remove('/tmp/test.db') # Test writer = Writer(base_path + '/static/config_valid.yml') writer.set_prop('name', self._job_name) writer.set_prop('input', self._job_input) writer.set_prop('input_parameters', self._job_input_params) writer.set_prop('output', self._job_output) writer.set_prop('output_parameters', self._job_output_params) job = writer.save() self.assertTrue(os.path.isfile('/tmp/test.db')) jobInDb = self._get_job() self.assertEqual(self._job_name, jobInDb['name']) self.assertTrue(jobInDb['active']) self.assertEqual(self._job_input, jobInDb['input']) self.assertEqual(self._job_output, jobInDb['output']) writer = Writer(base_path + '/static/config_valid.yml', job.name) job = writer.get_job() self.assertEqual(job.name, jobInDb['name']) self.assertTrue(job.active) self.assertEqual(job.input, jobInDb['input']) self.assertEqual(job.output, jobInDb['output']) writer = Writer(base_path + '/static/config_valid.yml', job.name) writer.set_prop('active', False) job = writer.save() jobInDb = self._get_job() self.assertEqual(self._job_name, jobInDb['name']) self.assertFalse(jobInDb['active'])
def test_add_rules_to_db_new_job(self): if os.path.isfile('/tmp/test.db'): os.remove('/tmp/test.db') # Test writer = Writer(base_path + '/static/config_valid.yml') writer.set_prop('name', self._job_name) writer.set_prop('input', self._job_input) writer.set_prop('output', self._job_output) writer.fields_writer.add_field('input_test', 'output_test') writer.fields_writer.add_field('input_test2', 'output_test2') writer.fields_writer.add_rule(output_field='output_test', name='lowercase', method='lwrcs', description='Lower the case !', active=False) writer.fields_writer.add_rule(output_field='output_test', name='uppercase', method='uprc', params={'a': 'b'}, blocking=True, priority=10) job = writer.save() writer = Writer(base_path + '/static/config_valid.yml', job.name) self.assertTrue(os.path.isfile('/tmp/test.db')) jobInDb = self._get_job() self.assertEqual(self._job_name, jobInDb['name']) self.assertEqual(self._job_name, writer.get_prop('name')) fieldsInDb = self._get_fields(jobInDb['id'], 2) self.assertEqual('input_test', fieldsInDb[0]['input']) self.assertEqual('output_test', fieldsInDb[0]['output']) rulesInDb = self._get_rules(fieldsInDb[0]['id'], 2) self.assertEqual('lowercase', rulesInDb[0]['name']) self.assertEqual('Lower the case !', rulesInDb[0]['description']) self.assertEqual(0, rulesInDb[0]['active']) self.assertEqual('lwrcs', rulesInDb[0]['method']) self.assertEqual({}, json.loads(rulesInDb[0]['params'])) self.assertIs(0, rulesInDb[0]['blocking']) self.assertIs(1, rulesInDb[0]['priority']) self.assertEqual('uppercase', rulesInDb[1]['name']) self.assertIs(None, rulesInDb[1]['description']) self.assertEqual(1, rulesInDb[1]['active']) self.assertEqual('uprc', rulesInDb[1]['method']) self.assertEqual({'a': 'b'}, json.loads(rulesInDb[1]['params'])) self.assertIs(1, rulesInDb[1]['blocking']) self.assertIs(10, rulesInDb[1]['priority']) job = writer.get_job() self.assertEqual(self._job_name, job.name) fields = writer.fields_writer.get_fields() self.assertTrue('output_test' in fields) self.assertTrue('output' in fields['output_test']) self.assertEqual(fields['output_test']['output'], 'output_test') self.assertTrue('rules' in fields['output_test']) self.assertTrue('lowercase' in fields['output_test']['rules']) self.assertTrue('method' in fields['output_test']['rules']['lowercase']) self.assertTrue('params' in fields['output_test']['rules']['lowercase']) self.assertEqual(fields['output_test']['rules']['lowercase']['params'], {}) rules = writer.fields_writer.get_rules('output_test') self.assertTrue('lowercase' in rules) self.assertTrue('method' in rules['lowercase']) self.assertTrue('params' in rules['lowercase']) self.assertEqual({}, rules['lowercase']['params']) self.assertTrue('uppercase' in rules) self.assertTrue('method' in rules['uppercase']) self.assertTrue('params' in rules['uppercase']) self.assertEqual({'a': 'b'}, rules['uppercase']['params'])