I have read that we can generate test reports in sikuli using HTML test runner.
I have installed SIKULI X and have script for which I want to generate reports.
Is there any particular version of html test runner I need to install for this version of Sikuli ?
I have downloaded the "html-testRunner-1.0.3.tar.gz (md5)" from the path "https://pypi.python.org/pypi/html-testRunner".
Can anyone guide me on how I should install and integrate the same to my script ?
For me, I downloaded HTMLTestRunner.py from this website and put somewhere in my computer. Say if I put it in ~/Downloads/HTMLTestRunner folder, I just need to tell my sikulix program to find the path into that folder, and import HTMLTestRunner afterwards. This part is as follows:
import sys
_path = r"Downloads/HTMLTestRunner"
sys.path.append(_path)
import HTMLTestRunner
After that, everything goes as usual. Lemme try to make one example below.
import unittest
import sys
_path = r"Downloads/HTMLTestRunner"
sys.path.append(_path)
import HTMLTestRunner
class TestDemo(unittest.TestCase):
def testA(self):
assert True
def testB(self):
assert False
class TestDemo2(unittest.TestCase):
def testC(self):
assert True
def testD(self):
assert True
def suite():
suite = unittest.TestSuite()
# TestDemo
suite.addTest(TestDemo('testA'))
suite.addTest(TestDemo('testB'))
# TestDemo2
suite.addTest(TestDemo2('testC'))
suite.addTest(TestDemo2('testD'))
return suite
if __name__ == "__main__":
suite = suite()
unittest.TextTestRunner(verbosity=2)
output = open("results.html", 'w')
runner = HTMLTestRunner.HTMLTestRunner(stream=output, title='Test Report', description='This is a test')
runner.run(suite)
When you run it, you will get the following report
Hope it helps
I'm trying to make bulk data downloads by serializing my entire database as JSON. The drf documentation on serializers has a section that says you can simply do:
from rest_framework.renderers import JSONRenderer
serializer = CommentSerializer(comment)
json = JSONRenderer().render(serializer.data)
Unfortunately, this doesn't work for HyperLinked relationships. When you try to do it with them, you get something like:
AssertionError: HyperlinkedIdentityField requires the request in the serializer context. Add context={'request': request} when instantiating the serializer.
So, I figured out I can add context attribute, like:
r = Request(request=HttpRequest())
context = dict(request=r)
serializer = CommentSerializer(comment, context=context)
json = JSONRenderer().render(serializer.data)
Which then returns the error:
django.core.exceptions.ImproperlyConfigured: Could not resolve URL for hyperlinked relationship using view name "opinioncluster-detail". You may have failed to include the related model in your API, or incorrectly configured the lookup_field attribute on this field.
I know this API works properly when it's called from the browser, but I can't get past this when I call it as above. Something that's automatic from the browser doesn't happen when you render it manually.
Any ideas?
First edit
Here's another strategy that seemed promising because it would add the path to my request object:
r = Request(request=RequestFactory().get(reverse('comment-list', kwargs={'version': 'v3'})))
context = dict(request=r)
serializer = CommentSerializer(comment, context=context)
json = JSONRenderer().render(serializer.data)
That returns the same problem as if I hadn't defined a path to the request:
django.core.exceptions.ImproperlyConfigured: Could not resolve URL for hyperlinked relationship using view name "opinioncluster-detail". You may have failed to include the related model in your API, or incorrectly configured the lookup_field attribute on this field.
Second Edit
As I said in my comments, I'm fairly certain my serializers and views aren't to blame, since they work perfectly fine via the browser. Nevertheless, here they are. If you're truly generous, the full serializers, filters, and codebase is online.
View:
class OpinionClusterViewSet(LoggingMixin, viewsets.ModelViewSet):
queryset = OpinionCluster.objects.all()
serializer_class = OpinionClusterSerializer
filter_class = OpinionClusterFilter
ordering_fields = (
'date_created', 'date_modified', 'date_filed', 'citation_count',
'date_blocked',
)
Serializer:
class OpinionClusterSerializer(DynamicFieldsModelSerializer,
serializers.HyperlinkedModelSerializer):
absolute_url = serializers.CharField(source='get_absolute_url',
read_only=True)
panel = serializers.HyperlinkedRelatedField(
many=True,
view_name='judge-detail',
read_only=True,
)
non_participating_judges = serializers.HyperlinkedRelatedField(
many=True,
view_name='judge-detail',
read_only=True,
)
docket = serializers.HyperlinkedRelatedField(
many=False,
view_name='docket-detail',
read_only=True,
)
sub_opinions = serializers.HyperlinkedRelatedField(
many=True,
view_name='opinion-detail',
read_only=True,
)
class Meta:
model = OpinionCluster
This management command creates a MockRequest to be used in a non-browser environment and should allow you to create your JSON:
from django.core.management.base import BaseCommand
from django.http import HttpRequest
from rest_framework.renderers import JSONRenderer
from rest_framework.request import Request
from comments.models import Comment
from comments.serializers import CommentSerializer
class MockRequest(HttpRequest):
def __init__(self):
super(MockRequest, self).__init__()
self.setup_host()
def setup_host(self):
# Required to give absolute urls in output
self.META['HTTP_HOST'] = 'localhost:8000'
class Command(BaseCommand):
help = 'Export JSON'
def handle(self, *args, **options):
request = MockRequest()
serializer_context = {
'request': Request(request),
}
comment = Comment.objects.first()
serializer = CommentSerializer(comment, context=serializer_context)
json = JSONRenderer().render(serializer.data)
print(json)
To remove the hard coded domain you could use the Sites framework to power the host name:
def setup_host(self):
from django.contrib.sites.models import Site
site = Site.objects.get_current()
self.META['HTTP_HOST'] = site.domain
After digging quite deeply into the code, I finally figured this out:
r = RequestFactory().request()
r.version = 'v3'
r.versioning_scheme = URLPathVersioning()
context = dict(request=r)
renderer = JSONRenderer()
json_str = renderer.render(
serializer(item, context=context).data,
accepted_media_type='application/json; indent=2',
)
This seems to work, but the HyperLinkRelated values in the JSON that is serialized have the server set to testserver. I could get around that by setting:
r.META['SERVER_NAME']
But I also need to set r.scheme to https, which doesn't seem to be possible (I get an error that r.scheme cannot be set).
I'm pretty close though, so this is going to have to serve as an answer for now.
I am doing a development to integrate a non Java OMS system with QuickFIX/J to send buy/sell orders to multiple brokerage systems .
I have written the belog logic to send the messages
I have written this under main function which is in the same class created by implementing Application "public class Initiator implements Application"
InputStream inp = InitiatorSocket.class.getResourceAsStream("test.cfg");
SessionSettings sessionSetting = new SessionSettings(inp);
Application myApp = new Initiator();
FileStoreFactory factory = new FileStoreFactory(sessionSetting);
ScreenLogFactory sfactory = new ScreenLogFactory(sessionSetting);
DefaultMessageFactory defaultMsgFactory = new DefaultMessageFactory();
initiator = new SocketInitiator(myApp, factory, sessionSetting,sfactory,defaultMsgFactory);
initiator.start();
SessionID sessionId = initiator.getSessions().get(0);
I am using the below code to send messages after continuously listening a directory using while Loop.
while(true)
{
readFilefromSrcDirectory();
prepareFixMessage();
Session.sendToTarget(fixMessage, sessionId);
}
My above code is getting executed while debugging but when I run it normally, the Session.sendToTarget(fixMessage, sessionId); and other file read related logic which is next to initiator.start(); is not getting executed.
Kindly note that the same above code is getting executed if we add some console print statements such as System.out.print("Test");
Please help me.
Are your test.cfg settings between debug and run different? I would add console print statements everywhere and work out exactly where the runtime is failing.
I am getting a ClassCastException when I try to get class items
from the following list iterator. The web application is running on TC7,
Win OS
List<CustomerList> aaData = customerlistDao.getCustomerList();
putting data in a JSON form that DataTables recognizes
Iterator<CustomerList> itr = aaData.iterator();
cl = itr.next();
We are using Quartz scheduling in our application to schedule jobs to generate and send self-audit emails.
I am trying to generate the processed emailBody from the email Template using GroovyPagesTemplateEngine.
The emailTemplate is processed properly into EmailBody when the processing does not use Quartz scheduling. But when a job is run using Quartz for emailtemplate processing the
groovyPagesTemplateEngine is failing in quartz job with error
[12:10:55 AM] Mandar: java.lang.IllegalStateException: TemplateEngine not initialised correctly, no [resourceLoader] specified!
this what I am trying to do
def getInfo(){
MockHttpServletRequest servletRequest = new MockHttpServletRequest()
GrailsWebRequest grailsWebRequest = new GrailsWebRequest(servletRequest, new MockHttpServletResponse(), new MockServletContext())
grailsWebRequest.setAttribute(GrailsApplicationAttributes.WEB_REQUEST, grailsWebRequest, 0)
RequestContextHolder.requestAttributes = grailsWebRequest
GroovyPagesTemplateEngine engine = new GroovyPagesTemplateEngine()
StringWriter sw = new StringWriter()
PrintWriter pw = new PrintWriter(sw)
engine.createTemplate('myteplate').make(model).writeTo(pw)
println sw.toString()
return sw.toString()
}
I am aware that the Quartz scheduler does not have a WebRequest associated with it. and I am thinking that the email processing is failing due to this.
How can I process the emailtemplate to generate the emailBody content when the scheduled job is run, and not by logging into the application from UI.
Thanks in advance.
The resourceLoader is not initialized in the groovyPagesTemplateEngine as you are just creating a new instance of it directly. Instead, you should let Spring's dependency injection do the job for you.
Add the following line to your service:
class YourService {
def groovyPagesTemplateEngine
def getInfo(){
GroovyPagesTemplateEngine engine = groovyPagesTemplateEngine
//your code here
}
}
You can try using the steps mentioned in http://www.intelligrape.com/blog/2010/12/27/request-mocking-to-use-groovypagestemplateengine-in-backend-threads/
If you are on Grails 2.0.x, you get a bean named groovyPageRenderer, which can be used outside the context of a web request as well. For more details, http://mrhaki.blogspot.in/2012/03/grails-goodness-render-gsp-views-and.html