Skip to content

Instantly share code, notes, and snippets.

View singh1114's full-sized avatar

Ranvir Singh singh1114

View GitHub Profile
from django.test import TestCase
from scanapp.models import ScanInfo
class ScanInfoTestCase(TestCase):
def test_scan_info_added(self):
URL_scan_info = ScanInfo(scan_type="URL", is_complete=True)
local_scan_info = ScanInfo(scan_type="localscan", is_complete=False)
URL_scan_info = ScanInfo.objects.get(scan_type="URL")
{
'scan_result':OrderedDict( [
('scanned_json_result',
{
u'files':[
{
u'licenses':[
{
u'category':u'Permissive',
u'dejacode_url': u'https: //enterprise.dejacode.com/urn/urn: dje: license:apache-2.0',
@singh1114
singh1114 / background.py
Last active August 22, 2017 20:24
Python script to allow put background into the HTML created using `pandoc`
import sys
# Read the second command line argument as the file name
read_file = open(sys.argv[1], 'r')
# Read the third command line argument as the output file name
write_file = open(sys.argv[2], 'w')
temp = ''
flag = 0
@singh1114
singh1114 / param_middleware.js
Last active January 25, 2021 20:11
Node.js middleware article
const validateParams = function (requestParams) {
return function (req, res, next) {
for (let param of requestParams) {
if (checkParamPresent(Object.keys(req.body), param)) {
let reqParam = req.body[param.param_key];
if (!checkParamType(reqParam, param)) {
return res.send(400, {
status: 400,
result: `${param.param_key} is of type ` +
`${typeof reqParam} but should be ${param.type}`
@singh1114
singh1114 / routes.js
Last active May 10, 2020 20:54
schema for route parameter validation middleware.
router.post('/abc', validateParams([
{
param_key: 'abc',
required: true,
type: 'string',
validator_functions: [(param) => {return param.length === 10}]
}]), routeFunction);
@singh1114
singh1114 / test_request_param.js
Created July 7, 2019 16:24
Tests for request validation middleware
const sinon = require('sinon');
const should = require('should');
describe('validate Params middleware', () => {
it('When param is required', () => {
let nextSpy = sinon.spy();
let response = function () {};
response.send = sinon.spy();
validateParams([{
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.singh1114.springboottut</groupId>
<artifactId>rest-api</artifactId>
<version>1.0-SNAPSHOT</version>
package io.singh1114.springboottut;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class RestAPI {
public static void main(String[] args) {
SpringApplication.run(RestAPI.class, args);
}
package io.singh1114.springboottut.status;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class StatusController {
@RequestMapping("status")
public String tellStatus() {
package io.singh1114.springboottut.standard;
public class Standard {
private String standard;
private String section;
private String classTeacher;
public Standard(String standard, String section, String classTeacher) {
super();
this.standard = standard;