def running_jobs(request): if request.user.is_authenticated(): # hack to get numbers to update get_all_jobs(request.user.credentials.all()) temp = len(Job.get_running_jobs(user=request.user)) return {"running_jobs": temp} else: return {"running_jobs": None}
def get_job_list(request): cluster = request.REQUEST.get("cluster", "") jobs = interface.get_all_jobs(request.user, cluster) a = { "is_authenticated": request.user.is_authenticated(), "clusters": jobs, } if request.REQUEST.get("html", ''): return render(request, "cluster/job_table.html", a) return HttpResponse(json.dumps(a), content_type="application/json")
def test_job_detail(self): interface.run_job(self.credential2, '', 'sleep 10') results = interface.get_all_jobs(self.user, self.cluster.name) jobid = results[0]["jobs"][0][0] url = reverse(views.job_detail, args=(self.cluster.name, jobid)) response = self.client.get(url) self.assertEqual(response.status_code, 302) r = self.client.login(**USER_LOGIN) self.assertTrue(r) response = self.client.get(url) self.assertEqual(response.status_code, 200)
def test_get_all_jobs(self): results = interface.get_all_jobs([self.credential]) results[0]["jobs"] = [] expected = [{ 'jobs': [], 'name': CLUSTER['name'], 'columns': [ 'Job ID', 'Username', 'Jobname', "Req'd Memory", "Req'd Time", 'Elap Time', 'S' ] }] self.assertEqual(results, expected)
def test_job_detail(self): run_fake_job(self.credential2, 10) results = interface.get_all_jobs([self.credential2]) # cred, ..., job0, id jobid = results[0]["jobs"][0][0] url = reverse(views.job_detail, args=(self.cluster.name, jobid)) response = self.client.get(url) self.assertEqual(response.status_code, 302) r = self.client.login(**USER_LOGIN) self.assertTrue(r) response = self.client.get(url) self.assertEqual(response.status_code, 200)
def get_job_list(request): cluster = request.REQUEST.get("cluster", "") if cluster: creds = request.user.credentials.filter(cluster__name__iexact=cluster) else: creds = request.user.credentials.all() jobs = interface.get_all_jobs(creds) a = { "is_authenticated": request.user.is_authenticated(), "clusters": jobs, } if request.REQUEST.get("html", ''): return render(request, "cluster/job_table.html", a) return HttpResponse(json.dumps(a), content_type="application/json")
def test_get_all_jobs(self): results = interface.get_all_jobs([self.credential]) results[0]["jobs"] = [] expected = [ { 'jobs': [], 'name': CLUSTER['name'], 'columns': [ 'Job ID', 'Username', 'Jobname', "Req'd Memory", "Req'd Time", 'Elap Time', 'S' ] } ] self.assertEqual(results, expected)