Exemplo n.º 1
0
class TestJob(UnitTestCase):
    def setUp(self):
        super(TestJob, self).setUp()
        self.job = Job(slug='cthulhubot-sleep').get_domain_object()
        self.echo_job = Job(slug='cthulhubot-test-helper-echo-job').get_domain_object()

    def test_unicode_on_job_returns_proper_text(self):
        self.assert_equals(u"Sleep for a sec", unicode(self.job))

    def test_unicode_on_model_returns_slug(self):
        self.assert_equals(u"cthulhubot-sleep", unicode(self.job.model))

    def test_dict_bad_slug_raises_error(self):
        self.assert_raises(ValueError, self.job.get_parameter_dict, 0, 'zoidberg')

    def test_dict_contains_proper_help_text(self):
        self.assert_equals(SleepCommand.parameters['time']['help'], self.job.get_parameter_description_dict(0, 'time')['help'])

    def test_dict_contains_job_value_if_it_overwrites_command(self):
        self.assert_equals(0.02, self.job.get_parameter_dict(0, 'time'))

    def test_empty_form_provided_for_command_one_returned(self):
        self.assert_equals({'commands' : [{'command': 'cthulhubot-sleep', 'parameters': {}}]}, get_command_params_from_form_data(self.job, {}))

    def test_form_created_with_proper_number_of_fields(self):
        self.assert_equals(1, len(get_job_configuration_form(self.job).fields))

    def test_form_default_values_propagated_to_initials(self):
        self.assert_equals(0.02, get_job_configuration_form(self.job).initial.get('job_configuration_0'))

    def test_parameters_from_command_propagated_to_form_even_if_not_specified_there(self):
        self.assert_equals(1, len(get_job_configuration_form(self.echo_job).fields))
Exemplo n.º 2
0
class TestCommandConfigUpdate(UnitTestCase):
    def setUp(self):
        super(TestCommandConfigUpdate, self).setUp()
        self.job = Job(slug='cthulhubot-sleep').get_domain_object()

    def test_bad_command_raises_error(self):
        self.assert_raises(ValueError, self.job.update_command_config, 5, {})

    def test_mismatched_command_name(self):
        self.assert_raises(ValueError, self.job.update_command_config, 0, {'command' : 'blahblahblah', 'parameters' : {'time' : 5}})

    def test_config_updated(self):
        self.job.update_command_config(0, {'command' : 'cthulhubot-sleep', 'parameters' : {'time' : 5}})
        self.assert_equals(5, self.job.get_parameter_dict(0, 'time'))
Exemplo n.º 3
0
 def test_overwriting_with_callback_works_do_not_overwrite_unrelated_matches(self):
     job = Job(slug='cthulhubot-test-helper-multiple-echo-2-defined-job').get_domain_object()
     self.assert_equals('first', job.get_parameter_dict(0, 'what'))
Exemplo n.º 4
0
 def test_overwriting_with_callback_works_for_proper_match(self):
     job = Job(slug='cthulhubot-test-helper-multiple-echo-2-defined-job').get_domain_object()
     self.assert_equals('overwritten by job callback', job.get_parameter_dict(1, 'what'))
Exemplo n.º 5
0
 def test_global_overwriting_works_on_all_matches(self):
     job = Job(slug='cthulhubot-test-helper-multiple-echo-all-defined-job').get_domain_object()
     for i in xrange(0, 3):
         self.assert_equals('overwritten by job', job.get_parameter_dict(i, 'what'))
Exemplo n.º 6
0
 def test_directly_overwritten_dict_contains_subclassed_job_value(self):
     job = Job(slug='cthulhubot-test-helper-echo-name-job').get_domain_object()
     self.assert_equals('name', job.get_parameter_dict(0, 'what'))