Beispiel #1
0
 def test_set_invalid_field(self):
     """
     DkronJob: Test setting invalid field
     """
     job = DkronJob(None, name="job1")
     with self.assertRaises(KeyError):
         job.awesome = True
Beispiel #2
0
 def test_set_read_only_field(self):
     """
     DkronJob: Test setting invalid field
     """
     job = DkronJob(None, name="job1")
     with self.assertRaises(KeyError):
         job.success_count = 1000
Beispiel #3
0
 def test_delete_job(self):
     """
     DkronJob: Test delete
     """
     job = DkronJob(self.client, name="job1")
     with requests_mock.Mocker() as mocker:
         exp = job.marshal()
         mocker.register_uri(
             requests_mock.DELETE,
             "http://localhost:8080/v1/jobs/job1",
             text=exp,
             status_code=200,
         )
         got = json.dumps(job.delete())
         self.assertEqual(exp, got, "Exp: '%s', Got: '%s'" % (exp, got))
Beispiel #4
0
 def test_get_executions(self):
     """
     DkronJob: Test executions
     """
     job = DkronJob(self.client, name="job1")
     with requests_mock.Mocker() as mocker:
         exp = "[]"
         mocker.register_uri(
             requests_mock.GET,
             "http://localhost:8080/v1/jobs/job1/executions/",
             text=exp,
             status_code=200,
         )
         got = json.dumps(job.executions())
         self.assertEqual(exp, got, "Exp: '%s', Got: '%s'" % (exp, got))
Beispiel #5
0
    def test_save(self):
        """
        DkronJob: Test saving job
        """
        job = DkronJob(self.client, name="job1")
        with requests_mock.Mocker() as mocker:
            exp = job.marshal()
            mocker.register_uri(
                requests_mock.POST,
                "http://localhost:8080/v1/jobs",
                text=exp,
                status_code=201,
            )

            got = json.dumps(job.save())
            self.assertEqual(exp, got, "Exp: '%s', Got: '%s'" % (exp, got))
Beispiel #6
0
 def create_job(self, data):
     """
     Create/update a job
     """
     job = DkronJob.from_dict(data, self)
     self.save_job(job)
     return job
Beispiel #7
0
 def get_job(self, name):
     """
     Return a job by name
     """
     resp = self._call(_GET, "/jobs/%s" % name)
     if resp.status_code == 404:
         raise DkronJobNotFound("Job %s was not found" % name)
     return DkronJob.from_dict(resp.json(), self)
Beispiel #8
0
 def test_save_job_exception(self):
     """
     DkronClient: Test save_job raises DkronClientException
     """
     job = DkronJob(self.client, name="job1")
     with requests_mock.Mocker() as mocker:
         mocker.register_uri(
             requests_mock.POST,
             "http://localhost:8080/v1/jobs",
             status_code=200,
         )
     self.assertRaises(DkronClientException, self.client.save_job, job)
Beispiel #9
0
    def toggle(self, name):
        '''
        Enable/disable a job

        Arguments:
            name {string} -- the name of job

        Raises:
            DkronJobNotFound -- raise if the job not exists

        Returns:
            DkronJob -- a job of Dkron
        '''
        resp = self._call(_POST, "/jobs/%s/toggle" % name)
        if resp.status_code == 404:
            raise DkronJobNotFound("Job %s was not found" % name)
        return DkronJob.from_dict(resp.json(), self)
Beispiel #10
0
 def jobs(self):
     """
     Returns a list of jobs
     """
     data = self._call(_GET, "/jobs").json()
     return [DkronJob.from_dict(job_data, self) for job_data in data]