How to create a 500 error on an rest API for error testing purpose? - node.js

I am writing some test code for my rest api using nodejs and chai.
I would like to create a 500 error on purpose to be sure my API react well, but I have no idea on how to do that.
Any help or tips about best practices would be really appreciated.
Thanks in advance

Try this URL, this is dedicated for testing purpose :
https://httpstat.us/500
Or expose a php script with garbage in it, like :
<?php
foobarbase

You can use following syntax:
res.status(500).json({your message});

Related

what is difference between `django.test.APITestCase` and `rest_framework.test.TestCase` in `python-django`

What is the major difference in these test classes django.test.TestCase and rest_framework.test.APITestCase . which is Better to test my views.py ?
can you suggest me documentations to understand about these.
Thank you in advance. :-)
Difference between rest_framework.test.APITestCase and django.test.testcases.TestCase in HTTP Client they use (source: github).
With rest_framework APIClient it easier to test API than with Django Client. For example, less work with json responses. See more: http://www.django-rest-framework.org/api-guide/testing/
APITestCase in rest_framework.test is to test the api's in the rest. It is specific for the api operations and api calls.
Django.test.TestCase is used to test the Django classes.

How do i access the Phabricator Maniphest restful APIs?

I'm trying to programmatically create tasks/bugs on Maniphest: https://www.phacility.com/phabricator/maniphest/
but i can't quite seem to find a RESTful API that can do this.
am i totally missing out on something? or does there not currently exist one
Conduit (https://secure.phabricator.com/book/phabricator/article/conduit/) should work for you. There is a method called createtask (looks like https://secure.phabricator.com/conduit/method/maniphest.createtask/) that is exactly what you are looking for.
You can access phabricator's api, to create task ,query user info etc.
here is the demo for access https api by postman .
Note: for multi value field such as "ccPHIDs" , you should use format like the image.
but in conduit UI Test. you have to use json format, like this: ["PHID-PROJ-xxx3", "PHID-PROJ-xx12"]
phabricator's API is the wrost api set, I have used by now. so sick...

Looking for sequelize.js REST API generator with associations support

Is there any node.js module which would provide full REST api sequelize?
Which must follow associations, so for example if I have tables testsuites (hasMany testcases) and testcases, than the api will allow me to do: get /api/testsuite/1/testcases and it will do all the magic for me?
I checked sequelize-restful, but does not seems to work this way :(
See below libraries can help you in generating REST API with sequelize
1.https://github.com/dchester/epilogue
2.https://github.com/sequelize/sequelize-restful
Example: https://github.com/pjanaya/nodejs-express4-sequelize-restful

Can I monkey patch the phantomjs browser api with execute_script?

Im trying to test an application with some native JavaScript features disabled e.g. querySelector ...
So I thought this might work before the call to visit:
page.execute_script("document.querySelector = null")
but it doesn't work, any thoughts on how I could achieve this?
Cheers
John
Have a look at the :extensions option. This allows you to define a JS file which gets preloaded into the browser.

Problems consuming web service from groovy script

I'm having some problems trying to consume a web service from a groovy script. I'm using WSClient lib.
If I execute the example posted at groovy's website:
#Grab(group='org.codehaus.groovy.modules', module='groovyws', version='0.5.2')
import groovyx.net.ws.WSClient
proxy = new WSClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", this.class.classLoader)
proxy.initialize()
result = proxy.CelsiusToFahrenheit(0)
println "You are probably freezing at ${result} degrees Farhenheit"
Works fine, but once I try to consume another service it crashes with this error:
INFO: Created classes: javac: no
source files Usage: javac
use -help for a list
of possible options 07-jul-2010
9:55:57
org.apache.cxf.endpoint.dynamic.DynamicClientFactory
createC lient GRAVE: Could not compile
java files for http://xxx:8080/x/services/xxx?wsdl.
Caught:
groovyx.net.ws.exceptions.InvokeException:
java.lang.NullPointerExceptio n
at groovy-ws.run(groovy-ws.groovy:13)
The code it's exactly the same (apart from wsdl url which correponds to one internal server). The main difference I found between them is that the second wsdl is RPC style while the first one isn't. I've read that there's some problems to consume RPC like webservices from groovy with WSClient lib. ¿Does anyone know how to consume RPC like webservices with WSClient? ¿Could anyone enlighten me please?
Thank you very much
There seems to be a bug in GroovyWS, documented here on their JIRA.
It's currently Unresolved and was added in 2010.
I'm personally getting the same error with anything other than the trivial example service, with Groovy 1.8.0, GroovyWS 0.5.2
Hopefully somebody can find the issue and fix it - WSClient could definitely be a great alternative to traditional CXF/JAXB
Don't use WSClient is the best answer I can give you. For anything but simple services I've found WSClient does not work well. Instead use what ever java based web service client your most comfortable with and call it from Groovy.

Resources