Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/
.git.exe
iReporterAPI2.exe
.vscode
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python

python: "2.7"

scripts: python -m pytest --cov=tests


install: pip install -r requirements.txt

after_success: coveralls
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# iReporterAPI
Corruption is a huge bane to Africa’s development. African countries must develop novel and localised solutions that will curb this menace, hence the birth of iReporter. iReporter enables any/every citizen to bring any form of corruption to the notice of appropriate authorities and the general public. Users can also report on things that needs government intervention
Corruption is a huge bane to Africa’s development. African countries must develop novel and localised solutions that will curb this menace, hence the birth of iReporter. iReporter enables any/every citizen to bring any form of corruption to the notice of appropriate authorities and the general public. Users can also report on things that needs government intervention. iReporter is an App that is aimed at solving this.
3 changes: 3 additions & 0 deletions api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from flask import Flask
from api import routes
app = Flask(__name__)
33 changes: 33 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from datetime import datetime

my_red_flags = []


class Redflag:

def __init__(self, createdBy, _type, place, status, Images, Videos, comment):

self._id = len(my_red_flags) + 1
self.createdOn = datetime.now()
self.createdBy = createdBy
self.type = _type
self.location = place
self.status = status
self.Images = Images
self.Videos = Videos
self.comment = comment

def format_record(self):

return {

"id": self._id,
"createdOn": self.createdOn,
"createdBy": self.createdBy,
"type": self.type,
"location": self.location,
"status": self.status,
"Images": self.Images,
"Videos": self.Videos,
"comment": self.comment
}
63 changes: 63 additions & 0 deletions api/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from flask import Flask, jsonify, request
from api.models import Redflag, my_red_flags


app = Flask(__name__)

@app.route("/")
def hello_world():
return "Hello Kato"


#API end point to create a red-flag record
@app.route("/api/v1/red-flags", methods=["POST"])
def create_redflag():
if not request.json:
return jsonify({
"Error": "There is no data returned from the request",
"status": 400
}), 400
data = request.get_json()
if 'createdBy' not in data or 'comment' not in data or 'type' not in data or 'location' not in data or 'status' not in data:
return jsonify({'status': 400, 'Error': 'The information is missing'}), 400
red_flag = Redflag(
data["createdBy"], data["type"],
data["location"], data["status"], data["Images"],
data["Videos"], data["comment"]
)
my_red_flags.append(
red_flag.format_record()
)
if len(my_red_flags) == 0:
return jsonify({
"status": 400,
"Error": "Invalid request"
})
return jsonify({
"status": 201,
"data": [{
"id": red_flag._id,
"Message": "Created red-flag record"
}]}), 200






















4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from api.routes import app

if __name__ == "__main__":
app.run(debug = True)
1 change: 1 addition & 0 deletions coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: CjaAwOWxXj8kSfulofMGrBmaW7uBGCv58
34 changes: 34 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
asn1crypto==0.24.0
astroid==1.6.5
backports.functools-lru-cache==1.5
certifi==2018.11.29
cffi==1.11.5
chardet==3.0.4
Click==7.0
colorama==0.4.1
configparser==3.5.0
coverage==4.5.2
coveralls==1.5.1
cryptography==2.4.2
docopt==0.6.2
enum34==1.1.6
Flask==1.0.2
futures==3.2.0
idna==2.8
ipaddress==1.0.22
isort==4.3.4
itsdangerous==1.1.0
Jinja2==2.10
lazy-object-proxy==1.3.1
MarkupSafe==1.1.0
mccabe==0.6.1
pycparser==2.19
pylint==1.9.3
pyOpenSSL==18.0.0
PyYAML==3.13
requests==2.21.0
singledispatch==3.4.0.3
six==1.12.0
urllib3==1.24.1
Werkzeug==0.14.1
wrapt==1.10.11
27 changes: 27 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
import json
from api.routes import app, my_red_flags

class BaseTest(unittest.TestCase):
def setUp(self):
self.client = app.test_client()


self.sample_record_data = {
"createdBy": "hassan",
"type": "red-flag",
"location": "Jinja",
"status": "Under investigation ",
"Images": "fed.png",
"Videos": "gfgg.mp4",
"comment": "This is good"
}

class RedFlagTest(BaseTest):
def test_create_red_flag(self):
response = self.client.post(
"/api/v1/red-flags",
data = json.dumps(self.sample_record_data),
content_type = "application/json"
)
self.assertEqual(response.status_code, 200)