The console is the first segment of the AirBnB project that will collectively cover fundamental concepts of higher-level programming. The goal of the AirBnB project is to eventually deploy our server as a simple copy of the AirBnB website (HBnB). A command interpreter is created in this segment to manage objects for the AirBnB (HBnB) website.
- Functionalities
- Environment
- Installation
- File Descriptions
- Usage
- Examples of Use
- Bugs
- Authors
- License
This command interpreter provides the following functionalities:
- Create a new object (e.g., a new User or a new Place)
- Retrieve an object from a file, a database, etc.
- Perform operations on objects (count, compute stats, etc.)
- Update attributes of an object
- Destroy an object
This project is interpreted/tested on Ubuntu 20.04 LTS using Python 3.8.10.
- Clone this repository:
git clone https://github.com/alexaorrico/AirBnB_clone.git
- Access the AirBnB directory:
cd AirBnB_clone
- Run
hbnb
(interactively):./console.py
- 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 currently supports:EOF
: Exits the consolequit
: Exits the console<emptyline>
: Overwrites the default empty line method and does nothingcreate
: Creates a new instance of BaseModel, saves it (to the JSON file), and prints the iddestroy
: Deletes an instance based on the class name and id (saves the change into the JSON file)show
: Prints the string representation of an instance based on the class name and idall
: Prints all string representations of all instances based or not on the class nameupdate
: Updates an instance based on the class name and id by adding or updating attribute (saves 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__init__(self, *args, **kwargs)
: Initialization of the base model__str__(self)
: String representation of the BaseModel classsave(self)
: Updates the attributeupdated_at
with the current datetimeto_dict(self)
: Returns a dictionary containing all keys/values of the instance
-
Classes inherited from BaseModel:
amenity.py
city.py
place.py
review.py
state.py
user.py
-
-
models/engine
directory contains the File Storage class that handles JSON serialization and deserialization:file_storage.py
: Serializes instances to a JSON file & deserializes back to instancesall(self)
: Returns the dictionary__objects
new(self, obj)
: Sets in__objects
the obj with key.id
save(self)
: Serializes__objects
to the JSON file (path:__file_path
)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 theTestBaseModel
andTestBaseModelDocs
classesTestBaseModelDocs
class:setUpClass(cls)
: Set up for the doc teststest_pep8_conformance_base_model(self)
: Test thatmodels/base_model.py
conforms to PEP8test_pep8_conformance_test_base_model(self)
: Test thattests/test_models/test_base_model.py
conforms to PEP8test_bm_module_docstring(self)
: Test for thebase_model.py
module docstringtest_bm_class_docstring(self)
: Test for theBaseModel
class docstringtest_bm_func_docstrings(self)
: Test for the presence of docstrings inBaseModel
methods
TestBaseModel
class:test_is_base_model(self)
: Test that the instantiation of aBaseModel
workstest_created_at_instantiation(self)
: Testcreated_at
is a public instance attribute of typedatetime
test_updated_at_instantiation(self)
: Testupdated_at
is a public instance attribute of typedatetime
test_diff_datetime_objs(self)
: Test that twoBaseModel
instances have different datetime objects
-
test_models/test_amenity.py
: Contains theTestAmenityDocs
classsetUpClass(cls)
: Set up for the doc teststest_pep8_conformance_amenity(self)
: Test thatmodels/amenity.py
conforms to PEP8test_pep8_conformance_test_amenity(self)
: Test thattests/test_models/test_amenity.py
conforms to PEP8test_amenity_module_docstring(self)
: Test for theamenity.py
module docstringtest_amenity_class_docstring(self)
: Test for theAmenity
class docstring
-
test_models/test_city.py
: Contains theTestCityDocs
classsetUpClass(cls)
: Set up for the doc teststest_pep8_conformance_city(self)
: Test thatmodels/city.py
conforms to PEP8test_pep8_conformance_test_city(self)
: Test thattests/test_models/test_city.py
conforms to PEP8test_city_module_docstring(self)
: Test for thecity.py
module docstringtest_city_class_docstring(self)
: Test for theCity
class docstring
-
test_models/test_file_storage.py
: Contains theTestFileStorageDocs
classsetUpClass(cls)
: Set up for the doc teststest_pep8_conformance_file_storage(self)
: Test thatmodels/file_storage.py
conforms to PEP8test_pep8_conformance_test_file_storage(self)
: Test thattests/test_models/test_file_storage.py
conforms to PEP8test_file_storage_module_docstring(self)
: Test for thefile_storage.py
module docstringtest_file_storage_class_docstring(self)
: Test for theFileStorage
class docstring
-
test_models/test_place.py
: Contains theTestPlaceDoc
classsetUpClass(cls)
: Set up for the doc teststest_pep8_conformance_place(self)
: Test thatmodels/place.py
conforms to PEP8test_pep8_conformance_test_place(self)
: Test thattests/test_models/test_place.py
conforms to PEP8test_place_module_docstring(self)
: Test for theplace.py
module docstringtest_place_class_docstring(self)
: Test for thePlace
class docstring
-
test_models/test_review.py
: Contains theTestReviewDocs
classsetUpClass(cls)
: Set up for the doc teststest_pep8_conformance_review(self)
: Test thatmodels/review.py
conforms to PEP8test_pep8_conformance_test_review(self)
: Test thattests/test_models/test_review.py
conforms to PEP8test_review_module_docstring(self)
: Test for thereview.py
module docstringtest_review_class_docstring(self)
: Test for theReview
class docstring
-
test_models/test_state.py
: Contains theTestStateDocs
classsetUpClass(cls)
: Set up for the doc teststest_pep8_conformance_state(self)
: Test thatmodels/state.py
conforms to PEP8test_pep8_conformance_test_state(self)
: Test thattests/test_models/test_state.py
conforms to PEP8test_state_module_docstring(self)
: Test for thestate.py
module docstringtest_state_class_docstring(self)
: Test for theState
class docstring
-
test_models/test_user.py
: Contains theTestUserDocs
classsetUpClass(cls)
: Set up for the doc teststest_pep8_conformance_user(self)
: Test thatmodels/user.py
conforms to PEP8- `test_pep8_conformance_test_user
-
(self): Test that
tests/test_models/test_user.pyconforms to PEP8 -
test_user_module_docstring(self): Test for the
user.pymodule docstring -
test_user_class_docstring(self): Test for the
User` class docstring
The console works in both interactive and non-interactive modes.
$ ./console.py
(hbnb) help
Documented commands (type help <topic>):
========================================
EOF all create destroy help quit show update
(hbnb) create User
(hbnb) show User 1234-1234-1234
(hbnb) destroy User 1234-1234-1234
(hbnb) all User
(hbnb) update
Bugs
No known bugs at this time.
No known bugs at this time.
Public Domain. No copy write protection.