/AirBnB_clone_v3

Python| Back-end| API| Webserver| Flask

Primary LanguagePython

0x05. AirBnB clone - RESTful API

#Resources Read or watch:

REST API concept page Learn REST: A RESTful Tutorial Designing a RESTful API with Python and Flask HTTP access control (CORS) Flask cheatsheet What are Flask Blueprints, exactly? Flask Modular Applications with Blueprints Flask tests Flask-CORS

Functionalities of this command interpreter:

  • Create a new object (ex: a new User or a new Place)
  • Retrieve an object from a file, a database etc...
  • Do operations on objects (count, compute stats, etc...)
  • Update attributes of an object
  • Destroy an object

Requirements

Python Scripts Allowed editors: vi, vim, emacs All your files will be interpreted/compiled on Ubuntu 14.04 LTS using python3 (version 3.4.3) All your files should end with a new line The first line of all your files should be exactly #!/usr/bin/python3 A README.md file, at the root of the folder of the project, is mandatory Your code should use the PEP 8 style (version 1.7) All your files must be executable The length of your files will be tested using wc All your modules should have documentation (python3 -c 'print(import("my_module").doc)') All your classes should have documentation (python3 -c 'print(import("my_module").MyClass.doc)') All your functions (inside and outside a class) should have documentation (python3 -c 'print(import("my_module").my_function.doc)' and python3 -c 'print(import("my_module").MyClass.my_function.doc)') A documentation is not a simple word, it’s a real sentence explaining what’s the purpose of the module, class or method (the length of it will be verified)

Installation

  • Clone this repository: git clone "https://github.com/fosityne007/AirBnB_clone_v3"
  • Access AirBnb directory: cd AirBnB_clone
  • Run hbnb(interactively): ./console and enter command
  • Run hbnb(non-interactively): echo "<command>" | ./console.py

File Descriptions

console.py - the console contains the entry point of the command interpreter. List of commands this console current supports:

  • EOF - exits console
  • quit - exits console
  • <emptyline> - overwrites default emptyline method and does nothing
  • create - Creates a new instance ofBaseModel, saves it (to the JSON file) and prints the id
  • destroy - Deletes an instance based on the class name and id (save the change into the JSON file).
  • show - Prints the string representation of an instance based on the class name and id.
  • all - Prints all string representation of all instances based or not on the class name.
  • update - Updates an instance based on the class name and id by adding or updating attribute (save the change into the JSON file).

models/ directory contains classes used for this project:

  • base_model.py - The BaseModel class from which future classes will be derived

    • def __init__(self, *args, **kwargs) - Initialization of the base model
    • def __str__(self) - String representation of the BaseModel class
    • def save(self) - Updates the attribute updated_at with the current datetime
    • def to_dict(self) - returns a dictionary containing all keys/values of the instance
  • Classes inherited from Base Model:

/models/engine directory contains File Storage class that handles JASON serialization and deserialization

  • file_storage.py - serializes instances to a JSON file & deserializes back to instances
    • def all(self) - returns the dictionary __objects
    • def new(self, obj) - sets in __objects the obj with key .id
    • def save(self) - serializes __objects to the JSON file (path: __file_path)
    • def reload(self) - deserializes the JSON file to __objects

/tests directory contains all unit test cases for this project:

/test_models/test_base_model.py - Contains the TestBaseModel and TestBaseModelDocs classes

  • TestBaseModelDocs class:

    • def setUpClass(cls)- Set up for the doc tests
    • def test_pep8_conformance_base_model(self) - Test that models/base_model.py conforms to PEP8
    • def test_pep8_conformance_test_base_model(self) - Test that tests/test_models/test_base_model.py conforms to PEP8
    • def test_bm_module_docstring(self) - Test for the base_model.py module docstring
    • def test_bm_class_docstring(self) - Test for the BaseModel class docstring
    • def test_bm_func_docstrings(self) - Test for the presence of docstrings in BaseModel methods
  • TestBaseModel class:

    • def test_is_base_model(self) - Test that the instatiation of a BaseModel works
    • def test_created_at_instantiation(self) - Test created_at is a pub. instance attribute of type datetime
    • def test_updated_at_instantiation(self) - Test updated_at is a pub. instance attribute of type datetime
    • def test_diff_datetime_objs(self) - Test that two BaseModel instances have different datetime objects
  • /test_models/test_amenity.py - Contains the TestAmenityDocs class:

    • def setUpClass(cls) - Set up for the doc tests
    • def test_pep8_conformance_amenity(self) - Test that models/amenity.py conforms to PEP8
    • def test_pep8_conformance_test_amenity(self) - Test that tests/test_models/test_amenity.py conforms to PEP8
    • def test_amenity_module_docstring(self) - Test for the amenity.py module docstring
    • def test_amenity_class_docstring(self) - Test for the Amenity class docstring
  • /test_models/test_city.py - Contains the TestCityDocs class:

    • def setUpClass(cls) - Set up for the doc tests
    • def test_pep8_conformance_city(self) - Test that models/city.py conforms to PEP8
    • def test_pep8_conformance_test_city(self) - Test that tests/test_models/test_city.py conforms to PEP8
    • def test_city_module_docstring(self) - Test for the city.py module docstring
    • def test_city_class_docstring(self) - Test for the City cla
  • /test_models/test_file_storage.py - Contains the TestFileStorageDocs class:

    • def setUpClass(cls) - Set up for the doc tests
    • def test_pep8_conformance_file_storage(self) - Test that models/file_storage.py conforms to PEP8
    • def test_pep8_conformance_test_file_storage(self) - Test that tests/test_models/test_file_storage.py conforms to PEP8
    • def test_file_storage_module_docstring(self) - Test for the file_storage.py module docstring
    • def test_file_storage_class_docstring(self) - Test for the FileStorage class docstring
  • /test_models/test_place.py - Contains the TestPlaceDoc class:

    • def setUpClass(cls) - Set up for the doc tests
    • def test_pep8_conformance_place(self) - Test that models/place.py conforms to PEP8.
    • def test_pep8_conformance_test_place(self) - Test that tests/test_models/test_place.py conforms to PEP8.
    • def test_place_module_docstring(self) - Test for the place.py module docstring
    • def test_place_class_docstring(self) - Test for the Place class docstring



## Authors

>Famous Osiaro {famous.osiaro@gmail.com}