Esempio n. 1
0
    def test_clear_all(self):
        '''Making a DELETE request to /job should delete all jobs.

        This also tests the 403 response when you're not authorized to delete,
        and tests the ?days argument.

        '''
        client = test_client()

        # Add some jobs, all completed and therefore eligible for deletion.
        db.add_pending_job("job_01",
                           str(uuid.uuid4()),
                           "job_type",
                           "result_url",
                           "api_key",
                           metadata={"key": "value"})
        db.mark_job_as_completed("job_01")
        db.add_pending_job("job_02",
                           str(uuid.uuid4()),
                           "job_type",
                           "result_url",
                           "api_key",
                           metadata={
                               "key": "value",
                               "moo": "moo"
                           })
        db.mark_job_as_completed("job_02")
        db.add_pending_job("job_03",
                           str(uuid.uuid4()),
                           "job_type",
                           "result_url",
                           "api_key",
                           metadata={
                               "key": "value",
                               "moo": "moo"
                           })
        db.mark_job_as_completed("job_03")

        original_number_of_jobs = number_of_jobs(client)

        # This should not delete any jobs because not authorized.
        response = client.delete('/job')
        assert response.status_code == 403, response.status
        assert number_of_jobs(client) == original_number_of_jobs

        login(client)

        # This should not delete any jobs because the jobs aren't old enough.
        response = client.delete('/job')
        assert response.status_code == 200, response.status
        assert number_of_jobs(client) == original_number_of_jobs

        # This should delete all the jobs.
        response = client.delete('/job?days=0')
        assert response.status_code == 200, response.status
        assert number_of_jobs(client) == 0
Esempio n. 2
0
    def test_clear_all(self):
        '''Making a DELETE request to /job should delete all jobs.

        This also tests the 403 response when you're not authorized to delete,
        and tests the ?days argument.

        '''
        client = test_client()

        # Add some jobs, all completed and therefore eligible for deletion.
        db.add_pending_job(
            "job_01", str(uuid.uuid4()), "job_type", "result_url", "api_key",
            metadata={"key": "value"})
        db.mark_job_as_completed("job_01")
        db.add_pending_job(
            "job_02", str(uuid.uuid4()), "job_type", "result_url", "api_key",
            metadata={"key": "value", "moo": "moo"})
        db.mark_job_as_completed("job_02")
        db.add_pending_job(
            "job_03", str(uuid.uuid4()), "job_type", "result_url", "api_key",
            metadata={"key": "value", "moo": "moo"})
        db.mark_job_as_completed("job_03")

        original_number_of_jobs = number_of_jobs(client)

        # This should not delete any jobs because not authorized.
        response = client.delete('/job')
        assert response.status_code == 403, response.status
        assert number_of_jobs(client) == original_number_of_jobs

        login(client)

        # This should not delete any jobs because the jobs aren't old enough.
        response = client.delete('/job')
        assert response.status_code == 200, response.status
        assert number_of_jobs(client) == original_number_of_jobs

        # This should delete all the jobs.
        response = client.delete('/job?days=0')
        assert response.status_code == 200, response.status
        assert number_of_jobs(client) == 0
Esempio n. 3
0
    def test_list(self):
        '''Tests for /job which should return a list of all the jobs.

        Tests the results from getting /job with various different limits and
        filters.

        '''
        client = test_client()

        db.add_pending_job("job_01",
                           str(uuid.uuid4()),
                           "job_type",
                           "result_url",
                           "api_key",
                           metadata={"key": "value"})
        db.mark_job_as_completed("job_01")
        db.add_pending_job("job_02",
                           str(uuid.uuid4()),
                           "job_type",
                           "result_url",
                           "api_key",
                           metadata={
                               "key": "value",
                               "moo": "moo"
                           })
        db.mark_job_as_completed("job_02")
        db.add_pending_job("job_03",
                           str(uuid.uuid4()),
                           "job_type",
                           "result_url",
                           "api_key",
                           metadata={
                               "key": "value",
                               "moo": "moo"
                           })
        db.mark_job_as_completed("job_03")
        db.add_pending_job("job_04",
                           str(uuid.uuid4()),
                           "job_type",
                           "result_url",
                           "api_key",
                           metadata={"key": "value"})
        db.mark_job_as_completed("job_04")
        db.add_pending_job("job_05", str(uuid.uuid4()), "job_type",
                           "result_url", "api_key")
        db.mark_job_as_completed("job_05")
        db.add_pending_job("job_06", str(uuid.uuid4()), "job_type",
                           "result_url", "api_key")
        db.mark_job_as_completed("job_06")
        db.add_pending_job("job_07", str(uuid.uuid4()), "job_type",
                           "result_url", "api_key")
        db.mark_job_as_completed("job_07")
        db.add_pending_job("job_08", str(uuid.uuid4()), "job_type",
                           "result_url", "api_key")
        db.mark_job_as_completed("job_08")
        db.add_pending_job("job_09", str(uuid.uuid4()), "job_type",
                           "result_url", "api_key")
        db.add_pending_job("job_10", str(uuid.uuid4()), "job_type",
                           "result_url", "api_key")
        db.add_pending_job("job_11", str(uuid.uuid4()), "job_type",
                           "result_url", "api_key")
        db.add_pending_job("job_12", str(uuid.uuid4()), "job_type",
                           "result_url", "api_key")
        db.add_pending_job("job_13", str(uuid.uuid4()), "job_type",
                           "result_url", "api_key")

        response = client.get('/job')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 13, return_data['list']

        response = client.get('/job?_limit=1')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 1, return_data['list']

        response = client.get('/job?_status=complete')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 8, return_data['list']

        response = client.get('/job?key=value')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 4, return_data['list']

        response = client.get('/job?key=value&moo=moo')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 2, return_data['list']

        response = client.get('/job?key=value&moo=moo&moon=moon')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 0, return_data['list']

        response = client.get('/job?key=value&moon=moon')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 0, return_data['list']
Esempio n. 4
0
    def test_list(self):
        '''Tests for /job which should return a list of all the jobs.

        Tests the results from getting /job with various different limits and
        filters.

        '''
        client = test_client()

        db.add_pending_job(
            "job_01", str(uuid.uuid4()), "job_type", "result_url", "api_key",
            metadata={"key": "value"})
        db.mark_job_as_completed("job_01")
        db.add_pending_job(
            "job_02", str(uuid.uuid4()), "job_type", "result_url", "api_key",
            metadata={"key": "value", "moo": "moo"})
        db.mark_job_as_completed("job_02")
        db.add_pending_job(
            "job_03", str(uuid.uuid4()), "job_type", "result_url", "api_key",
            metadata={"key": "value", "moo": "moo"})
        db.mark_job_as_completed("job_03")
        db.add_pending_job(
            "job_04", str(uuid.uuid4()), "job_type", "result_url", "api_key",
            metadata={"key": "value"})
        db.mark_job_as_completed("job_04")
        db.add_pending_job(
            "job_05", str(uuid.uuid4()), "job_type", "result_url", "api_key")
        db.mark_job_as_completed("job_05")
        db.add_pending_job(
            "job_06", str(uuid.uuid4()), "job_type", "result_url", "api_key")
        db.mark_job_as_completed("job_06")
        db.add_pending_job(
            "job_07", str(uuid.uuid4()), "job_type", "result_url", "api_key")
        db.mark_job_as_completed("job_07")
        db.add_pending_job(
            "job_08", str(uuid.uuid4()), "job_type", "result_url", "api_key")
        db.mark_job_as_completed("job_08")
        db.add_pending_job(
            "job_09", str(uuid.uuid4()), "job_type", "result_url", "api_key")
        db.add_pending_job(
            "job_10", str(uuid.uuid4()), "job_type", "result_url", "api_key")
        db.add_pending_job(
            "job_11", str(uuid.uuid4()), "job_type", "result_url", "api_key")
        db.add_pending_job(
            "job_12", str(uuid.uuid4()), "job_type", "result_url", "api_key")
        db.add_pending_job(
            "job_13", str(uuid.uuid4()), "job_type", "result_url", "api_key")

        response = client.get('/job')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 13, return_data['list']

        response = client.get('/job?_limit=1')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 1, return_data['list']

        response = client.get('/job?_status=complete')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 8, return_data['list']

        response = client.get('/job?key=value')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 4, return_data['list']

        response = client.get('/job?key=value&moo=moo')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 2, return_data['list']

        response = client.get('/job?key=value&moo=moo&moon=moon')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 0, return_data['list']

        response = client.get('/job?key=value&moon=moon')
        return_data = json.loads(response.data)
        assert len(return_data['list']) == 0, return_data['list']