def create_job(self, analysis_name, input_data): """ Create a job for the supplied analysis and input hash The input_data dict is converted to a Perl string before storing """ input_data['timestamp'] = time.time() analysis = self.get_analysis_by_name(analysis_name) if analysis == None: raise ValueError("Analysis %s not found" % analysis_name) s = Session() try: job = Job(input_id=dict_to_perl_string(input_data), status='READY', analysis_id=analysis.analysis_id) s.add(job) s.commit() # force load of object job.analysis job.result return job except: s.rollback() raise finally: s.close()
def test_parse_simple_str(self): o = {'a': 'b'} s = dict_to_perl_string(o) self.assertEquals(s, """{"a" => "b"}""") o2 = perl_string_to_python(s) t = type(o2).__name__ self.assertEquals(t, "dict") self.assertEquals(o2['a'], 'b')
def test_parse_string_dollar(self): o = {'a': "$b"} s = dict_to_perl_string(o) self.assertEquals(s, """{"a" => "\\$b"}""") o2 = perl_string_to_python(s) t = type(o2).__name__ self.assertEquals(t, "dict") self.assertEquals(o2['a'], '$b')
def test_parse_string_quotes(self): o = {'a': "\"b\""} s = dict_to_perl_string(o) self.assertEquals(s, """{"a" => "\\"b\\""}""") o2 = perl_string_to_python(s) t = type(o2).__name__ self.assertEquals(t, "dict") self.assertEquals(o2['a'], '"b"')
def test_parse_simple_list(self): o = {'a': ["a", "b", "c"]} s = dict_to_perl_string(o) self.assertEquals(s, """{"a" => ["a", "b", "c"]}""") o2 = perl_string_to_python(s) t = type(o2).__name__ self.assertEquals(t, "dict") self.assertEquals(type(o2['a']).__name__, "list")
def test_parse_complex(self): o = {'a': ["a", "b", "c"], 'b': 'd', 'c': 99} s = dict_to_perl_string(o) self.assertEquals( s, """{"a" => ["a", "b", "c"], "b" => "d", "c" => 99}""") o2 = perl_string_to_python(s) t = type(o2).__name__ self.assertEquals(t, "dict") self.assertEquals(type(o2['a']).__name__, "list") self.assertEquals(o2['b'], 'd') self.assertEquals(o2['c'], 99)
def test_parse_none(self): o = {'a': None} s = dict_to_perl_string(o) self.assertEquals(s, """{}""")