aboutsummaryrefslogtreecommitdiffstats
path: root/iceci
diff options
context:
space:
mode:
authorEdan Binshtok <eb578m@intl.att.com>2017-11-19 11:50:50 +0200
committerEdan Binshtok <eb578m@intl.att.com>2017-11-19 11:51:04 +0200
commit71891b3040605103397ffa7fb349215eced3a2c3 (patch)
tree22dda04edd1b8ee0d0de2a6a260d6d60e42cba25 /iceci
parent433a8256e31f755f5e236491bbe39d3db24d6d6d (diff)
Pep8 another fixes
Add more fixes to pep8 Issue-ID: VVP-25 Change-Id: Icc3bd3977ced2b537c858a9801e04a6bf6d1db05 Signed-off-by: Edan Binshtok <eb578m@intl.att.com>
Diffstat (limited to 'iceci')
-rw-r--r--iceci/__init__.py4
-rw-r--r--iceci/admin.py18
-rw-r--r--iceci/apps.py4
-rw-r--r--iceci/decorator/__init__.py4
-rw-r--r--iceci/decorator/exception_decor.py9
-rw-r--r--iceci/decorator/logFuncEntry.py18
-rw-r--r--iceci/decorator/repeat.py9
-rw-r--r--iceci/mail.py55
-rw-r--r--iceci/migrations/0001_initial.py9
-rw-r--r--iceci/migrations/__init__.py4
-rw-r--r--iceci/models.py14
-rw-r--r--iceci/serializers.py37
-rw-r--r--iceci/urls.py21
-rw-r--r--iceci/views.py175
14 files changed, 253 insertions, 128 deletions
diff --git a/iceci/__init__.py b/iceci/__init__.py
index 30d7152..32b601a 100644
--- a/iceci/__init__.py
+++ b/iceci/__init__.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
diff --git a/iceci/admin.py b/iceci/admin.py
index 21d8f3a..d9fac56 100644
--- a/iceci/admin.py
+++ b/iceci/admin.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -47,7 +47,8 @@ def export_csv(modeladmin, request, queryset):
from django.utils.encoding import smart_str
from django.http import HttpResponse
response = HttpResponse(content_type='text/csv')
- response['Content-Disposition'] = 'attachment; filename=ci_Test_Results.csv'
+ response['Content-Disposition'] = \
+ 'attachment; filename=ci_Test_Results.csv'
writer = csv.writer(response, csv.excel)
# BOM (optional...Excel needs it to open UTF-8 file properly)
response.write(u'\ufeff'.encode('utf8'))
@@ -113,8 +114,15 @@ def as_percentage_of(part, whole):
@admin.register(TestResults)
class TestResultsModelAdmin(admin.ModelAdmin):
- list_display = ["testType", "testFeature", "testName",
- "testResult", "notes", "duration", "build_id", "create_time"]
+ list_display = [
+ "testType",
+ "testFeature",
+ "testName",
+ "testResult",
+ "notes",
+ "duration",
+ "build_id",
+ "create_time"]
list_filter = ["testResult", "testType", "testFeature",
"testName", "notes", "duration", "build_id", "create_time"]
search_fields = ["testResult", "testType", "testFeature", "testName",
diff --git a/iceci/apps.py b/iceci/apps.py
index 1e33154..459b943 100644
--- a/iceci/apps.py
+++ b/iceci/apps.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
diff --git a/iceci/decorator/__init__.py b/iceci/decorator/__init__.py
index 30d7152..32b601a 100644
--- a/iceci/decorator/__init__.py
+++ b/iceci/decorator/__init__.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
diff --git a/iceci/decorator/exception_decor.py b/iceci/decorator/exception_decor.py
index 467f2ce..2bbced7 100644
--- a/iceci/decorator/exception_decor.py
+++ b/iceci/decorator/exception_decor.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -36,7 +36,6 @@
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-import logging
import traceback
from services.logging_service import LoggingServiceFactory
@@ -48,7 +47,7 @@ logger = LoggingServiceFactory.get_logger()
def exception():
"""
- A decorator that wraps the passed in function and logs
+ A decorator that wraps the passed in function and logs
exceptions should one occur
@param logger: The logging object
@@ -59,7 +58,7 @@ def exception():
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
- except:
+ except BaseException:
err = "There was an exception in %s" % func.__name__
logger.error(err)
session.errorCounter += 1
diff --git a/iceci/decorator/logFuncEntry.py b/iceci/decorator/logFuncEntry.py
index 0995f3b..3caac92 100644
--- a/iceci/decorator/logFuncEntry.py
+++ b/iceci/decorator/logFuncEntry.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -39,6 +39,7 @@
from services.logging_service import LoggingServiceFactory
logger = LoggingServiceFactory.get_logger()
+
def _aop(decorator):
'''This decorator can be used to turn simple functions
into well-behaved decorators, so long as the decorators
@@ -55,7 +56,7 @@ def _aop(decorator):
g.__doc__ = f.__doc__
g.__dict__.update(f.__dict__)
return g
-
+
# Now a few lines needed to make _aop itself
# be a well-behaved decorator.
new_decorator.__name__ = decorator.__name__
@@ -66,10 +67,17 @@ def _aop(decorator):
#
# Sample Use:
#
+
+
@_aop
def logFuncEntry(func):
def foo(*args, **kwargs):
- logger.debug('calling {}'.format(func.__name__)+" | "+str(args)+" | "+str(kwargs))
+ logger.debug(
+ 'calling {}'.format(
+ func.__name__) +
+ " | " +
+ str(args) +
+ " | " +
+ str(kwargs))
return func(*args, **kwargs)
return foo
-
diff --git a/iceci/decorator/repeat.py b/iceci/decorator/repeat.py
index 38eac03..cf57a14 100644
--- a/iceci/decorator/repeat.py
+++ b/iceci/decorator/repeat.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -36,7 +36,9 @@
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-import unittest,time
+import time
+
+
def repeat(times):
def repeatHelper(f):
def callHelper(*args):
@@ -46,4 +48,3 @@ def repeat(times):
return callHelper
time.sleep(3)
return repeatHelper
-
diff --git a/iceci/mail.py b/iceci/mail.py
index 80660b5..310f09e 100644
--- a/iceci/mail.py
+++ b/iceci/mail.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -36,7 +36,7 @@
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-##################################################################################################
+##########################################################################
'''
Created on Apr 20, 2016
@@ -50,7 +50,7 @@ from django.conf import settings
from django.core.mail import send_mail
from django.utils import timezone
-from services.constants import Constants, ServiceProvider
+from services.constants import ServiceProvider
from services.logging_service import LoggingServiceFactory
@@ -60,45 +60,57 @@ param = "1"
logger = LoggingServiceFactory.get_logger()
-def sendMail(param,email, data, mail_body, mail_subject, mail_from=admin_mail_from):
+def sendMail(param, email, data, mail_body, mail_subject,
+ mail_from=admin_mail_from):
logger.debug("about to send mail to " + email)
-
+
try:
html_msg = mail_body.substitute(data)
mail_subject = mail_subject.substitute(data)
send_mail(mail_subject, '', ServiceProvider.PROGRAM_NAME
+ "-CI Report Test Team <" + mail_from + ">",
- settings.ICE_CONTACT_EMAILS , fail_silently=False,
+ settings.ICE_CONTACT_EMAILS, fail_silently=False,
html_message=html_msg)
- logger.debug("Looks like email delivery to "+email+" has succeeded")
+ logger.debug(
+ "Looks like email delivery to " +
+ email +
+ " has succeeded")
except Exception:
traceback.print_exc()
raise
+
##########################
# For Contact Request #
##########################
-lastBuild= param
+lastBuild = param
dt = timezone.now().strftime("%Y-%m-%d %H:%M:%S")
-#envIP = str(socket.gethostbyname(socket.gethostname()))
+# envIP = str(socket.gethostbyname(socket.gethostname()))
envIP = str(socket.gethostname())
-testsResults_mail_subject = Template("""CI Testing results """+ str(dt))
+testsResults_mail_subject = Template("""CI Testing results """ + str(dt))
testsResults_mail_to = settings.ICE_CONTACT_EMAILS
-testsResults_mail_body = Template("""
+testsResults_mail_body = Template(
+ """
<html>
<head>
<title>CI Test Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
- <body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif;">
+ <body style="word-wrap: break-word; -webkit-nbsp-mode: space; """ +
+ """-webkit-line-break: after-white-space; color: rgb(0, 0, 0); """ +
+ """font-size: 14px; font-family: Calibri, sans-serif;">
<a href="http://172.20.31.59:9090/">Jenkins Link for Build</a>
- <h3>Environment name : """+ settings.ICE_CI_ENVIRONMENT_NAME + """</h3>
- <h3>Environment IP : """ + envIP + """</h3>
+ <h3>Environment name : """ +
+ settings.ICE_CI_ENVIRONMENT_NAME +
+ """</h3>
+ <h3>Environment IP : """ +
+ envIP +
+ """</h3>
<h2>Tests summary</h2>
-
+
<table id="versions" style="border:1px solid black">
<tr>
- <th scope="col" class="sortable column-testVersion">
+ <th scope="col" class="sortable column-testVersion">
<div class="text"><a href="#">Last Build Version</a></div>
<div class="clear"></div>
</th>
@@ -107,10 +119,10 @@ testsResults_mail_body = Template("""
$paramData
</tbody>
</table>
-
+
<table id="statistics" style="border:1px solid black">
<tr>
- <th scope="col" class="sortable column-testTotal">
+ <th scope="col" class="sortable column-testTotal">
<div class="text"><a href="#">Total</a></div>
<div class="clear"></div>
</th>
@@ -131,7 +143,7 @@ testsResults_mail_body = Template("""
$statisticData
</tbody>
</table>
-
+
<table id="result_list" style="border:1px solid blue">
<tr>
<th scope="col" class="sortable column-testType">
@@ -167,9 +179,8 @@ testsResults_mail_body = Template("""
$allData
</tbody>
</table>
-
+
</body>
</html>
""")
-
diff --git a/iceci/migrations/0001_initial.py b/iceci/migrations/0001_initial.py
index 5441f12..b229156 100644
--- a/iceci/migrations/0001_initial.py
+++ b/iceci/migrations/0001_initial.py
@@ -55,15 +55,18 @@ class Migration(migrations.Migration):
name='TestResults',
fields=[
('id', models.AutoField(
- auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ auto_created=True, primary_key=True,
+ serialize=False, verbose_name='ID')),
('testType', models.CharField(max_length=64)),
('testCaseName', models.CharField(max_length=64)),
('testResult', models.CharField(max_length=64)),
('testName', models.CharField(max_length=64)),
('notes', models.TextField(
blank=True, max_length=1024, null=True)),
- ('create_time', models.DateTimeField(default=datetime.datetime(
- 2016, 6, 6, 16, 50, 59, 963000), verbose_name='creation time')),
+ ('create_time', models.DateTimeField(
+ default=datetime.datetime(
+ 2016, 6, 6, 16, 50, 59, 963000),
+ verbose_name='creation time')),
],
options={
'db_table': 'ice_test_results',
diff --git a/iceci/migrations/__init__.py b/iceci/migrations/__init__.py
index 30d7152..32b601a 100644
--- a/iceci/migrations/__init__.py
+++ b/iceci/migrations/__init__.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
diff --git a/iceci/models.py b/iceci/models.py
index a448eb4..9f92eca 100644
--- a/iceci/models.py
+++ b/iceci/models.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -41,6 +41,7 @@ from django.db import models
import datetime
from django.conf import settings
+
class TestResults(models.Model):
testType = models.CharField(max_length=64)
testFeature = models.CharField(max_length=64)
@@ -48,8 +49,13 @@ class TestResults(models.Model):
testResult = models.CharField(max_length=64)
notes = models.TextField(null=True, blank=True)
duration = models.CharField(max_length=64)
- build_id = models.TextField(null=True, blank=True,default=settings.ICE_BUILD_REPORT_NUM)
- create_time = models.DateTimeField('creation time', default=datetime.datetime.now)
+ build_id = models.TextField(
+ null=True,
+ blank=True,
+ default=settings.ICE_BUILD_REPORT_NUM)
+ create_time = models.DateTimeField(
+ 'creation time', default=datetime.datetime.now)
+
class Meta:
db_table = "ice_test_results"
verbose_name_plural = 'Tests Results'
diff --git a/iceci/serializers.py b/iceci/serializers.py
index b597c10..2eaae34 100644
--- a/iceci/serializers.py
+++ b/iceci/serializers.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -39,25 +39,44 @@
from rest_framework import serializers
from .models import TestResults
+
class TestResultsModelSerializer(serializers.ModelSerializer):
class Meta:
model = TestResults
- fields = ('testType', 'testFeature', 'testName', 'testResult', 'notes', 'create_time',)
+ fields = (
+ 'testType',
+ 'testFeature',
+ 'testName',
+ 'testResult',
+ 'notes',
+ 'create_time',
+ )
+
class TestResultsSerializer(serializers.Serializer):
class Meta:
model = TestResults
- fields = ('testType', 'testFeature', 'testName', 'testResult', 'notes', 'create_time',)
-
+ fields = (
+ 'testType',
+ 'testFeature',
+ 'testName',
+ 'testResult',
+ 'notes',
+ 'create_time',
+ )
+
def create(self, validated_data):
return TestResults(**validated_data)
-
+
def update(self, instance, validated_data):
instance.testType = validated_data.get('testType', instance.testType)
- instance.testFeature = validated_data.get('testFeature', instance.testFeature)
+ instance.testFeature = validated_data.get(
+ 'testFeature', instance.testFeature)
instance.testName = validated_data.get('testName', instance.testName)
- instance.testResult = validated_data.get('testResult', instance.testResult)
+ instance.testResult = validated_data.get(
+ 'testResult', instance.testResult)
instance.notes = validated_data.get('notes', instance.notes)
instance.duration = validated_data.get('duration', instance.duration)
- instance.create_time = validated_data.get('create_time', instance.create_time)
+ instance.create_time = validated_data.get(
+ 'create_time', instance.create_time)
return instance
diff --git a/iceci/urls.py b/iceci/urls.py
index baf47d2..e52e7ce 100644
--- a/iceci/urls.py
+++ b/iceci/urls.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -39,10 +39,13 @@
from django.conf.urls import url
from . import views
-urlpatterns = [
- url(r'^testresults/?$', views.testResult_list),
- url(r'^testresults/(?P<param>.*)$', views.testResult_detail),
- url(r'^testresultstomail/(?P<param>.*)$', views.testResult_list_to_mail),
- url(r'^testresultstohtml/(?P<param>.*)$', views.testResult_list_to_html_file),
- url(r'^testresultstr/(?P<param>.*)$', views.testResultStr)
-]
+urlpatterns = [url(r'^testresults/?$',
+ views.testResult_list),
+ url(r'^testresults/(?P<param>.*)$',
+ views.testResult_detail),
+ url(r'^testresultstomail/(?P<param>.*)$',
+ views.testResult_list_to_mail),
+ url(r'^testresultstohtml/(?P<param>.*)$',
+ views.testResult_list_to_html_file),
+ url(r'^testresultstr/(?P<param>.*)$',
+ views.testResultStr)]
diff --git a/iceci/views.py b/iceci/views.py
index 6a5a9b8..8f33679 100644
--- a/iceci/views.py
+++ b/iceci/views.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -36,8 +36,7 @@
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-import logging
-from string import Template
+
from django.conf import settings
from django.http import HttpResponse
@@ -47,7 +46,7 @@ from rest_framework.renderers import JSONRenderer
from iceci import mail
from iceci.mail import testsResults_mail_body
-from services.constants import Constants, ServiceProvider
+from services.constants import ServiceProvider
from services.logging_service import LoggingServiceFactory
from .models import TestResults
@@ -59,15 +58,17 @@ LAST_BUILD_REPORT_NUM = None
# from . import mail
logger = LoggingServiceFactory.get_logger()
+
def index(request):
return HttpResponse("Hello, world. You're at the "
+ ServiceProvider.PROGRAM_NAME + " ci index.")
+
@csrf_exempt
def testResult_list(request): # List all tests, or create a new test.
if (request.method == 'DELETE' or request.method == 'PUT'):
return HttpResponse(status=405)
-
+
if request.method == 'GET':
testResult = TestResults.objects.all()
serializer = TestResultsModelSerializer(testResult, many=True)
@@ -80,26 +81,34 @@ def testResult_list(request): # List all tests, or create a new test.
serializer.save()
return JSONResponse(serializer.data, status=201)
return JSONResponse(serializer.errors, status=400)
+
+
@csrf_exempt
-def testResultStr(request,param): # List all tests, or create a new test.
+def testResultStr(request, param): # List all tests, or create a new test.
try:
testResults = TestResults.objects.filter(build_id=param)
- pass_counter, total_counter, statisticData, fail_counter = strReportForTestResults(testResults)
+ pass_counter, total_counter, statisticData, fail_counter = \
+ strReportForTestResults(testResults)
evaultaion = as_percentage_of(pass_counter, total_counter)
except Exception as e:
- msg = "Something went wrong while trying to send Test Results " + str(e)
+ msg = "Something went wrong while trying to send Test Results " + \
+ str(e)
return HttpResponse(msg, status=500)
- msg = "Total Tests: " + str(total_counter) +" Pass Tests: " + str(pass_counter)+" Fail Tests: "+ str(fail_counter) + " Statistics : " + str(evaultaion) + " BUILD_REPORT_NUM : "+str(param)
+ msg = "Total Tests: " + str(total_counter) + " Pass Tests: " + \
+ str(pass_counter) + " Fail Tests: " + str(fail_counter) +\
+ " Statistics : " + str(evaultaion) + \
+ " BUILD_REPORT_NUM : " + str(param)
return HttpResponse(msg, status=200)
+
@csrf_exempt
def testResult_detail(request, param): # Retrieve, update or delete a test.
if request.method == 'POST':
return HttpResponse(status=405)
-
+
param = param.strip("/")
-
+
try:
testResult = TestResults.objects.get(name=param)
except TestResults.DoesNotExist:
@@ -121,125 +130,183 @@ def testResult_detail(request, param): # Retrieve, update or delete a test.
testResult.delete()
return HttpResponse(status=204)
-#===============================================================================
+# =========================================================================
# def testResult_post_action(request, data):
-#
+#
# logger.debug("about to send mail to " + data['email'])
-#
+#
# html_msg = mail.mail_body.substitute(data)
-# #send mail with template
-# send_mail(mail.mail_subject,
-# '',
+# #send mail with template
+# send_mail(mail.mail_subject,
+# '',
# mail.mail_from,
-# mail.mail_to,
+# mail.mail_to,
# fail_silently=False,
# html_message=html_msg)
-#===============================================================================
+# =========================================================================
+
+
def createHtmlStrReportForTestResults(testResults):
total_counter = 0
fail_counter = 0
pass_counter = 0
statisticData = ""
- str2 = "<tr class='row1'>" + "<th class='field-testTotal'>@Total</th>" + "<td class='field-testPass'>@Pass</td>" + "<td class='field-tesFail'>@Fail</td>" + "<td class='field-testEvaultaion'>@Evaultaion</td>" + "</tr>"
+ str2 = "<tr class='row1'>" + "<th class='field-testTotal'>@Total</th>" + \
+ "<td class='field-testPass'>@Pass</td>" + \
+ "<td class='field-tesFail'>@Fail</td>" + \
+ "<td class='field-testEvaultaion'>@Evaultaion</td>" + "</tr>"
paramData = ""
- str3 = "<tr class='row2'>" + "<th class='field-testTotal'>@Version</th>" + "</tr>"
+ str3 = "<tr class='row2'>" + \
+ "<th class='field-testTotal'>@Version</th>" + "</tr>"
allData = ""
- str = "<tr class='row1'>" + "<th class='field-testType'>@TestType</th>" + "<td class='field-testFeature'>@TestFeature</td>" + "<td class='field-testName'>@TestName</td>" + "<td class='field-testResult'>@TestResult</td>" + "<td class='field-notes'>@Notes</td>" + "<td class='field-create_time nowrap'>@Creation_time</td>" + "</tr>"
- for res in testResults: # testResults
- allData += str.replace("@TestType", str(res.testType)).replace("@TestFeature", str(res.testFeature)).replace("@TestName", str(res.testName)).replace("@TestResult", str(res.testResult)).replace("@Notes", str(res.notes)).replace("@Creation_time", str(res.create_time))
+ string_temp = "<tr class='row1'>" + \
+ "<th class='field-testType'>@TestType</th>" +\
+ "<td class='field-testFeature'>@TestFeature</td>" + \
+ "<td class='field-testName'>@TestName</td>" + \
+ "<td class='field-testResult'>@TestResult</td>" + \
+ "<td class='field-notes'>@Notes</td>" + \
+ "<td class='field-create_time nowrap'>@Creation_time</td>" + "</tr>"
+ # testResults
+ for res in testResults:
+ allData += string_temp.replace(
+ "@TestType", string_temp(
+ res.testType)).replace(
+ "@TestFeature", string_temp(
+ res.testFeature)).replace(
+ "@TestName", string_temp(
+ res.testName)).replace(
+ "@TestResult", string_temp(
+ res.testResult)).replace(
+ "@Notes", string_temp(
+ res.notes)).replace(
+ "@Creation_time", string_temp(
+ res.create_time))
total_counter += 1
if (res.testResult == "PASS"):
pass_counter += 1
else:
fail_counter += 1
-
- return pass_counter, total_counter, statisticData, str2, fail_counter, paramData, str3, allData
+
+ return pass_counter, total_counter, statisticData, str2, \
+ fail_counter, paramData, str3, allData
+
def strReportForTestResults(testResults):
total_counter = 0
fail_counter = 0
pass_counter = 0
statisticData = ""
- for res in testResults: # testResults
+ for res in testResults: # testResults
total_counter += 1
if (res.testResult == "PASS"):
pass_counter += 1
else:
fail_counter += 1
-
+
return pass_counter, total_counter, statisticData, fail_counter
+
@csrf_exempt
-def testResult_list_to_mail(request,param): # List all tests, or create a new test.
- if (request.method == 'DELETE' or request.method == 'PUT' or request.method == 'POST'):
+# List all tests, or create a new test.
+def testResult_list_to_mail(request, param):
+ if (request.method == 'DELETE' or request.method ==
+ 'PUT' or request.method == 'POST'):
return HttpResponse(status=405)
data = dict()
- print("BUILD_REPORT_NUM = "+settings.ICE_BUILD_REPORT_NUM)
+ print("BUILD_REPORT_NUM = " + settings.ICE_BUILD_REPORT_NUM)
testResults = TestResults.objects.filter(build_id=param)
- pass_counter, total_counter, statisticData, str2, fail_counter, paramData, str3, allData = createHtmlStrReportForTestResults(testResults)
-
+ pass_counter, total_counter, statisticData, str2, fail_counter, \
+ paramData, str3, allData = createHtmlStrReportForTestResults(
+ testResults)
+
evaultaion = as_percentage_of(pass_counter, total_counter)
- statisticData += str2.replace("@Total", str(total_counter)).replace("@Pass", str(pass_counter)).replace("@Fail", str(fail_counter)).replace("@Evaultaion", str(evaultaion))
+ statisticData += str2.replace(
+ "@Total", str(total_counter)).replace(
+ "@Pass", str(pass_counter)).replace(
+ "@Fail", str(fail_counter)).replace(
+ "@Evaultaion", str(evaultaion))
paramData += str3.replace("@Version", str(param))
data['email'] = "rgafiulin@interwise.com"
- data['allData'] = str(allData)
- data['statisticData'] = str(statisticData)
+ data['allData'] = str(allData)
+ data['statisticData'] = str(statisticData)
data['paramData'] = str(paramData)
-
+
mail.testsResults_mail_to = data['email']
try:
- mail.sendMail(param,data['email'], data, mail.testsResults_mail_body, mail.testsResults_mail_subject)
+ mail.sendMail(
+ param,
+ data['email'],
+ data,
+ mail.testsResults_mail_body,
+ mail.testsResults_mail_subject)
except Exception as e:
- msg = "Something went wrong while trying to send Test Report mail to " + data['email'] + str(e)
+ msg = "Something went wrong while " +\
+ "trying to send Test Report mail to " + \
+ data['email'] + str(e)
return HttpResponse(msg, status=500)
serializer = TestResultsModelSerializer(testResults, many=True)
return JSONResponse(serializer.data)
+
@csrf_exempt
-def testResult_list_to_html_file(request,param):
- if (request.method == 'DELETE' or request.method == 'PUT' or request.method == 'POST'):
+def testResult_list_to_html_file(request, param):
+ if (request.method == 'DELETE' or request.method ==
+ 'PUT' or request.method == 'POST'):
return HttpResponse(status=405)
data = dict()
- print("BUILD_REPORT_NUM = "+settings.ICE_BUILD_REPORT_NUM)
+ print("BUILD_REPORT_NUM = " + settings.ICE_BUILD_REPORT_NUM)
+
+ testResults = TestResults.objects.filter(
+ build_id=settings.ICE_BUILD_REPORT_NUM)
- testResults = TestResults.objects.filter(build_id=settings.ICE_BUILD_REPORT_NUM)
+ pass_counter, total_counter, statisticData, str2, fail_counter, \
+ paramData, str3, allData = \
+ createHtmlStrReportForTestResults(testResults)
- pass_counter, total_counter, statisticData, str2, fail_counter, paramData, str3, allData = createHtmlStrReportForTestResults(testResults)
-
evaultaion = as_percentage_of(pass_counter, total_counter)
- statisticData += str2.replace("@Total", str(total_counter)).replace("@Pass", str(pass_counter)).replace("@Fail", str(fail_counter)).replace("@Evaultaion", str(evaultaion))
+ statisticData += str2.replace(
+ "@Total", str(total_counter)).replace(
+ "@Pass", str(pass_counter)).replace(
+ "@Fail", str(fail_counter)).replace(
+ "@Evaultaion", str(evaultaion))
paramData += str3.replace("@Version", str(param))
- data['allData'] = str(allData)
- data['statisticData'] = str(statisticData)
+ data['allData'] = str(allData)
+ data['statisticData'] = str(statisticData)
data['paramData'] = str(paramData)
-
+
html_msg = testsResults_mail_body.substitute(data)
- fileName = settings.LOGS_PATH+"Test_Results_"+settings.ICE_BUILD_REPORT_NUM+".html"
+ fileName = settings.LOGS_PATH + "Test_Results_" + \
+ settings.ICE_BUILD_REPORT_NUM + ".html"
try:
with open(fileName, "w") as text_file:
text_file.write(html_msg)
except Exception as e:
- msg = "Something went wrong while trying to write the tet results to html file " +fileName +" "+ str(e)
+ msg = "Something went wrong while trying to " +\
+ "write the tet results to html file " + \
+ fileName + " " + str(e)
return HttpResponse(msg, status=500)
serializer = TestResultsModelSerializer(testResults, many=True)
return JSONResponse(serializer.data)
+
def as_percentage_of(part, whole):
try:
return "%d%%" % (float(part) / whole * 100)
except (ValueError, ZeroDivisionError):
- return ""
+ return ""
+
-class JSONResponse(HttpResponse): # An HttpResponse that renders its content into JSON.
+# An HttpResponse that renders its content into JSON.
+class JSONResponse(HttpResponse):
def __init__(self, data, **kwargs):
content = JSONRenderer().render(data)
kwargs['content_type'] = 'application/json'