diff --git a/.gitignore b/.gitignore index 894a44c..634300d 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ venv.bak/ # mypy .mypy_cache/ +.git.exe +iReporterAPI2.exe +.vscode diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f6b3929 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: python + +python: "2.7" + +scripts: python -m pytest --cov=tests + + +install: pip install -r requirements.txt + +after_success: coveralls \ No newline at end of file diff --git a/README.md b/README.md index 41a8457..a8fdf16 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..238373f --- /dev/null +++ b/api/__init__.py @@ -0,0 +1,3 @@ +from flask import Flask +from api import routes +app = Flask(__name__) \ No newline at end of file diff --git a/api/models.py b/api/models.py new file mode 100644 index 0000000..e1d995c --- /dev/null +++ b/api/models.py @@ -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 + } diff --git a/api/routes.py b/api/routes.py new file mode 100644 index 0000000..4ebe2cf --- /dev/null +++ b/api/routes.py @@ -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 + + + + + + + + + + + + + + + + + + + + + + diff --git a/app.py b/app.py new file mode 100644 index 0000000..2d9ecd3 --- /dev/null +++ b/app.py @@ -0,0 +1,4 @@ +from api.routes import app + +if __name__ == "__main__": + app.run(debug = True) \ No newline at end of file diff --git a/coverage.yml b/coverage.yml new file mode 100644 index 0000000..5ae0821 --- /dev/null +++ b/coverage.yml @@ -0,0 +1 @@ +repo_token: CjaAwOWxXj8kSfulofMGrBmaW7uBGCv58 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1510be4 --- /dev/null +++ b/requirements.txt @@ -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 diff --git a/test.py b/test.py new file mode 100644 index 0000000..2b4e0a9 --- /dev/null +++ b/test.py @@ -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) \ No newline at end of file