The first part of this project involves simulating an Airbnb application by creating a control system for the modules used on our web page. We achieve this by implementing a JSON-format database and leveraging object-oriented programming, Python data translation, and command interpretation. The result is a local database that can be easily modified using specific commands, providing a flexible and efficient way to manage data.
- Creates new object (ex: a new User or a new Place)
- Retrieves an object from a file, a database etc...
- Does operations on objects (count, compute stats, etc...)
- Updates attributes of an object
- Destroys an object
- Environment
- Installation
- File Descriptions
- How to use:
- Authors
- Licence
This project is interpreted/tested on Ubuntu 22.04 LTS using python3 (version 3.12.2)
- Clone this repository:
git clone "https://github.com/Tafara-N/AirBnB_clone.git"
- Access AirBnb directory:
cd AirBnB_clone
- Run hbnb(interactively):
./console
and press enter - Run hbnb(non-interactively):
echo "<command>" | ./console.py
console.py - The console contains the entry point of the command interpreter. List of commands this console current supports:
EOF
- exits consolequit
- exits console<emptyline>
- Overwrites default emptyline method and does nothingcreate
- Creates a new instance ofBaseModel
, saves it (to the JSON file) and prints the iddestroy
- 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).
base_model.py - The BaseModel class from which future classes will be derived
def __init__(self, *args, **kwargs)
- Initialization of the base modeldef __str__(self)
- String representation of the BaseModel classdef save(self)
- Updates the attributeupdated_at
with the current datetimedef to_dict(self)
- Returns a dictionary containing all keys/values of the instance
Classes inherited from Base Model:
/models/engine
Directory containing File Storage class that handles JSON serialization and deserialization
file_storage.py - Serializing instances to a JSON file & deserializes back to instances
def all(self)
- Returns dictionary __objectsdef new(self, obj)
- Sets in __objects the obj with key .iddef save(self)
- Serializing __objects to the JSON file (path:__file_path)def reload(self)
- Deserializing the JSON file to __objects
test_console.py Tests classes:
class TestHBNBCommandPrompting(unitest.TestCase)
- Testing the HBNB command interpreter's promptingclass TestHBNBCommandHelp (unitest.TestCase)
- Testing the HBNB command interpreter's help messageclass TestHBNBCommandExit (unitest.TestCase)
Testing the HBNB command interpreter's quit/exitclass TestHBNBCommandCreate (unitest.TestCase)
Testing the HBNB command interpreter's createclass TestHBNBCommandShow (unitest.TestCase)
- Testing the HBNB command interpreter's showclass TestHBNBCommandDestroy (unitest.TestCase)
- Testing the HBNB command interpreter's destroyclass TestHBNBCommandAll (unitest.TestCase)
- Testing the HBNB command interpreter's allclass TestHBNBCommandUpdate (unitest.TestCase)
- Testing the HBNB command interpreter's updateclass TestHBNBCommandCount(unittest.TestCase)
- Testing the HBNB command interpreter's count
/test_models/test_base_model.py - Contains the TestBaseModel and TestBaseModelDocs classes
TestBaseModel classes
/test_models/test_amenity.py - Contains the TestAmenity class
/test_models/test_city.py - Contains the TestCity class
/test_models/test_file_storage.py - Contains the TestFileStorage class:
/test_models/test_place.py - Contains the TestPlace class
/test_models/test_review.py - Contains the TestReview class
/test_models/state.py - Contains the TestState class
/test_models/user.py - Contains the TestUser class
vagrantAirBnB_clone$ ./console.py
(hbnb) help
Documented commands (type help <topic>):
========================================
EOF all create destroy help quit show update
(hbnb) all MyModel
** class doesn't exist **
(hbnb) create BaseModel
7da56403-cc45-4f1c-ad32-bfafeb2bb050
(hbnb) all BaseModel
[[BaseModel] (7da56403-cc45-4f1c-ad32-bfafeb2bb050) {'updated_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772167), 'id': '7da56403-cc45-4f1c-ad32-bfafeb2bb050', 'created_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772123)}]
(hbnb) show BaseModel 7da56403-cc45-4f1c-ad32-bfafeb2bb050
[BaseModel] (7da56403-cc45-4f1c-ad32-bfafeb2bb050) {'updated_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772167), 'id': '7da56403-cc45-4f1c-ad32-bfafeb2bb050', 'created_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772123)}
(hbnb) destroy BaseModel 7da56403-cc45-4f1c-ad32-bfafeb2bb050
(hbnb) show BaseModel 7da56403-cc45-4f1c-ad32-bfafeb2bb050
** no instance found **
(hbnb) quit
- Tafara Nyamhunga - Github
Public Domain. No copy write protection.