diff --git a/brewtils/models.py b/brewtils/models.py index c9ee4a52..fe80efce 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -104,8 +104,9 @@ class Events(Enum): TOPIC_REMOVED = 56 REPLICATION_CREATED = 57 REPLICATION_UPDATED = 58 + DIRECTORY_FILE_CHANGE = 59 - # Next: 59 + # Next: 60 class Permissions(Enum): @@ -1415,26 +1416,44 @@ def scheduler_kwargs(self): class FileTrigger(BaseModel): schema = "FileTriggerSchema" - def __init__(self, pattern=None, path=None, recursive=None, callbacks=None): + def __init__( + self, + pattern=None, + path=None, + recursive=None, + create=None, + modify=None, + move=None, + delete=None, + ): self.pattern = pattern self.path = path self.recursive = recursive - self.callbacks = callbacks + self.create = create + self.modify = modify + self.move = move + self.delete = delete def __str__(self): return repr(self) def __repr__(self): - return "" % ( + return ( + "" + ) % ( self.pattern, self.path, self.recursive, - self.callbacks, + self.create, + self.modify, + self.move, + self.delete, ) @property def scheduler_attributes(self): - return ["pattern", "path", "recursive", "callbacks"] + return ["pattern", "path", "recursive", "create", "modify", "move", "delete"] @property def scheduler_kwargs(self): @@ -1444,7 +1463,10 @@ def scheduler_kwargs(self): "pattern": self.pattern, "path": self.path, "recursive": self.recursive, - "callbacks": self.callbacks, + "create": self.create, + "modify": self.modify, + "move": self.move, + "delete": self.delete, } ) diff --git a/brewtils/schemas.py b/brewtils/schemas.py index 913435f8..37d2bd22 100644 --- a/brewtils/schemas.py +++ b/brewtils/schemas.py @@ -452,10 +452,13 @@ class CronTriggerSchema(BaseSchema): class FileTriggerSchema(BaseSchema): - pattern = fields.List(fields.Str(), allow_none=True) + pattern = fields.Str(allow_none=True) path = fields.Str(allow_none=True) recursive = fields.Bool(allow_none=True) - callbacks = fields.Dict(fields.Bool(), allow_none=True) + create = fields.Bool(allow_none=True) + modify = fields.Bool(allow_none=True) + move = fields.Bool(allow_none=True) + delete = fields.Bool(allow_none=True) class ConnectionSchema(BaseSchema): diff --git a/brewtils/test/comparable.py b/brewtils/test/comparable.py index bcf4f5de..bba46ea9 100644 --- a/brewtils/test/comparable.py +++ b/brewtils/test/comparable.py @@ -21,6 +21,7 @@ CronTrigger, DateTrigger, Event, + FileTrigger, Garden, Instance, IntervalTrigger, @@ -201,7 +202,8 @@ def _assert_wrapper(obj1, obj2, expected_type=None, do_raise=False, **kwargs): assert_queue_equal = partial(_assert_wrapper, expected_type=Queue) assert_request_template_equal = partial(_assert_wrapper, expected_type=RequestTemplate) assert_trigger_equal = partial( - _assert_wrapper, expected_type=(CronTrigger, DateTrigger, IntervalTrigger) + _assert_wrapper, + expected_type=(CronTrigger, DateTrigger, FileTrigger, IntervalTrigger), ) assert_request_file_equal = partial(_assert_wrapper, expected_type=RequestFile) assert_runner_equal = partial(_assert_wrapper, expected_type=Runner) diff --git a/brewtils/test/fixtures.py b/brewtils/test/fixtures.py index 95a67e17..2cf581cc 100644 --- a/brewtils/test/fixtures.py +++ b/brewtils/test/fixtures.py @@ -14,6 +14,7 @@ CronTrigger, DateTrigger, Event, + FileTrigger, Garden, Instance, IntervalTrigger, @@ -700,6 +701,15 @@ def cron_job_dict(job_dict, cron_trigger_dict): return dict_copy +@pytest.fixture +def file_job_dict(job_dict, file_trigger_dict): + """A file job represented as a dictionary.""" + dict_copy = copy.deepcopy(job_dict) + dict_copy["trigger_type"] = "file" + dict_copy["trigger"] = file_trigger_dict + return dict_copy + + @pytest.fixture def interval_job_dict(job_dict, interval_trigger_dict): """An interval job represented as a dictionary.""" @@ -751,6 +761,16 @@ def bg_cron_job(cron_job_dict, bg_request_template, bg_cron_trigger, ts_dt): return Job(**dict_copy) +@pytest.fixture +def bg_file_job(file_job_dict, bg_request_template, bg_file_trigger): + """A beer garden interval job""" + dict_copy = copy.deepcopy(file_job_dict) + dict_copy["next_run_time"] = None + dict_copy["trigger"] = bg_file_trigger + dict_copy["request_template"] = bg_request_template + return Job(**dict_copy) + + @pytest.fixture def bg_interval_job(interval_job_dict, bg_request_template, bg_interval_trigger, ts_dt): """A beer garden interval job""" @@ -848,6 +868,27 @@ def bg_date_trigger(date_trigger_dict, ts_dt): return DateTrigger(**dict_copy) +@pytest.fixture +def file_trigger_dict(): + """A file trigger as a dictionary""" + return { + "path": "./input", + "pattern": "*", + "recursive": False, + "create": True, + "modify": False, + "move": False, + "delete": False, + } + + +@pytest.fixture +def bg_file_trigger(file_trigger_dict): + """A file trigger as a model""" + dict_copy = copy.deepcopy(file_trigger_dict) + return FileTrigger(**dict_copy) + + @pytest.fixture def bg_request_file(request_file_dict): """A request file as a model""" diff --git a/test/models_test.py b/test/models_test.py index ca562d1a..8bfa5443 100644 --- a/test/models_test.py +++ b/test/models_test.py @@ -572,6 +572,19 @@ def test_scheduler_kwargs(self, bg_date_trigger, ts_dt_utc): } +class TestFileTrigger(object): + def test_schedule_kwargs_default(self, bg_file_trigger): + assert bg_file_trigger.scheduler_kwargs == { + "path": "./input", + "pattern": "*", + "recursive": False, + "create": True, + "modify": False, + "move": False, + "delete": False, + } + + class TestIntervalTrigger(object): def test_scheduler_kwargs_default(self): assert IntervalTrigger(timezone="utc").scheduler_kwargs == { @@ -637,6 +650,17 @@ def test_scheduler_kwargs( "", "", ), + ( + lazy_fixture("bg_file_trigger"), + ( + "" + ), + ( + "" + ), + ), ( lazy_fixture("bg_interval_trigger"), "",