From 1d6eba31d00eb9901e8de6ab98f0cd89bd03cef8 Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 21:15:54 +0300 Subject: [PATCH 01/12] [Chore #161308201] Add files for build enviroment --- .gitignore | 7 +++++++ .travis.yml | 13 +++++++++++++ app/__init__.py | 0 app/api/__init__.py | 0 app/api/v1/__init__.py | 0 app/api/v1/models.py | 0 app/api/v1/utils.py | 0 app/api/v1/views.py | 0 app/tests/v1/__init__.py | 0 app/tests/v1/test_endpoints.py | 0 instance/__init__.py | 0 instance/config.py | 0 procfile | 0 run.py | 0 14 files changed, 20 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 app/__init__.py create mode 100644 app/api/__init__.py create mode 100644 app/api/v1/__init__.py create mode 100644 app/api/v1/models.py create mode 100644 app/api/v1/utils.py create mode 100644 app/api/v1/views.py create mode 100644 app/tests/v1/__init__.py create mode 100644 app/tests/v1/test_endpoints.py create mode 100644 instance/__init__.py create mode 100644 instance/config.py create mode 100644 procfile create mode 100644 run.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf6dbf4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.pyc + +*__pycache__ +/env +.coverage +requirements.txt +.env diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2fe84b4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: python +python: +- "3.6" +cache: pip +install: +- pip install -r requirements.txt +before_script: + - export SECRET_KEY="secret" +script: +- pytest +- pytest --cov=app +after_success: +- coveralls diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/__init__.py b/app/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/v1/__init__.py b/app/api/v1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/v1/models.py b/app/api/v1/models.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/v1/utils.py b/app/api/v1/utils.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/v1/views.py b/app/api/v1/views.py new file mode 100644 index 0000000..e69de29 diff --git a/app/tests/v1/__init__.py b/app/tests/v1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/tests/v1/test_endpoints.py b/app/tests/v1/test_endpoints.py new file mode 100644 index 0000000..e69de29 diff --git a/instance/__init__.py b/instance/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/instance/config.py b/instance/config.py new file mode 100644 index 0000000..e69de29 diff --git a/procfile b/procfile new file mode 100644 index 0000000..e69de29 diff --git a/run.py b/run.py new file mode 100644 index 0000000..e69de29 From 672ba042c7d129c59d1f5e0a3405dbc750e1e4e1 Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 21:17:54 +0300 Subject: [PATCH 02/12] [Chore #161308201] Add files for build enviroment --- .gitignore | 1 - requirements.txt | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index cf6dbf4..214c48f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ *__pycache__ /env .coverage -requirements.txt .env diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..57ffa2c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,22 @@ +aniso8601==3.0.2 +atomicwrites==1.2.1 +attrs==18.2.0 +Blueprints==2.3.0.2 +Click==7.0 +coverage==4.5.1 +Flask==1.0.2 +Flask-RESTful==0.3.6 +funcsigs==1.0.2 +itsdangerous==0.24 +Jinja2==2.10 +MarkupSafe==1.0 +more-itertools==4.3.0 +pathlib2==2.3.2 +pluggy==0.8.0 +py==1.7.0 +PyJWT==1.6.4 +pytest==3.9.1 +pytz==2018.5 +scandir==1.9.0 +six==1.11.0 +Werkzeug==0.14.1 From 36edfe5b0f4e878409101a4168ac5e6dee8942c0 Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 21:38:38 +0300 Subject: [PATCH 03/12] [Feature #161325459] Add test for sign up --- .gitignore | 1 - app/tests/v1/test_endpoints.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 214c48f..b17bfec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.pyc - *__pycache__ /env .coverage diff --git a/app/tests/v1/test_endpoints.py b/app/tests/v1/test_endpoints.py index e69de29..7041d17 100644 --- a/app/tests/v1/test_endpoints.py +++ b/app/tests/v1/test_endpoints.py @@ -0,0 +1,34 @@ +import unittest +import json +from app import create_app +from instance.config import app_config +from app.api.v1.models import collapse + + +class TestEndpoints(unittest.TestCase): + """docstring for setting up testEndpoints.""" + def setUp(self): + self.app = create_app(app_config['testing']) + self.test_client = self.app.test_client() + self.app_context = self.app.app_context() + self.user_admin_details = json.dumps({ + "name": "kevin", + "email": "kevin@email.com", + "password": "kevin", + "role": "admin" + }) + admin_signup = self.test_client.post( + "/storemanager/api/v1/auth/signup", + data=self.user_admin_details, headers={ + 'content-type': 'application/json'}) + + def tearDown(self): + """removes all the context and dicts""" + print(collapse) + collapse() + self.app_context.pop() + def test_signup(self): + response = self.test_client.post("/storemanager/api/v1/auth/signup", + data=self.user_admin_details, + content_type='application/json') + self.assertEqual(response.status_code, 201) From c9955b2df9685b60f3c18634da3733d833deb4ff Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 22:30:28 +0300 Subject: [PATCH 04/12] [Feature #161325459] Add endpoint for signup --- app/__init__.py | 15 +++++++++++++++ app/api/v1/__init__.py | 8 ++++++++ app/api/v1/models.py | 23 +++++++++++++++++++++++ app/api/v1/views.py | 34 ++++++++++++++++++++++++++++++++++ app/tests/__init__.py | 0 app/tests/v1/test_endpoints.py | 14 ++++++++++++-- instance/config.py | 20 ++++++++++++++++++++ run.py | 6 ++++++ 8 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 app/tests/__init__.py diff --git a/app/__init__.py b/app/__init__.py index e69de29..d7de1ab 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -0,0 +1,15 @@ +from flask import Flask, Blueprint +from flask_restful import Api +from instance.config import app_config +from .api.v1 import myblue + +def create_app(config_name): + app = Flask(__name__, instance_relative_config=True) + app.config.from_object(app_config["development"]) + app.config.from_pyfile('config.py') + app.register_blueprint(myblue) + + app.config["TESTING"] = True + + + return app diff --git a/app/api/v1/__init__.py b/app/api/v1/__init__.py index e69de29..4eb387e 100644 --- a/app/api/v1/__init__.py +++ b/app/api/v1/__init__.py @@ -0,0 +1,8 @@ +from flask import Flask, Blueprint +from flask_restful import Api, Resource +from .views import SignUp +myblue = Blueprint("api", __name__, url_prefix="/storemanager/api/v1") + +api = Api(myblue) +api.add_resource(SignUp, '/auth/signup') +# api.add_resource(Login, '/auth/login') diff --git a/app/api/v1/models.py b/app/api/v1/models.py index e69de29..b88052a 100644 --- a/app/api/v1/models.py +++ b/app/api/v1/models.py @@ -0,0 +1,23 @@ +users = [] + + +class UserAuth(): + def __init__(self, name, email, password, role): + self.name = username + self.email = email + self.password = password + self.role = role + + def save_user(self): + id = len(users) + 1 + user = { + 'id' : self.id, + 'name' : self.name, + 'email': self.email, + 'password' : self.password, + 'role' : self.role + } + users.append(user) + +def collapse(): + users = [] diff --git a/app/api/v1/views.py b/app/api/v1/views.py index e69de29..b04d9ff 100644 --- a/app/api/v1/views.py +++ b/app/api/v1/views.py @@ -0,0 +1,34 @@ +from flask import jsonify, make_response, request +from flask_restful import Resource +from functools import wraps +from instance.config import Config +import datetime +import jwt +import json + +from .models import * + + +class SignUp(Resource): + def post(self): + data = request.get_json() + id = len(users) + 1 + name = data["name"] + email = data["email"] + password = data["password"] + role = data["role"] + + user = { + "id": id, + "name": name, + "email": email, + "password": password, + "role": role + } + users.append(user) + return make_response(jsonify({ + "Status": "ok", + "Message": "user successfully created", + "user": users + } + ), 201) diff --git a/app/tests/__init__.py b/app/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/tests/v1/test_endpoints.py b/app/tests/v1/test_endpoints.py index 7041d17..fb32223 100644 --- a/app/tests/v1/test_endpoints.py +++ b/app/tests/v1/test_endpoints.py @@ -21,12 +21,22 @@ def setUp(self): "/storemanager/api/v1/auth/signup", data=self.user_admin_details, headers={ 'content-type': 'application/json'}) + self.user_attendant_details = json.dumps({ + "name": "brian", + "email": "brian@email.com", + "password": "brian", + "role": "attendant" + }) + attendant_signup = self.test_client.post("/storemanager/api/v1/auth/signup", + data=self.user_attendant_details, + headers={ + 'content-type': 'application/json' + }) def tearDown(self): """removes all the context and dicts""" - print(collapse) collapse() - self.app_context.pop() + # self.app_context.pop() def test_signup(self): response = self.test_client.post("/storemanager/api/v1/auth/signup", data=self.user_admin_details, diff --git a/instance/config.py b/instance/config.py index e69de29..3f20a36 100644 --- a/instance/config.py +++ b/instance/config.py @@ -0,0 +1,20 @@ +class Config(): + + debug = False + SECRET_KEY = "secretkey" + +class Develop(Config): + """Configuration for the development enviroment""" + debug = True + + +class Testing(Config): + """Configuration for the testing enviroment""" + WTF_CSRF_ENABLED = False + debug = True + + +app_config={ +"development": Develop, +"testing": Testing +} diff --git a/run.py b/run.py index e69de29..24df9c5 100644 --- a/run.py +++ b/run.py @@ -0,0 +1,6 @@ +from app import create_app + +app = create_app("development") + +if __name__ == '__main__': + app.run() From 891d2c76e2cda3138dd3310ac085380c4738acbd Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 22:43:37 +0300 Subject: [PATCH 05/12] [Feature #161309671] Add failing test for login endpoint --- app/tests/v1/test_endpoints.py | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/app/tests/v1/test_endpoints.py b/app/tests/v1/test_endpoints.py index fb32223..afca114 100644 --- a/app/tests/v1/test_endpoints.py +++ b/app/tests/v1/test_endpoints.py @@ -32,6 +32,25 @@ def setUp(self): headers={ 'content-type': 'application/json' }) + self.login_admin = json.dumps({ + "email": "kevin@email.com", + "password": "kevin" + }) + admin_login = self.test_client.post("/storemanager/api/v1/auth/login", + data=self.login_admin, headers={ + 'content-type': 'application/json' + }) + self.token_for_admin = json.loads(admin_login.data.decode())["token"] + self.login_attendant = json.dumps({ + "email": "brian@email.com", + "password": "brian" + }) + attendant_login = self.test_client.post("/storemanager/api/v1/auth/login", + data=self.login_attendant, + headers={ + 'content-type': 'application/json' + }) + self.token_for_attendant = json.loads(attendant_login.data.decode())["token"] def tearDown(self): """removes all the context and dicts""" @@ -42,3 +61,34 @@ def test_signup(self): data=self.user_admin_details, content_type='application/json') self.assertEqual(response.status_code, 201) + def test_empty_login(self): + data = json.dumps( + { + "email": "", + "password": "" + } + ) + response = self.test_client.post("storemanager/api/v1/auth/login", + data=data, + content_type='application/json') + self.assertEqual(response.status_code, 401) + + def test_wrong_login(self): + data = json.dumps({ + "email": "blah@email.com", + "password": "blahblah" + }) + response = self.test_client.post("storemanager/api/v1/auth/login", + data=data, + content_type='application/json') + + self.assertEqual(response.status_code, 401) + + def test_login_granted(self): + + response = self.test_client.post("/storemanager/api/v1/auth/login", + data=self.login_admin, + headers={ + 'content-type': 'application/json' + }) + self.assertEqual(response.status_code, 200) From 360ef12cda953f66bb4a48245a11c108e1f0a7ef Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 22:48:56 +0300 Subject: [PATCH 06/12] [Feature #161309671] Add login endpoint for tests to pass --- app/api/v1/__init__.py | 4 ++-- app/api/v1/views.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/app/api/v1/__init__.py b/app/api/v1/__init__.py index 4eb387e..7c5e3c9 100644 --- a/app/api/v1/__init__.py +++ b/app/api/v1/__init__.py @@ -1,8 +1,8 @@ from flask import Flask, Blueprint from flask_restful import Api, Resource -from .views import SignUp +from .views import SignUp, Login myblue = Blueprint("api", __name__, url_prefix="/storemanager/api/v1") api = Api(myblue) api.add_resource(SignUp, '/auth/signup') -# api.add_resource(Login, '/auth/login') +api.add_resource(Login, '/auth/login') diff --git a/app/api/v1/views.py b/app/api/v1/views.py index b04d9ff..401309a 100644 --- a/app/api/v1/views.py +++ b/app/api/v1/views.py @@ -8,6 +8,30 @@ from .models import * +def token_required(func): + @wraps(func) + def decorated(*args, **kwargs): + token = None + if 'x-access-token' in request.headers: + token = request.headers['x-access-token'] + if not token: + return make_response(jsonify({ + "Message": "the access token is missing, Login"}, 401)) + try: + data = jwt.decode(token, Config.SECRET_KEY) + for user in users: + if user['email'] == data['email']: + current_user = user + + except: + + print(Config.SECRET_KEY) + return make_response(jsonify({ + "Message": "This token is invalid" + }, 403)) + + return func(current_user, *args, **kwargs) + return decorated class SignUp(Resource): def post(self): @@ -32,3 +56,28 @@ def post(self): "user": users } ), 201) + +class Login(Resource): + def post(self): + data = request.get_json() + if not data: + return make_response(jsonify({ + "Message": "Ensure you have inserted your credentials" + } + ), 401) + email = data["email"] + password = data["password"] + + for user in users: + if email == user["email"] and password == user["password"]: + token = jwt.encode({ + "email": email, + "exp": datetime.datetime.utcnow() + datetime.timedelta + (minutes=5) + }, Config.SECRET_KEY) + return make_response(jsonify({ + "token": token.decode("UTF-8")}), 200) + return make_response(jsonify({ + "Message": "Login failed, wrong entries" + } + ), 401) From 03826a69d59339672dc5bf5150671992871d04b7 Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 23:04:08 +0300 Subject: [PATCH 07/12] [Feature #161320154] Add failing test for posting product --- app/tests/v1/test_endpoints.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/tests/v1/test_endpoints.py b/app/tests/v1/test_endpoints.py index afca114..b5b6be7 100644 --- a/app/tests/v1/test_endpoints.py +++ b/app/tests/v1/test_endpoints.py @@ -92,3 +92,19 @@ def test_login_granted(self): 'content-type': 'application/json' }) self.assertEqual(response.status_code, 200) + + def test_post_product(self): + response = self.test_client.post("storemanager/api/v1/products", + data=json.dumps({ + 'name': 'minji', + 'category': 'food', + 'desc': 'great food', + 'currstock': 200, + 'minstock': 20, + 'price': 30 + }), + headers={ + 'content-type': 'application/json', + "x-access-token": self.token_for_admin + }) + self.assertEqual(response.status_code, 201) From c70e340fe5f30e84e418e2c2a5eb41e53a8ecb4d Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 23:09:22 +0300 Subject: [PATCH 08/12] [Feature #161320154] Add post product endpoint for test to pass --- app/api/v1/__init__.py | 3 ++- app/api/v1/models.py | 26 +++++++++++++++++++++++++- app/api/v1/views.py | 25 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/api/v1/__init__.py b/app/api/v1/__init__.py index 7c5e3c9..d8adc42 100644 --- a/app/api/v1/__init__.py +++ b/app/api/v1/__init__.py @@ -1,8 +1,9 @@ from flask import Flask, Blueprint from flask_restful import Api, Resource -from .views import SignUp, Login +from .views import SignUp, Login, Product myblue = Blueprint("api", __name__, url_prefix="/storemanager/api/v1") api = Api(myblue) api.add_resource(SignUp, '/auth/signup') api.add_resource(Login, '/auth/login') +api.add_resource(Product, '/products') diff --git a/app/api/v1/models.py b/app/api/v1/models.py index b88052a..c212098 100644 --- a/app/api/v1/models.py +++ b/app/api/v1/models.py @@ -1,5 +1,5 @@ users = [] - +products = [] class UserAuth(): def __init__(self, name, email, password, role): @@ -19,5 +19,29 @@ def save_user(self): } users.append(user) +class PostProduct(): + def __init__(self, id, name, category, desc, currstock, minstock, price): + self.id = id + self.name = name + self.category = category + self.desc = desc + self.currstock = currstock + self.minstock = minstock + self.price = price + + def add_product(self): + payload = { + 'id' : self.id, + 'name': self.name, + 'category' : self.category, + 'desc': self.desc, + 'currstock' : self.currstock, + 'minstock' : self.minstock, + 'price': self.price + } + + products.append(payload) + print(products) + def collapse(): users = [] diff --git a/app/api/v1/views.py b/app/api/v1/views.py index 401309a..60f254c 100644 --- a/app/api/v1/views.py +++ b/app/api/v1/views.py @@ -33,6 +33,31 @@ def decorated(*args, **kwargs): return func(current_user, *args, **kwargs) return decorated +class Product(Resource): + @token_required + def post(current_user, self): + if current_user["role"] != "admin": + return make_response(jsonify({ + "Message": "you have no clearance for this endpoint"} + ), 403) + id = len(products) + 1 + data = request.get_json() + name = data["name"] + category = data["category"] + desc = data["desc"] + currstock = data["currstock"] + minstock = data["minstock"] + price = data["price"] + + prod = PostProduct(id, name, category, desc, currstock, minstock, price) + prod.add_product() + return make_response(jsonify({ + "Status": "ok", + "Message": "Product posted successfully", + "Products": products + } + ), 201) + class SignUp(Resource): def post(self): data = request.get_json() From 20e178f44ed7e9e5837f8aa6ea34ef9e03913e0e Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 23:16:17 +0300 Subject: [PATCH 09/12] [Feature #161314817] Add failing tests for posting sale --- app/tests/v1/test_endpoints.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/tests/v1/test_endpoints.py b/app/tests/v1/test_endpoints.py index b5b6be7..cd100dc 100644 --- a/app/tests/v1/test_endpoints.py +++ b/app/tests/v1/test_endpoints.py @@ -108,3 +108,13 @@ def test_post_product(self): "x-access-token": self.token_for_admin }) self.assertEqual(response.status_code, 201) + def test_post_sale(self): + data = json.dumps({ + "id": 1 + }) + response = self.test_client.post("storemanager/api/v1/sales", + data=data, headers={ + 'content-type': 'application/json', + 'x-access-token': self.token_for_attendant + }) + self.assertEqual(response.status_code, 201) From 24dae18b3173b54e1d612ed724a6bb6e658957f8 Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 23:20:30 +0300 Subject: [PATCH 10/12] [Feature #161314817]Add post sale endpoint for test to pass --- app/api/v1/__init__.py | 3 +- app/api/v1/models.py | 1 + app/api/v1/views.py | 50 ++++++++++++++++++++++++++++++++++ app/tests/v1/test_endpoints.py | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/app/api/v1/__init__.py b/app/api/v1/__init__.py index d8adc42..4286de6 100644 --- a/app/api/v1/__init__.py +++ b/app/api/v1/__init__.py @@ -1,9 +1,10 @@ from flask import Flask, Blueprint from flask_restful import Api, Resource -from .views import SignUp, Login, Product +from .views import SignUp, Login, Product, Sale myblue = Blueprint("api", __name__, url_prefix="/storemanager/api/v1") api = Api(myblue) api.add_resource(SignUp, '/auth/signup') api.add_resource(Login, '/auth/login') api.add_resource(Product, '/products') +api.add_resource(Sale, '/sales') diff --git a/app/api/v1/models.py b/app/api/v1/models.py index c212098..22fbd6d 100644 --- a/app/api/v1/models.py +++ b/app/api/v1/models.py @@ -1,5 +1,6 @@ users = [] products = [] +sales = [] class UserAuth(): def __init__(self, name, email, password, role): diff --git a/app/api/v1/views.py b/app/api/v1/views.py index 60f254c..7a806cf 100644 --- a/app/api/v1/views.py +++ b/app/api/v1/views.py @@ -58,6 +58,56 @@ def post(current_user, self): } ), 201) +class Sale(Resource): + def get(self): + return make_response(jsonify({ + "Status": "ok", + "Message": "All products fetched successfully", + "sales": sales + } + )) + + @token_required + def post(current_user, self): + total = 0 + data = request.get_json() + print(data) + if current_user["role"] != "attendant": + return make_response(jsonify({ + "Message": "You must be an attendant to access this endpoint" + } + )) + id = data['id'] + for product in products: + if product["currstock"] > 0: + if product["id"] == id: + sale = { + "saleid": len(sales) + 1, + "product": product + } + product["currstock"] = product["currstock"] - 1 + sales.append(sale) + for sale in sales: + if product["id"] in sale.values(): + total = total + int(product["price"]) + return make_response(jsonify({ + "Status": "ok", + "Message": "sale is successfull", + "Sales": sales, + "total cost": total + }), 201) + else: + return make_response(jsonify({ + "Status": "non-existent", + "Message": "item not found" + }), 404) + else: + return make_response(jsonify({ + "Status": "not found", + "Message": "items have run out" + + }), 404) + class SignUp(Resource): def post(self): data = request.get_json() diff --git a/app/tests/v1/test_endpoints.py b/app/tests/v1/test_endpoints.py index cd100dc..3a06b16 100644 --- a/app/tests/v1/test_endpoints.py +++ b/app/tests/v1/test_endpoints.py @@ -118,3 +118,4 @@ def test_post_sale(self): 'x-access-token': self.token_for_attendant }) self.assertEqual(response.status_code, 201) + From 56dba7fcc5e58d24557a20e9f51cfeb60c1b9572 Mon Sep 17 00:00:00 2001 From: Arusey Date: Thu, 18 Oct 2018 23:25:18 +0300 Subject: [PATCH 11/12] [Feature #161320158]Add failing test for getting all sales --- app/tests/v1/test_endpoints.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/tests/v1/test_endpoints.py b/app/tests/v1/test_endpoints.py index 3a06b16..25b795b 100644 --- a/app/tests/v1/test_endpoints.py +++ b/app/tests/v1/test_endpoints.py @@ -118,4 +118,6 @@ def test_post_sale(self): 'x-access-token': self.token_for_attendant }) self.assertEqual(response.status_code, 201) - + def test_get_all_sales(self): + response = self.test_client.get("storemanager/api/v1/products") + self.assertEqual(response.status_code, 200) From 845dcaae2acd295dab1e2b4b74e35cb4d34d3213 Mon Sep 17 00:00:00 2001 From: Arusey Date: Fri, 19 Oct 2018 00:07:51 +0300 Subject: [PATCH 12/12] [Feature #161320158]Add get sale endpoint for test to pass --- app/api/v1/models.py | 2 ++ app/api/v1/views.py | 9 +++++++++ app/tests/v1/test_endpoints.py | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/api/v1/models.py b/app/api/v1/models.py index 22fbd6d..0eae331 100644 --- a/app/api/v1/models.py +++ b/app/api/v1/models.py @@ -46,3 +46,5 @@ def add_product(self): def collapse(): users = [] + products = [] + sales = [] diff --git a/app/api/v1/views.py b/app/api/v1/views.py index 7a806cf..2f5c2d3 100644 --- a/app/api/v1/views.py +++ b/app/api/v1/views.py @@ -107,6 +107,15 @@ def post(current_user, self): "Message": "items have run out" }), 404) +# class Sale(Resource): +# def get(self): +# return make_response(jsonify({ +# "Status": "ok", +# "Message": "All products fetched successfully", +# "sales": sales +# } +# )) + class SignUp(Resource): def post(self): diff --git a/app/tests/v1/test_endpoints.py b/app/tests/v1/test_endpoints.py index 25b795b..f0678a2 100644 --- a/app/tests/v1/test_endpoints.py +++ b/app/tests/v1/test_endpoints.py @@ -119,5 +119,5 @@ def test_post_sale(self): }) self.assertEqual(response.status_code, 201) def test_get_all_sales(self): - response = self.test_client.get("storemanager/api/v1/products") + response = self.test_client.get("storemanager/api/v1/sales") self.assertEqual(response.status_code, 200)