Skip to content

Latest commit

 

History

History
219 lines (150 loc) · 6.99 KB

README.md

File metadata and controls

219 lines (150 loc) · 6.99 KB

AirBnB Clone: Phase # 4

Web dynamic with JQuery

Description

Project attempts to clone the the AirBnB application and website, including the database, storage, RESTful API, Web Framework, and Front End. Currently the application is designed to run with 2 storage engine models:

  • File Storage Engine:

    • /models/engine/file_storage.py
  • Database Storage Engine:

    • /models/engine/db_storage.py

    • To Setup the DataBase for testing and development, there are 2 setup scripts that setup a database with certain privileges: setup_mysql_test.sql & setup_mysql_test.sql (for more on setup, see below).

    • The Database uses Environmental Variables for tests. To execute tests with the environmental variables prepend these declarations to the execution command:

$ HBNB_MYSQL_USER=hbnb_test HBNB_MYSQL_PWD=hbnb_test_pwd \
HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_test_db HBNB_TYPE_STORAGE=db \
[COMMAND HERE]

Run the web_dynamic version

To run this inside vagrant, add those two lines to the Vagrantfile:

config.vm.network :forwarded_port, guest: 5000, host: 5000
config.vm.network :forwarded_port, guest: 5001, host: 5001

The API will run on port 5001 and the page will run on port 5000.

In a first terminal inside the repo, run the API:

HBNB_MYSQL_USER=hbnb_dev HBNB_MYSQL_PWD=hbnb_dev_pwd HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_dev_db HBNB_TYPE_STORAGE=db HBNB_API_PORT=5001 python3 -m api.v1.app

In a second window inside the repo, run a page (for example 100-hbnb):

HBNB_MYSQL_USER=hbnb_dev HBNB_MYSQL_PWD=hbnb_dev_pwd HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_dev_db HBNB_TYPE_STORAGE=db HBNB_API_PORT=5000 python3 -m web_dynamic.100-hbnb

All the web dynamic Flask scripts, HTML templates and Javascript scripts are in the foler web_dynamic.

Environment

  • OS: Ubuntu 14.04 LTS
  • language: Python 3.4.3
  • web server: nginx/1.4.6
  • application server: Flask 0.12.2, Jinja2 2.9.6
  • web server gateway: gunicorn (version 19.7.1)
  • database: mysql Ver 14.14 Distrib 5.7.18
  • documentation: Swagger (flasgger==0.6.6)
  • style:
    • python: PEP 8 (v. 1.7.0)
    • web static: W3C Validator
    • bash: ShellCheck 0.3.3
    • javascript: semistandard

Setup

This project comes with various setup scripts to support automation, especially during maintanence or to scale the entire project. The following files are the setupfiles along with a brief explanation:

  • dev/setup.sql: Drops test and dev databases, and then reinitializes the datbase.

    • Usage: $ cat dev/setup.sql | mysql -uroot -p
  • setup_mysql_dev.sql: initialiezs dev database with mysql for testing

    • Usage: $ cat setup_mysql_dev.sql | mysql -uroot -p
  • setup_mysql_test.sql: initializes test database with mysql for testing

    • Usage: $ cat setup_mysql_test.sql | mysql -uroot -p
  • 0-setup_web_static.sh: sets up nginx web server config file & the file structure.

    • Usage: $ sudo ./0-setup_web_static.sh
  • 3-deploy_web_static.py: uses 2 functions from (1-pack_web_static.py & 2-do_deploy_web_static.py) that use the fabric3 python integration, to create a .tgz file on local host of all the local web static fils, and then calls the other function to deploy the compressed web static files. Command must be executed from the AirBnB_clone root directory.

    • Usage: $ fab -f 3-deploy_web_static.py deploy -i ~/.ssh/holberton -u ubuntu

Testing

unittest

This project uses python library, unittest to run tests on all python files. All unittests are in the ./tests directory with the command:

  • File Storage Engine Model:

    • $ python3 -m unittest discover -v ./tests/
  • DataBase Storage Engine Model

$ HBNB_MYSQL_USER=hbnb_test HBNB_MYSQL_PWD=hbnb_test_pwd \
HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_test_db HBNB_TYPE_STORAGE=db \
python3 -m unittest discover -v ./tests/

All Tests

The bash script init_test.sh executes all these tests for both File Storage & DataBase Engine Models:

  • checks pep8 style

  • runs all unittests

  • runs all w3c_validator tests

  • cleans up all __pycache__ directories and the storage file, file.json

  • Usage init_test.sh:

$ ./dev/init_test.sh

CLI Interactive Tests

  • This project uses python library, cmd to run tests in an interactive command line interface. To begin tests with the CLI, run this script:

File Storage Engine Model

$ ./console.py

To execute the CLI using the Database Storage Engine Model:

$ HBNB_MYSQL_USER=hbnb_test HBNB_MYSQL_PWD=hbnb_test_pwd \
HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_test_db HBNB_TYPE_STORAGE=db \
./console.py

For a detailed description of all tests, run these commands in the CLI:

(hbnb) help help
List available commands with "help" or detailed help with "help cmd".
(hbnb) help

Documented commands (type help <topic>):
========================================
Amenity    City  Place   State  airbnb  create   help  show
BaseModel  EOF   Review  User   all     destroy  quit  update

(hbnb) help User
class method with .function() syntax
        Usage: User.<command>(<id>)
(hbnb) help create
create: create [ARG] [PARAM 1] [PARAM 2] ...
        ARG = Class Name
        PARAM = <key name>=<value>
                value syntax: "<value>"
        SYNOPSIS: Creates a new instance of the Class from given input ARG
                  and PARAMS. Key in PARAM = an instance attribute.
        EXAMPLE: create City name="Chicago"
                 City.create(name="Chicago")
  • Tests in the CLI may also be executed with this syntax:

    • destroy: <class name>.destroy(<id>)

    • update: <class name>.update(<id>, <attribute name>, <attribute value>)

    • update with dictionary: <class name>.update(<id>, <dictionary representation>)


Authors

Repo forked from the V3 made by:

V4 made by:

License

MIT License