def test_get_record_value(self): """ Ensure that get_record_value() works okay """ job1 = BaseJob({"key": "value"}, {"key": "raw-value"}) job2 = BaseJob({"_key": "value"}, {"_key": "raw-value"}) self.assertEqual(job1.get_record_value("key"), "value") self.assertEqual(job2.get_record_value("key"), "value")
def test_environ_parsing_with_various_separators(self): job = BaseJob({ 'name': 'name', 'plugin': 'plugin', 'environ': self.parameters_keymap[ self.parameters.glue].join(['foo', 'bar', 'froz'])}) expected = set({'foo', 'bar', 'froz'}) observed = job.get_environ_settings() self.assertEqual(expected, observed)
def test_get_environ_settings(self): job1 = BaseJob({}) self.assertEqual(job1.get_environ_settings(), set()) job2 = BaseJob({'environ': 'a b c'}) self.assertEqual(job2.get_environ_settings(), set(['a', 'b', 'c'])) job3 = BaseJob({'environ': 'a,b,c'}) self.assertEqual(job3.get_environ_settings(), set(['a', 'b', 'c']))
def test_environ_parsing_with_various_separators(self): job = BaseJob( { "id": "id", "plugin": "plugin", "environ": self.parameters_keymap[self.parameters.glue].join(["foo", "bar", "froz"]), } ) expected = set({"foo", "bar", "froz"}) observed = job.get_environ_settings() self.assertEqual(expected, observed)
def test_checksum_smoke(self): job1 = BaseJob({'plugin': 'plugin', 'user': '******'}) identical_to_job1 = BaseJob({'plugin': 'plugin', 'user': '******'}) # Two distinct but identical jobs have the same checksum self.assertEqual(job1.checksum, identical_to_job1.checksum) job2 = BaseJob({'plugin': 'plugin', 'user': '******'}) # Two jobs with different definitions have different checksum self.assertNotEqual(job1.checksum, job2.checksum) # The checksum is stable and does not change over time self.assertEqual( job1.checksum, "c47cc3719061e4df0010d061e6f20d3d046071fd467d02d093a03068d2f33400")
def test_environ_parsing_with_various_separators(self): job = BaseJob({ 'id': 'id', 'plugin': 'plugin', 'environ': self.parameters_keymap[self.parameters.glue].join( ['foo', 'bar', 'froz']) }) expected = set({'foo', 'bar', 'froz'}) observed = job.get_environ_settings() self.assertEqual(expected, observed)
def test_properties_default_values(self): """ Ensure that all properties default to None """ job = BaseJob({}) self.assertEqual(job.plugin, None) self.assertEqual(job.command, None) self.assertEqual(job.environ, None) self.assertEqual(job.user, None)
class JobEnvTests(TestCase): def setUp(self): self.job = BaseJob({'plugin': 'plugin', 'environ': 'foo'}) def test_checkbox_env(self): base_env = {"PATH": "", 'foo': 'bar', 'baz': 'qux'} path = '/usr/share/checkbox-lambda' with patch.dict('os.environ', {}): env = self.job.modify_execution_environment(base_env, [path]) self.assertEqual(env['CHECKBOX_LAMBDA_SHARE'], path) self.assertEqual(env['foo'], 'bar') self.assertNotIn('bar', env) def test_checkbox_env_with_data_dir(self): base_env = {"PATH": "", "CHECKBOX_DATA": "DEADBEEF"} path = '/usr/share/checkbox-lambda' with patch.dict('os.environ', {"CHECKBOX_DATA": "DEADBEEF"}): env = self.job.modify_execution_environment(base_env, [path]) self.assertEqual(env['CHECKBOX_LAMBDA_SHARE'], path) self.assertEqual(env['CHECKBOX_DATA'], "DEADBEEF")
def test_get_environ_settings(self): job1 = BaseJob({}) self.assertEqual(job1.get_environ_settings(), set()) job2 = BaseJob({"environ": "a b c"}) self.assertEqual(job2.get_environ_settings(), set(["a", "b", "c"])) job3 = BaseJob({"environ": "a,b,c"}) self.assertEqual(job3.get_environ_settings(), set(["a", "b", "c"]))
def test_get_record_value(self): """ Ensure that get_record_value() works okay """ job1 = BaseJob({'key': 'value'}, {'key': 'raw-value'}) job2 = BaseJob({'_key': 'value'}, {'_key': 'raw-value'}) self.assertEqual(job1.get_record_value('key'), 'value') self.assertEqual(job2.get_record_value('key'), 'value')
def test_properties(self): """ Ensure that properties are looked up in the non-raw copy of the data """ job = BaseJob( { 'plugin': 'plugin-value', 'command': 'command-value', 'environ': 'environ-value', 'user': '******', }, { 'plugin': 'plugin-raw', 'command': 'command-raw', 'environ': 'environ-raw', 'user': '******', }) self.assertEqual(job.plugin, "plugin-value") self.assertEqual(job.command, "command-value") self.assertEqual(job.environ, "environ-value") self.assertEqual(job.user, "user-value")
def setUp(self): self.job = BaseJob({'plugin': 'plugin', 'environ': 'foo'})
def test_environ_parsing_empty(self): job = BaseJob({'plugin': 'plugin'}) expected = set() observed = job.get_environ_settings() self.assertEqual(expected, observed)