예제 #1
0
def register():
    email = request.form['email']
    password = request.form['password']

    Customer.register(email, password)

    return render_template("login.html")
 def test_reverse_ascending():
     customer_one = CustomerRecord(
         Customer(user_id=11, name="Alice Cahill"),
         Location(latitude=51.92893, longitude=-10.27699))
     customer_two = CustomerRecord(
         Customer(user_id=4, name="Ian Kehoe"),
         Location(latitude=53.2451022, longitude=-6.238335))
     customer_three = CustomerRecord(
         Customer(user_id=9, name="Alice Cahill"),
         Location(latitude=51.92893, longitude=-10.27699))
     data = [customer_one, customer_two, customer_three]
     extracted_data = Extractor.extract_customer(data)
     Sorting.sort_customers(extracted_data, True)
     assert len(extracted_data) == 3
     assert extracted_data[0].user_id <= extracted_data[1].user_id
     assert extracted_data[1].user_id <= extracted_data[2].user_id
    def test_filter_by_distance_happy_scenario(get_filter_by_distance_obj):
        customer_one = CustomerRecord(
            Customer(user_id=1, name="Alice Cahill"),
            Location(latitude=51.92893, longitude=-10.27699))
        customer_two = CustomerRecord(
            Customer(user_id=4, name="Ian Kehoe"),
            Location(latitude=53.2451022, longitude=-6.238335))

        result = get_filter_by_distance_obj.filter(
            [customer_one, customer_two], DUBLIN_OFFICE_LOCATION,
            INVITATION_RANGE_THRESHOLD_IN_KILOMETERS)

        assert len(result) == 1
        assert result[0].customer.user_id == 4
        assert result[0].customer.name == "Ian Kehoe"
        assert result[0].location.latitude == 53.2451022
        assert result[0].location.longitude == -6.238335
 def test_extractor_happy_scenario():
     data = [
         CustomerRecord(Customer(user_id=1, name="Alice Cahill"),
                        Location(latitude=51.92893, longitude=-10.27699))
     ]
     result = Extractor.extract_customer(data)
     assert len(result) == 1
     assert isinstance(result[0], Customer)
     assert result[0].user_id == 1
     assert result[0].name == "Alice Cahill"
예제 #5
0
def login_user():

    #Getting the email and password from the page
    email = request.form['email']
    password = request.form['password']

    #checking if the customer is registered
    if Customer.login_valid(email, password):
        Customer.login(email)  #if registered login sucessfull
    else:

        return render_template("login.html")

    Database.update_one("tables", {'user_email': "none"},
                        {"$set": {
                            'user_email': email
                        }})

    date = Database.find('tables')

    for day in date:
        time = day['created_date']
        table_no = day['table_no']
        table_name = day['table_name']

        time = time.weekday()

        if (time == 3):
            today = "Thursday"
        elif (time == 4):
            today = "Friday"

    return render_template(
        "profile.html",
        email=session['email'],
        table_no=table_no,
        time=today,
        table_name=table_name
    )  #returning the home page when the login is sucessfull
예제 #6
0
class TestCustomer(unittest.TestCase):
    """
	Test cases for Customer model
	"""
    def setUp(self):
        self.customer = Customer(1, "Christina", 52.986375, -6.043701)

    # Positive case
    def test_getUserId(self):
        self.assertEqual(self.customer.getUserId(), 1)

    # Negative case
    def test_getUserId_0(self):
        self.assertNotEqual(self.customer.getUserId(), 2)

    # Positive case
    def test_getName(self):
        self.assertEqual(self.customer.getName(), "Christina")

    # Negative case
    def test_getName_0(self):
        self.assertNotEqual(self.customer.getName(), "Martha")

    # Positive case
    def test_getLatitude(self):
        self.assertEqual(self.customer.getLatitude(), 52.986375)

    # Negative case
    def test_getLatitude_0(self):
        self.assertNotEqual(self.customer.getLatitude(), 55)

    # Positive case
    def test_getLongitude(self):
        self.assertEqual(self.customer.getLongitude(), -6.043701)

    # Negative case
    def test_getLongitude_0(self):
        self.assertNotEqual(self.customer.getLongitude(), 55)

    # Positive case
    def test_getLocation(self):
        self.assertIsInstance(self.customer.getLocation(), GeoLocation)
 def deserialize(self, raw_data):
     """
     Deserializer method for Customer Records.This method deserializes json strings of customer records
     into objects of Customer Records.
     :param raw_data: List of json strings of customer records
     :return: List of Customer record objects
     """
     if not isinstance(raw_data, List):
         raise BaseDeserializerError(
             "Customer Record Deserializer expects raw input to be a list")
     deserialized_data = []
     logging.info("Starting data deserialization")
     for line in raw_data:
         data = json.loads(line)
         location = Location(float(data[LocationFields.latitude.name]),
                             float(data[LocationFields.longitude.name]))
         customer = Customer(data[CustomerFields.user_id.name],
                             data[CustomerFields.name.name])
         customer_record = CustomerRecord(customer, location)
         deserialized_data.append(customer_record)
     logging.info("Deserialization completed")
     return deserialized_data
예제 #8
0
def insert_data(cnx):
    """insert data in the database."""
    fake = Faker("fr_FR")
    now = datetime.datetime(2020, 7, 14, 11, 55, 00)
    Faker.seed(123456)
    random.seed(123456)

    print(
        "\n\n",
        " Insertion du jeu de données en base ".center(100, "#"),
        "\n\n",
    )

    # restaurant
    restaurants = RESTAURANT
    restaurant_mng = RestaurantManager(cnx)
    for restaurant in restaurants:
        restaurant_data = {
            "restaurant_name": restaurant,
            "phone_number": fake.pystr_format(string_format="##-##-##-##-##"),
            "address1": fake.street_address(),
            "address2": fake.pystr(min_chars=0, max_chars=20),
            "add_info": fake.pystr_format(string_format="##?##"),
            "city_name": fake.city(),
            "zip_code": fake.postcode(),
        }

        restaurant_obj = Restaurant(restaurant_data)
        restaurant_mng.create(restaurant_obj)

        # Add Lola as Founder
        founder_data = {
            "first_name": "Lola",
            "last_name": "Dupont",
            "phone_number": "00-00-00-00-00",
            "email": "*****@*****.**",
            "password": pbkdf2_sha256.hash(
                fake.pystr(min_chars=6, max_chars=20)
            ),
            "job_name": "Founder",
            "restaurant_name": restaurant,
        }

        founder_obj = Employee(founder_data)
        founder_mng = EmployeeManager(cnx)
        founder_mng.create(founder_obj)

        # employee
        staff = STAFF
        employee_mng = EmployeeManager(cnx)
        for employee_job in staff:
            employee_first_name = fake.first_name()
            employee_last_name = fake.last_name()
            employee_data = {
                "first_name": employee_first_name,
                "last_name": employee_last_name,
                "phone_number": fake.pystr_format(
                    string_format="##-##-##-##-##"
                ),
                "email": f"{employee_first_name}.{employee_last_name}@OC-Pizza.com",  # noqa: E501
                "password": pbkdf2_sha256.hash(
                    fake.pystr(min_chars=6, max_chars=20)
                ),
                "job_name": employee_job,
                "restaurant_name": restaurant,
            }

            employee_obj = Employee(employee_data)
            employee_mng.create(employee_obj)

    # customer
    customer_mng = CustomerManager(cnx)
    restau_custom_mng = RestaurantCustomerManager(cnx)
    for index in range(50):
        customer_first_name = fake.first_name()
        customer_last_name = fake.last_name()
        customer_data = {
            "first_name": customer_first_name,
            "last_name": customer_last_name,
            "phone_number": fake.pystr_format(string_format="##-##-##-##-##"),
            "email": f"{customer_first_name}.{customer_last_name}@gmail.com",
            "password": pbkdf2_sha256.hash(
                fake.pystr(min_chars=6, max_chars=20)
            ),
            "birthdate": fake.date(),
            "address1": fake.street_address(),
            "address2": fake.pystr(min_chars=0, max_chars=20),
            "add_info": fake.pystr_format(string_format="##?##"),
            "city_name": fake.city(),
            "zip_code": fake.postcode(),
        }

        customer_obj = Customer(customer_data)
        customer_mng.create(customer_obj)

        restaurant_list = random.choices(RESTAURANT, k=random.randint(1, 8))
        restau_custom_obj = RestaurantCustomer(
            customer_data.get("email"), restaurant_list
        )
        restau_custom_mng.create(restau_custom_obj)

    # ingredient & stock
    ingredients = INGREDIENT
    ingredient_mng = IngredientManager(cnx)
    for restaurant in restaurants:
        for ingredient in ingredients:
            ingredient_data = {
                "ingredient_name": ingredient,
                "ingredient_stock": random.randint(0, 25),
                "ingredient_restaurant": restaurant,
            }

            ingredient_obj = Ingredient(ingredient_data)
            ingredient_mng.create(ingredient_obj)

    # product, vat, & category
    recipes = {}
    products = PRODUCT
    product_mng = ProductManager(cnx)
    for product in products:
        product_data = {
            "product_name": product,
            "vat_100": random.choice(VAT),
            "price_excluding_tax": random.randint(9, 20),
            "category": random.choice(CATEGORY),
        }

        recipe_data = []
        recipe_data = [
            (ingredient_recipe, random.randint(1, 3))
            for ingredient_recipe in random.choices(
                INGREDIENT, k=(random.randint(1, 5))
            )
        ]
        recipes[product] = recipe_data

        product_obj = Product(product_data, recipe_data)
        product_mng.create(product_obj)

    # recipe
    recipe_mng = RecipeManager(cnx)
    for recipe_name, instruction in recipes.items():
        recipe_obj = Recipe(instruction, recipe_name)
        recipe_mng.create(recipe_obj)

    # status
    status_mng = StatusManager(cnx)
    for status in STATUS:
        status_obj = Status(status)
        status_mng.create(status_obj)

    # order
    SQL_SELECT_CUSTOMER = "SELECT email FROM Customer;"
    cursor = cnx.cursor()
    cursor.execute(SQL_SELECT_CUSTOMER)
    customer_list = cursor.fetchall()
    order_mng = PurchaseOrderManager(cnx)
    order_prod_mng = OrderProductManager(cnx)

    for order in range(1, 101):
        order_payment_method = random.choice(PAYMENT_METHOD)
        order_status = random.choice(STATUS)
        order_restaurant = random.choice(RESTAURANT)
        order_customer = (random.choice(customer_list))[0]
        order_data = {
            "order_date": now.strftime("%Y/%m/%d %H:%M:%S"),
            "order_number": order,
            "order_payment_method": order_payment_method,
            "order_restaurant": order_restaurant,
            "order_customer": order_customer,
            "order_status": order_status,
            "order_mode": random.choice(["livraison", "sur place"]),
        }
        order_obj = PurchaseOrder(order_data)
        order_mng.create(order_obj)

        order_details = []
        for product in random.sample(PRODUCT, k=random.randint(1, 10)):
            order_details.append((product, random.randint(1, 5)))
        order_prod_obj = OrderProduct(order, order_details)
        order_prod_mng.create(order_prod_obj)

    print(
        "\n", "> Insertion réalisée avec succès <".center(100, "-"), "\n",
    )
 def test_calculateDistance_0(self):
     invited = CustomerService.calculateDistance(
         Customer(1, "Alice", 51.92893, -10.27699), self.intercomLocation,
         self.maxDistance)
     self.assertFalse(invited)
     self.assertIsInstance(invited, bool)
 def test_calculateDistance(self):
     invited = CustomerService.calculateDistance(
         Customer(1, "Mark", 53.2451022, -6.238335), self.intercomLocation,
         self.maxDistance)
     self.assertTrue(invited)
     self.assertIsInstance(invited, bool)
예제 #11
0
 def test_customer_record_serializer_happy_scenario(get_customer_record_serializer_obj):
     data = CustomerRecord(Customer(user_id=1, name="Alice Cahill"), Location(latitude=51.92893, longitude=-10.27699))
     result = get_customer_record_serializer_obj.serialize([data])
     assert len(result) == 1
     assert result[0] == '{"customer": {"user_id": 1, "name": "Alice Cahill"}, "location": {"latitude": 51.92893, "longitude": -10.27699}}'
예제 #12
0
    async def post(self, request: Request, user: User):
        customer = Customer(**request.json)
        await customer.save()

        return json(customer.dict(), status=201)
예제 #13
0
 def setUp(self):
     self.customer = Customer(1, "Christina", 52.986375, -6.043701)