Skip to content

Instantly share code, notes, and snippets.

@victorfsf
Last active March 26, 2018 18:48
Show Gist options
  • Save victorfsf/f1e0b0fa3f05b731b573e1f0083e7c07 to your computer and use it in GitHub Desktop.
Save victorfsf/f1e0b0fa3f05b731b573e1f0083e7c07 to your computer and use it in GitHub Desktop.
Mocking WS for MJ
from flask import Flask
from flask import request
from flask import Response
from functools import wraps
import json
app = Flask(__name__)
def login_required(f):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not (
auth.username == 'user' and
auth.password == 'pass'
):
return Response(
'Could not verify your access level for that URL.\n'
'You have to login with proper credentials', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'}
)
return f(*args, **kwargs)
return decorated
@app.route("/crop/create/", methods=['POST', 'PUT'])
@login_required
def crop_create():
data = json.loads(request.data)
return json.dumps({
'crops_id': list(
range(1, data['jobs_count'] // data['crop_limit'] + 2)
),
'exec_id': data['exec_id']
})
@app.route("/justica/services/", methods=['GET'])
@login_required
def services():
return json.dumps({
'4.5': [4, 5, 6],
'8.19': [7, 8, 9, 10],
'8.26': [1, 2, 3, 11, 12]
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment