- The
dots(.)
on the file names represent the directory hierarchy e.g.js.cms.[your_module].js
representsjs/cms/[your_module].js
. - REPLACE the current
js/utils.js
file with the one on this gist. The changes on this file allow for synchronization of cms data loading for your module. - Follow the same naming convection for your module scripts. If your script
belongs to a broad module create a subdirectory for the module e.g.
js/cms/repository/documents.js
- ENSURE you place the link to your script on the section to that is loaded by jquery.
e.g.
documents.js
is imported insidedocuments.html
ofresources
. - CREATE
js/cms/utils.js
and add the content on this gist. This will prevent multiple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl http://192.168.1.1/api/device/information | |
<?xml version="1.0" encoding="UTF-8"?> | |
<response> | |
<DeviceName>E303</DeviceName> | |
<SerialNumber>K3XBYAxxxxxxxxxx</SerialNumber> | |
<Imei>xxxxxxxxxxxxxxx</Imei> | |
<Imsi>xxxxxxxxxxxxxxx</Imsi> | |
<Iccid>xxxxxxxxxxxxxxxxxxxx</Iccid> | |
<Msisdn></Msisdn> | |
<HardwareVersion>CH2E303SM</HardwareVersion> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unittest import TestCase | |
from rest_framework import status | |
from rest_framework.test import APIClient | |
class BaseTestCase(TestCase): | |
def setUp(self): | |
self.client = APIClient() | |
def post_login(self, username='johndoe', password='P@$$word'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the main app file | |
import express from "express"; | |
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db) | |
import authenticate from "./authentication"; // middleware for doing authentication | |
import permit from "./permission"; // middleware for checking if user's role is permitted to make request | |
const app = express(), | |
api = express.Router(); | |
// first middleware will setup db connection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('supertest'); | |
const request = supertest(app); | |
describe('Articles', function () { | |
it('should allow users to list all articles', function (done) { | |
request.get('/articles').expect(200, done) | |
}); | |
it('should allow users to get one article', function (done) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('supertest'); | |
describe('Articles', function () { | |
it('should allow users to list all articles', function (done) { | |
request(app).get('/articles').expect(200, done) | |
}); | |
it('should allow users to get one article', function (done) { | |
request(app).get('/articles/2').expect(200, done) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('supertest'); | |
const request = supertest(app); | |
describe('Articles', function () { | |
it('should allow users to list all articles', function (done) { | |
request | |
.get('/articles') | |
.set('authorization', generateAuthToken()) | |
.expect(200, done) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test/article.spec.js | |
import app from './testUtils/app'; | |
describe('Articles', () => { | |
describe('GET', () => { | |
it('should not allow unauthenticated users to list all articles', async () => { | |
const res = await app.get('/articles'); | |
expect(res.status).toBe(401); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test/article.spec.js | |
var app = require('./testUtils/app'); | |
describe('Articles', function() { | |
describe('GET', function() { | |
it('should not allow unauthenticated users to list all articles', function(done) { | |
app.get('/articles').expect(401, done); | |
}); | |
it('should allow authenticated users to list all articles', function(done) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test/testUtils/app.js | |
var supertest = require('supertest'); | |
var appDef = require('../../src/app'); | |
var User = require('../../src/models').User; | |
var generateAuthToken = require('../../src/utils').generateAuthToken; | |
var app = { | |
client: supertest(appDef), |
OlderNewer