def search(request): job_count = TestJobs.objects.all().count() environments = Environments.objects.all() tests = TestsStorage.objects.all() # Custom data list_of_c_data_keys = [] for obj in TestJobs.objects.all().values_list('custom_data', flat=True): if obj is None: continue if isinstance(obj, str): continue list_of_c_data_keys = list_of_c_data_keys + list(obj.keys()) c_data_uniq_keys = sorted(list(set(list_of_c_data_keys))) # Running jobs count running_jobs_count = helpers.running_jobs_count() return render( request, "search/search.html", { "job_count": job_count, "environments": environments, "tests": tests, "running_jobs_count": running_jobs_count, "c_data_k": c_data_uniq_keys })
def main(request): envs = Environments.objects.all().exclude(name="") # Running jobs count running_jobs_count = helpers.running_jobs_count() return render(request, "management/main.html", { 'envs': envs, 'running_jobs_count': running_jobs_count })
def users(request): users = User.objects.all() # Use if we have users without token for user in users: Token.objects.get_or_create(user=user) # Running jobs count running_jobs_count = helpers.running_jobs_count() return render(request, "management/users.html", { "users": users, "running_jobs_count": running_jobs_count })
def index(request): running_jobs_count = helpers.running_jobs_count() latest_jobs = TestJobs.objects.select_related('env').order_by('-stop_time').exclude(status='1')[:10] latest_jobs_items = [] for job in latest_jobs: job_item = dict() job_item['uuid'] = job.uuid job_item['time_taken'] = job.get_time_taken() job_item['stop_time'] = job.get_stop_time() job_item['status'] = job.status job_item['tests_passed'] = job.tests_passed job_item['tests_failed'] = job.tests_failed job_item['tests_aborted'] = job.tests_aborted job_item['tests_skipped'] = job.tests_skipped job_item['tests_not_started'] = job.tests_not_started job_item['tests_percentage'] = job.tests_percentage() job_item['env'] = job.get_env() job_item['status'] = job.status latest_jobs_items.append(job_item) running_jobs = TestJobs.objects.filter(status='1').order_by('-start_time') running_jobs_items = [] for job in running_jobs: job_item = dict() job_item['uuid'] = job.uuid job_item['start_time'] = job.get_start_time() job_item['env'] = job.get_env() job_item['tests_passed'] = job.tests_passed job_item['tests_failed'] = job.tests_failed job_item['tests_aborted'] = job.tests_aborted job_item['tests_skipped'] = job.tests_skipped # Fix for None if job.tests_not_started is None: job.tests_not_started = 0 job_item['tests_not_started'] = job.tests_not_started running_jobs_items.append(job_item) return render(request, "main/index.html", {"running_jobs_count": running_jobs_count, "latest_jobs_items": latest_jobs_items, "running_jobs_items": running_jobs_items})
def users_edit(request, pk): # Running jobs count running_jobs_count = helpers.running_jobs_count() # User user = User.objects.get(pk=pk) if request.method == 'POST': form = EditUserForm(request.POST) if form.is_valid(): if form.cleaned_data.get("password"): password = form.cleaned_data["password"], is_staff = form.cleaned_data["staff"] try: validate_password(password[0]) form.check_password() except ValidationError as e: form.add_error('password', e) return render(request, 'management/users_edit.html', { 'form': form, 'running_jobs_count': running_jobs_count }) user.set_password(password[0]) user.is_staff = is_staff user.save() return HttpResponseRedirect('/management/users') else: is_staff = form.cleaned_data["staff"] user.is_staff = is_staff user.save() return HttpResponseRedirect('/management/users') else: form = EditUserForm() return render(request, 'management/users_edit.html', { 'form': form, 'user': user, 'running_jobs_count': running_jobs_count })
def users_add(request): # Running jobs count running_jobs_count = helpers.running_jobs_count() if request.method == 'POST': form = AddUserForm(request.POST) if form.is_valid(): # user = form.save(commit=False) username = form.cleaned_data["username"], password = form.cleaned_data["password"], is_staff = form.cleaned_data["staff"] try: form.check_for_spaces() validate_password(password[0]) form.check_password() except ValidationError as e: form.add_error('password', e) return render(request, 'management/users_add.html', { 'form': form, 'running_jobs_count': running_jobs_count }) user_obj = User.objects.create(username=username[0], password=password[0], is_staff=is_staff) user_obj.set_password(password[0]) user_obj.save() Token.objects.create(user=user_obj) return HttpResponseRedirect('/management/users') else: form = AddUserForm() return render(request, 'management/users_add.html', { 'form': form, 'running_jobs_count': running_jobs_count })
def history(request): job_objects = TestJobs.objects.filter(~Q(status=1)).order_by('-id') paginator = Paginator(job_objects, 15) # Show {num} contacts per page page = request.GET.get('page') # Running jobs count running_jobs_count = helpers.running_jobs_count() try: items = paginator.get_page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. items = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. items = paginator.page(paginator.num_pages) return render(request, 'history/history.html', { 'job_objects': items, 'running_jobs_count': running_jobs_count })
def about(request): version = "1.14.2" response = requests.get( f"https://api.github.com/repos/and-sm/testgr/releases/latest", headers={ "Content-Type": "application/json", "User-Agent": "testgr" }) if response.status_code != 200: latest_version = "Unknown" else: latest_version = response.json()['tag_name'] # Running jobs count running_jobs_count = helpers.running_jobs_count() return render( request, "management/about.html", { "version": version, "latest_version": latest_version, "running_jobs_count": running_jobs_count })
def job(request, job_uuid): job_object = TestJobs.objects.get(uuid=job_uuid) uuid = job_object.uuid start_time = job_object.get_start_time() if job_object.stop_time: stop_time = job_object.get_stop_time() else: stop_time = None if job_object.time_taken: time_taken = job_object.get_time_taken() elif job_object.status == 4 and job_object.time_taken is None: time_taken = 0 else: time_taken = None env = job_object.get_env() files = Files.objects.filter(job_id=job_object) if files: files = files status = job_object.status tests = job_object.tests.select_related('test').prefetch_related('test__bugs') # Statistics not_started = int(job_object.tests_not_started or 0) passed = int(job_object.tests_passed or 0) failed = int(job_object.tests_failed or 0) skipped = int(job_object.tests_skipped or 0) aborted = int(job_object.tests_aborted or 0) test_count = int(not_started or 0) + int(passed or 0) + int(failed or 0) + int(skipped or 0) + int(aborted or 0) # Framework type fw = job_object.fw_type # Running jobs count running_jobs_count = helpers.running_jobs_count() # Custom data if job_object.custom_data: custom_data = job_object.custom_data else: custom_data = None return render(request, "main/job.html", {'uuid': uuid, 'start_time': start_time, 'stop_time': stop_time, 'time_taken': time_taken, 'env': env, 'status': status, 'tests': tests, 'test_count': test_count, 'passed': passed, 'failed': failed, 'skipped': skipped, 'not_started': not_started, 'aborted': aborted, 'fw': fw, 'running_jobs_count': running_jobs_count, 'custom_data': custom_data, 'files': files # 'tests_percentage': job_object.tests_percentage() })
def test(request, test_uuid): test_object = Tests.objects.get(uuid=test_uuid) test_job = test_object.job test_storage_data = test_object.test uuid = test_object.uuid if test_object.start_time: start_time = test_object.get_start_time() else: start_time = None if test_object.stop_time: stop_time = test_object.get_stop_time() else: stop_time = None if test_object.time_taken: time_taken = test_object.get_time_taken() elif test_object.status == 6 and test_object.time_taken is None: time_taken = 0 else: time_taken = None env = test_job.get_env() if not env: env = "Not provided by user" elif env == "None": env = "Not provided by user" status = test_object.status msg = test_object.msg trace = test_object.trace # msg_detailed = test_object.msg_detailed identity = test_storage_data.identity if test_job.fw_type == 1: identity = identity.split(".") elif test_job.fw_type == 2: identity = identity.split("/") for item in identity: if "::" in item: modified_item = item.split("::") identity.remove(item) identity.extend(modified_item) else: pass files = Files.objects.filter(test_id=test_object) if files: files = files if test_object.test.description: description = test_object.test.description else: description = "" if test_object.test.note: note = test_object.test.note else: note = "" if test_object.test.suppress: suppress = test_object.test.suppress else: suppress = "" if test_storage_data.bugs: bugs = test_storage_data.bugs else: bugs = "" # Running jobs count running_jobs_count = helpers.running_jobs_count() # Last 5 jobs data = Tests.objects.filter(test__identity=test_object.test.identity).order_by('-id')[:10] last_10_tests = list() last_tests_count = 0 for i in data: test_data = list() test_data.append(i.uuid) test_data.append(i.status) test_data.append(i.get_stop_time()) last_10_tests.append(test_data) last_tests_count += 1 # Last success data = Tests.objects.filter(test__identity=test_object.test.identity).filter(status=3).order_by('-id')[:1] last_success = list() for i in data: last_success.append(i.uuid) last_success.append(i.status) last_success.append(i.get_stop_time()) # Last fail data = Tests.objects.filter(test__identity=test_object.test.identity).filter(status=4).order_by('-id')[:1] last_fail = list() for i in data: last_fail.append(i.uuid) last_fail.append(i.status) last_fail.append(i.get_stop_time()) # Previous success prev_success = list() data = Tests.objects.filter(test__identity=test_object.test.identity, pk__lt=test_object.pk, status=3).order_by('-id')[:1] if data is not None: for i in data: prev_success.append(i.uuid) prev_success.append(i.status) prev_success.append(i.get_stop_time()) # Next success next_success = list() data = Tests.objects.filter(test__identity=test_object.test.identity, pk__gt=test_object.pk, status=3).order_by('id')[:1] if data is not None: for i in data: next_success.append(i.uuid) next_success.append(i.status) next_success.append(i.get_stop_time()) # Previous fail prev_fail = list() data = Tests.objects.filter(test__identity=test_object.test.identity, pk__lt=test_object.pk, status=4).order_by('-id')[:1] if data is not None: for i in data: prev_fail.append(i.uuid) prev_fail.append(i.status) prev_fail.append(i.get_stop_time()) # Next fail next_fail = list() data = Tests.objects.filter(test__identity=test_object.test.identity, pk__gt=test_object.pk, status=4).order_by('id')[:1] if data is not None: for i in data: next_fail.append(i.uuid) next_fail.append(i.status) next_fail.append(i.get_stop_time()) # Custom data if test_job.custom_data: custom_data = sorted(test_job.custom_data.items()) else: custom_data = None # Test full path full_path = ".".join(identity) if test_job.fw_type == 1: test_class = test_storage_data.get_test_class_for_nose() test_method = test_storage_data.get_test_method_for_nose() else: test_class = test_storage_data.get_test_class_for_pytest() test_method = test_storage_data.get_test_method_for_pytest() screenshots = Screenshots.objects.filter(test = test_object) return render(request, "main/test.html", {'uuid': uuid, 'start_time': start_time, 'stop_time': stop_time, 'time_taken': time_taken, 'env': env, 'status': status, 'msg': msg, # 'msg_detailed': msg_detailed, 'identity': identity, 'description': description, 'note': note, 'suppress': suppress, 'bugs': bugs, 'running_jobs_count': running_jobs_count, 'last_10_tests': last_10_tests, 'last_tests_count': last_tests_count, 'last_success': last_success, 'last_fail': last_fail, 'storage_data': test_storage_data, 'test_job': test_job, 'test_class': test_class, 'test_method': test_method, 'trace': trace, 'custom_data': custom_data, 'full_path': full_path, 'prev_f_result': prev_fail, 'next_f_result': next_fail, 'prev_s_result': prev_success, 'next_s_result': next_success, 'screenshots': screenshots, 'files': files})