Ejemplo n.º 1
0
 def test_get_all_orders(self):
     """Testing retrieval of all orders
     """
     Meal.save(self.meal_data)
     date = datetime.datetime.today().strftime('%Y-%m-%d')
     Menu.set_menu(date, self.meal_data)
     Order.add_order(self.meal_data)
     response = self.app.get('/api/v1/orders')
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 2
0
 def test_create_menu(self):
     """
     Test menu creation
     """
     self.restaurant.save()
     menu = Menu(name=self.menu_name,
                 date=self.menu_date,
                 restaurant_id=self.restaurant.id)
     menu.save()
     self.assertIsNotNone(Menu.objects.filter(name=self.menu_name).first())
Ejemplo n.º 3
0
 def test_order_meal(self):
     """Test order meal from today's menu
     """
     Meal.save(self.meal_data)
     date = datetime.datetime.today().strftime('%Y-%m-%d')
     Menu.set_menu(date, self.meal_data)
     response = self.app.post('/api/v1/orders',
                              data=json.dumps(
                                  {'selected_id': self.meal_data['id']}))
     self.assertEqual(response.status_code, 201)
     self.assertIn(b'Order created successfully', response.data)
Ejemplo n.º 4
0
 def setUp(self):
     self.restaurant_name = "restaurant name"
     self.restaurant = Restaurant(name=self.restaurant_name)
     self.menu_name = "menu name"
     self.menu_date = datetime.now()
     self.employee_name = "employee name"
     self.employee = Employee(name=self.employee_name)
     self.employee.save()
     self.restaurant.save()
     self.menu = Menu(name=self.menu_name, date=self.menu_date, restaurant_id=self.restaurant.id)
     self.menu.save()
Ejemplo n.º 5
0
class VoteAPITestCase(APITestCase):
    """
    Test class to test Menu API
    """

    def setUp(self):
        self.apiClient = APIClient()
        self.restaurant_name = "restaurant name"
        self.restaurant = Restaurant(name=self.restaurant_name)
        self.restaurant.save()
        self.menu_name = "menu name"
        self.menu_date = datetime.now()
        self.menu = Menu(name=self.menu_name, date=self.menu_date, restaurant_id=self.restaurant.id)
        self.menu.save()
        self.employee_name = "employee name"
        self.employee = Employee(name=self.employee_name)
        self.employee.save()

    def test_api_create_vote(self):
        """
        Test menu creation using API
        """
        vote_json = {'menu': self.menu.id, 'employee': self.employee.id}
        response = self.client.post(reverse('vote'), vote_json, format="json")
        self.assertEquals(response.status_code, status.HTTP_201_CREATED)

    def test_api_get_vote(self):
        """
        Test menu retrieval using API
        """
        response = self.client.get(reverse('vote'))
        self.assertEquals(response.status_code, status.HTTP_200_OK)

    def test_api_get_today_vote_result(self):
        """
        Test menu retrieval for today using API
        """
        response = self.client.get(reverse('vote-today-result'))
        self.assertEquals(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 6
0
  def setUp(self):
    self.app = app
    self.db = DB()
    self.db.create_db_tables()
    self.dbmenu = Menu()
    self.dbuser = Users()
    self.dbuser.register_admin('super', 'super')
    self.dbuser.register_user('deee', 'deee')
    self.dbmenu.add_meal('pizza', 4000)
    self.client = self.app.test_client()

    self.admin = {
        'username': '******',
        'password': '******'
    }
    self.user = {
        'username': '******',
        'password': '******'
    }

    self.meal = {
        "meal_name": 'pizza',
        'price': 4000
    }
    self.meal_update = {
        'meal_status': "Accepted",
        "price": 800
    }
    self.order = {
        "location": "bunga",
        "quantity": 4,
        "meal": "pizza"
    }
    self.order_status = {
        "status": "Accepted"
    }
Ejemplo n.º 7
0
class VoteTestCase(TestCase):
    """
    Test class to test Vote model
    """

    def setUp(self):
        self.restaurant_name = "restaurant name"
        self.restaurant = Restaurant(name=self.restaurant_name)
        self.menu_name = "menu name"
        self.menu_date = datetime.now()
        self.employee_name = "employee name"
        self.employee = Employee(name=self.employee_name)
        self.employee.save()
        self.restaurant.save()
        self.menu = Menu(name=self.menu_name, date=self.menu_date, restaurant_id=self.restaurant.id)
        self.menu.save()

    def test_create_vote(self):
        """
        Test menu creation
        """
        vote = Vote(menu=self.menu, employee=self.employee)
        vote.save()
        self.assertIsNotNone(Vote.objects.filter(menu=self.menu, employee=self.employee).first())
Ejemplo n.º 8
0
  def setUp(self):
    self.app = app
    self.db = DB()
    self.db.create_db_tables()
    self.dbmenu = Menu()
    self.dbuser = Users()
    self.dbuser.register_admin('super', 'super')
    self.client = self.app.test_client()

    self.admin = {
        'username': '******',
        'password': '******'
    }

    self.meal = {
        "meal_name": 'pizza',
        'price': 4000
    }
    self.meal_update = {
        'meal_status': "Accepted",
        "price": 800
    }
Ejemplo n.º 9
0
 def setUp(self):
     self.db = DB()
     self.dbusers = Users()
     self.dbmenu = Menu()
     self.dborders = Orders()
     self.db.create_db_tables()
Ejemplo n.º 10
0
class DBTestCase(unittest.TestCase):
    def setUp(self):
        self.db = DB()
        self.dbusers = Users()
        self.dbmenu = Menu()
        self.dborders = Orders()
        self.db.create_db_tables()

    def test_create_user(self):
        query = self.dbusers.register_user('dee', 'dee')
        self.assertIn('user created', str(query))

    def test_find_user_by_username(self):
        query = self.dbusers.register_user('dee', 'dee')
        self.assertIn('user created', str(query))
        query = self.dbusers.find_by_username('dee')
        self.assertIn('dee', str(query))

    def test_create_meal_option(self):
        query = self.dbmenu.add_meal('pizza', 4000)
        self.assertIn('meal pizza added', str(query))

    def test_get_menu(self):
        query = self.dbmenu.get_menu()
        self.assertIn('Menu', str(query))

    def test_create_order(self):
        query = self.dbusers.register_user('dee', 'dee')
        query = self.dbmenu.add_meal('pizza', 4000)
        query = self.dborders.create_order("location", 4, 1, 'pizza')
        self.assertIn("order placed successfully", str(query))

    def test_get_order_history_for_a_user(self):
        query = self.dbusers.register_user('dee', 'dee')
        query = self.dbmenu.add_meal('pizza', 4000)
        query = self.dborders.create_order("location", 4, 1, 'pizza')
        query = self.dborders.get_order_history_for_a_user(1)
        self.assertIn('orders for user with id 1', str(query))

    def test_get_all_orders(self):
        query = self.dbusers.register_user('dee', 'dee')
        query = self.dbmenu.add_meal('pizza', 4000)
        query = self.dborders.create_order("location", 4, 1, 'pizza')
        query = self.dborders.get_all_orders()
        self.assertIn('All Orders', str(query))

    def test_get_order(self):
        query = self.dbusers.register_user('dee', 'dee')
        query = self.dbmenu.add_meal('pizza', 4000)
        query = self.dborders.create_order("location", 4, 1, 'pizza')
        query = self.dborders.get_order(1)
        self.assertIn('1', str(query))
        self.assertIn('pizza', str(query))

    def test_update_order_status(self):
        query = self.dbusers.register_user('dee', 'dee')
        query = self.dbmenu.add_meal('pizza', 4000)
        query = self.dborders.create_order("location", 4, 1, 'pizza')
        query = self.dborders.update_order_status(1, "Accepted")
        self.assertIn("order status updated", str(query))

    def test_update_meal_option(self):
        query = self.dbmenu.add_meal('pizza', 4000)
        query = self.dbmenu.update_meal(1, 2000, "burger")
        self.assertIn("meal updated", str(query))

    def test_delete_meal_option(self):
        query = self.dbmenu.add_meal('pizza', 4000)
        query = self.dbmenu.delete_meal(1)
        self.assertIn("meal deleted", str(query))

    def tearDown(self):
        print('dropping')
        self.db.drop_all_tables('orders', 'users', 'fastfoods')
Ejemplo n.º 11
0
class DatabaseTest(unittest.TestCase):
  def setUp(self):
    self.app = app
    self.db = DB()
    self.db.create_db_tables()
    self.dbmenu = Menu()
    self.dbuser = Users()
    self.dbuser.register_admin('super', 'super')
    self.dbuser.register_user('deee', 'deee')
    self.dbmenu.add_meal('pizza', 4000)
    self.client = self.app.test_client()

    self.admin = {
        'username': '******',
        'password': '******'
    }
    self.user = {
        'username': '******',
        'password': '******'
    }

    self.meal = {
        "meal_name": 'pizza',
        'price': 4000
    }
    self.meal_update = {
        'meal_status': "Accepted",
        "price": 800
    }
    self.order = {
        "location": "bunga",
        "quantity": 4,
        "meal": "pizza"
    }
    self.order_status = {
        "status": "Accepted"
    }

  def test_create_order(self):
    '''login  user'''
    res_login = self.client.post('/api/v2/auth/login',
                                 data=json.dumps(self.user),
                                 content_type='application/json')
    login_data = res_login.json
    '''get authentication token'''
    self.token = login_data['token']
    '''create order'''
    res = self.client.post('/api/v2/users/orders',
                           data=json.dumps(self.order),
                           content_type="application/json",
                           headers={'Authorization':
                                    'Bearer {}'.format(self.token)}
                           )
    self.assertIn("order placed successfully", str(res.data))

  def test_get_orders_for_a_user(self):
    '''login admin user'''
    res_login = self.client.post('/api/v2/auth/login',
                                 data=json.dumps(self.admin),
                                 content_type='application/json')
    login_data = res_login.json
    self.token = login_data['token']
    '''add meal using admin token'''
    res = self.client.post('/api/v2/menu',
                           data=json.dumps(self.meal),
                           content_type="application/json",
                           headers={'Authorization':
                                    'Bearer {}'.format(self.token)})
    '''login user'''
    res_login = self.client.post('/api/v2/auth/login',
                                 data=json.dumps(self.user),
                                 content_type='application/json')
    login_data = res_login.json
    '''get user token'''
    self.token = login_data['token']
    '''create order using admin token'''
    res = self.client.post('/api/v2/users/orders',
                           data=json.dumps(self.order),
                           content_type="application/json",
                           headers={'Authorization':
                                    'Bearer {}'.format(self.token)}
                           )
    '''get orders of user with Id 2'''
    res = self.client.get('/api/v2/users/orders',
                          headers={'Authorization':
                                   'Bearer {}'.format(self.token)}
                          )
    self.assertIn('orders for user with id 2', str(res.data))

  def test_get_all_orders(self):
    '''login admin user'''
    res_login = self.client.post('/api/v2/auth/login',
                                 data=json.dumps(self.admin),
                                 content_type='application/json')
    login_data = res_login.json
    '''get admin token'''
    self.token_admin = login_data['token']
    '''create meal using admin token'''
    res = self.client.post('/api/v2/menu',
                           data=json.dumps(self.meal),
                           content_type="application/json",
                           headers={'Authorization':
                                    'Bearer {}'.format(self.token_admin)})
    '''login normal user to post order'''
    res_login = self.client.post('/api/v2/auth/login',
                                 data=json.dumps(self.user),
                                 content_type='application/json')
    login_data = res_login.json
    self.token = login_data['token']
    '''create order using user token'''
    res = self.client.post('/api/v2/users/orders',
                           data=json.dumps(self.order),
                           content_type="application/json",
                           headers={'Authorization':
                                    'Bearer {}'.format(self.token)}
                           )
    '''get all orders using admin token'''
    res = self.client.get('/api/v2/orders',
                          headers={'Authorization':
                                   'Bearer {}'.format(self.token_admin)})

    self.assertIn("All Orders", str(res.data))

  def test_get_order(self):
    res_login = self.client.post('/api/v2/auth/login',
                                 data=json.dumps(self.admin),
                                 content_type='application/json')
    login_data = res_login.json
    self.token_admin = login_data['token']

    res = self.client.post('/api/v2/menu',
                           data=json.dumps(self.meal),
                           content_type="application/json",
                           headers={'Authorization':
                                    'Bearer {}'.format(self.token_admin)})
    res_login = self.client.post('/api/v2/auth/login',
                                 data=json.dumps(self.user),
                                 content_type='application/json')
    login_data = res_login.json
    self.token = login_data['token']

    res = self.client.post('/api/v2/users/orders',
                           data=json.dumps(self.order),
                           content_type="application/json",
                           headers={'Authorization':
                                    'Bearer {}'.format(self.token)}
                           )
    res_order = self.client.get('/api/v2/orders/1', headers={'Authorization':
                                                             'Bearer {}'.format(self.token_admin)})

    self.assertIn("pizza", str(res_order.data))

  def test_update_order_status(self):

    res_login = self.client.post('/api/v2/auth/login',
                                 data=json.dumps(self.admin),
                                 content_type='application/json')
    login_data = res_login.json
    self.token_admin = login_data['token']

    res = self.client.post('/api/v2/menu',
                           data=json.dumps(self.meal),
                           content_type="application/json",
                           headers={'Authorization':
                                    'Bearer {}'.format(self.token_admin)})

    res_login = self.client.post('/api/v2/auth/login',
                                 data=json.dumps(self.user),
                                 content_type='application/json')
    login_data = res_login.json
    self.token = login_data['token']

    res = self.client.post('/api/v2/users/orders',
                           data=json.dumps(self.order),
                           content_type="application/json",
                           headers={'Authorization':
                                    'Bearer {}'.format(self.token)}
                           )

    res_order = self.client.put('/api/v2/orders/1',
                                data=json.dumps(self.order_status),
                                content_type="application/json",
                                headers={'Authorization':
                                         'Bearer {}'.format(self.token_admin)}
                                )
    self.assertIn("order status updated", str(res_order.data))

  def tearDown(self):
    print('dropping')
    self.db.drop_all_tables('orders', 'users', 'fastfoods')
Ejemplo n.º 12
0
from flask import jsonify
from flask_restplus import Api, Resource, fields
from flask_jwt_extended import jwt_required, JWTManager, create_access_token, get_jwt_identity, verify_jwt_in_request
from api.app import app
from api.models.db import DB
from api.models.users import Users
from api.models.menu import Menu
from api.models.orders import Orders
from functools import wraps
import os

db = DB()
dbusers = Users()
dbmenu = Menu()
dborder = Orders()

api = Api(app, prefix='/api/v2', version='2.0', title='Fast-Foods-Api')
jwt = JWTManager(app)
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY')
app.config['JWT_SECRET_KEY'] = os.getenv('JWT_SECRET_KEY')

db.create_db_tables()


def register_super_admin(username, password):
    if dbusers.find_by_username(username) == None:
        dbusers.register_admin(username, password)
    return False


register_super_admin('super', 'super')