def test_init(self): """ DkronClient: Test __init__ has list """ client = DkronClient(hosts="localhost:8080") self.assertEqual( client.hosts, ["localhost:8080"], "Exp: '%s', Got: '%s'" % (['localhost:8080'], client.hosts))
def setUp(self): self.client = DkronClient(hosts=["localhost:8080"])
class DkronClientTestCase(unittest.TestCase): """ Test cases for pydkron.client """ def setUp(self): self.client = DkronClient(hosts=["localhost:8080"]) def test_init(self): """ DkronClient: Test __init__ has list """ client = DkronClient(hosts="localhost:8080") self.assertEqual( client.hosts, ["localhost:8080"], "Exp: '%s', Got: '%s'" % (['localhost:8080'], client.hosts) ) def test_status(self): """ DkronClient: Test status """ exp = {'awesome': 'stuff'} with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.GET, "http://*****:*****@every 5h", "command": "testcommand" }, { "name": "job2", "schedule": "@every 5h", "command": "testcommand2" } ] with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.GET, "http://*****:*****@every 5h", "command": "testcommand" } with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.GET, "http://*****:*****@every 5m", "command": "testcommand", "shell": True, "tags": { "role": "dkron:1", } } with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.POST, "http://localhost:8080/v1/jobs", text=json.dumps(data), status_code=201, ) got = json.loads(self.client.create_job(data).marshal()) self.assertEqual( data, got, "Exp: '%s', Got: '%s'" % (data, got) ) def test_get_executions(self): """ DkronClient: Test get_executions """ with requests_mock.Mocker() as mocker: exp = "[]" mocker.register_uri( requests_mock.GET, "http://localhost:8080/v1/executions/job1", text=exp, status_code=200, ) got = json.dumps(self.client.get_executions("job1")) self.assertEqual( exp, got, "Exp: '%s', Got: '%s'" % (exp, got) ) def test_get_executions_not_found(self): """ DkronClient: Test get_executions raises DkronJobNotFound exception """ with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.GET, "http://localhost:8080/v1/executions/job1", status_code=404, ) self.assertRaises(DkronJobNotFound, self.client.get_executions, "job1")
class DkronClientTestCase(unittest.TestCase): """ Test cases for pydkron.client """ def setUp(self): self.client = DkronClient(hosts=["localhost:8080"]) def test_init(self): """ DkronClient: Test __init__ has list """ client = DkronClient(hosts="localhost:8080") self.assertEqual( client.hosts, ["localhost:8080"], "Exp: '%s', Got: '%s'" % (['localhost:8080'], client.hosts)) def test_status(self): """ DkronClient: Test status """ exp = {'awesome': 'stuff'} with requests_mock.Mocker() as mocker: mocker.register_uri(requests_mock.GET, "http://*****:*****@every 5h", "command": "testcommand" }, { "name": "job2", "schedule": "@every 5h", "command": "testcommand2" }] with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.GET, "http://*****:*****@every 5h", "command": "testcommand" } with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.GET, "http://*****:*****@every 5m", "command": "testcommand", "shell": True, "tags": { "role": "dkron:1", } } with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.POST, "http://*****:*****@every 10s", "timezone": "Europe/Berlin", "owner": "Platform Team", "owner_email": "*****@*****.**", "success_count": 0, "error_count": 0, "last_success": "2020-07-26T01:44:06.459Z", "last_error": "2020-07-26T01:44:06.459Z", "disabled": True, "tags": { "server": "true" }, "metadata": { "office": "Barcelona" }, "retries": 2, "parent_job": "parent_job", "dependent_jobs": ["dependent_job"], "processors": { "files": { "forward": True } }, "concurrency": "allow", "executor": "shell", "executor_config": { "command": "echo 'Hello from Dkron'" }, "status": "success" } with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.POST, "http://localhost:8080/v1/jobs/job1/toggle", text=json.dumps(data), status_code=200, ) job = self.client.toggle("job1") exp = data["name"] got = job.name self.assertEqual( got, exp, "Incorrect job command, exp: '%s' got '%s'" % (exp, got)) def test_toggle_not_found(self): """ DkronClient: Test toggle DkronJobNotFound exception """ with requests_mock.Mocker() as mocker: mocker.register_uri( requests_mock.POST, "http://localhost:8080/v1/jobs/job1/toggle", status_code=404, ) self.assertRaises(DkronJobNotFound, self.client.toggle, "job1")