- Name of the project :
0x00. AirBnB clone - The console
- Authors :
This is the first step of our first full web application: the AirBnB clone. Our console is able to work in interactive mode but also in non-interactive mode. It main goal is to manage the AirBnB objects. It is capable of creating new objects, retrieving an object from a file, doing operations on objects like counting and computing stats, updating attributes of an object and destroying them.
It is a program that receives commands from a user, our console has the following functions:
create
update
Destroy
store
persists
-> Objects
- 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
Steps:
sudo apt install python3.8
git clone https://github.com/paolo-abarca/holbertonschool-AirBnB_clone.git
./console.py
(hbnb)
you should see the following prompt waiting for your commands
$ echo "help" | ./console.py
(hbnb)
Documented commands (type help <topic>):
========================================
EOF help quit
(hbnb)
$
$ cat test_help
help
$
$ cat test_help | ./console.py
(hbnb)
Documented commands (type help <topic>):
========================================
EOF help quit
(hbnb)
$
$ ./console.py
(hbnb) help
Documented commands (type help <topic>):
========================================
EOF help quit
(hbnb)
(hbnb)
(hbnb) quit
$
General
- How to create a
Python package
- How to create a command interpreter in Python using the
cmd module
- What is
Unit testing
and how to implement it in alarge project
- How to
serialize
anddeserialize
a Class - How to
write
andread
a JSON file - How to manage
datetime
- What is an
UUID
- What is
*args
and how to use it - What is
**kwargs
and how to use it - How to handle
named arguments
in a function
we must run the tests in interactive and non-interactive mode
| Non interactive mode
echo "python3 -m unittest discover tests" | bash
| Interactive mode
python3 -m unittest discover tests"
(hbnb) create <[class]>
######salida######
(hbnb) create User
38f22813-2753-4d42-b37c-57a17f1e4f88
(hbnb)
all <class>
<nombre de clase>.all()
(hbnb) User.all()
["[User] (1aa89e6c-d6f0-4be5-96e8-05636eb60122) {'id': '1aa89e6c-d6f0-4be5-96e8-05636eb60122', 'created_at': datetime.datetime(2022, 7, 2, 23, 4, 16, 460854), 'updated_at': datetime.datetime(2022, 7, 2, 23, 4, 16, 460854), 'first_name': 'Zenkaiser', 'age': '89'}"]
(hbnb)
muestra una instancia especifica
================ Usage 1 ==============
(hbnb) show City 07062be7-fd57-4791-88a6-6a78806398c9
================ Usage 2 ==============
City.show(07062be7-fd57-4791-88a6-6a78806398c9)
========================Output======================================
[City] (07062be7-fd57-4791-88a6-6a78806398c9) {'id': '07062be7-fd57-4791-88a6-6a78806398c9', 'created_at': datetime.datetime(2022, 7, 1, 16, 6, 54, 356353), 'updated_at': datetime.datetime(2022, 7, 1, 16, 6, 54, 356365)}
(hbnb)
==================== Usage 1 ==================
destroy User 38f22813-2753-4d42-b37c-57a17f1e4f88
==================== Usage 2 ===================
destroy.User("38f22813-2753-4d42-b37c-57a17f1e4f88")
========================Output======================================
(hbnb) User.all()
["[User] (1aa89e6c-d6f0-4be5-96e8-05636eb60122) {'id': '1aa89e6c-d6f0-4be5-96e8-05636eb60122', 'created_at': datetime.datetime(2022, 7, 2, 23, 4, 16, 460854), 'updated_at': datetime.datetime(2022, 7, 2, 23, 4, 16, 460854), 'first_name': 'Zenkaiser', 'age': '89'}"]
(hbnb)
(hbnb) User.all()
["[User] (1aa89e6c-d6f0-4be5-96e8-05636eb60122) {'id': '1aa89e6c-d6f0-4be5-96e8-05636eb60122', 'created_at': datetime.datetime(2022, 7, 2, 23, 4, 16, 460854), 'updated_at': datetime.datetime(2022, 7, 2, 23, 4, 16, 460854), 'first_name': 'Zenkaiser', 'age': '89'}"]
(hbnb)
================= Usage 1 ======================
update User 49faff9a-6318-451f-87b6-910505c55907 first_name "Zenkaiser"
================= Usage 2 =======================
update.User(49faff9a-6318-451f-87b6-910505c55907, first_name, "Zenkaiser")
========================Output======================================
["[User] (1aa89e6c-d6f0-4be5-96e8-05636eb60122) {'id': '1aa89e6c-d6f0-4be5-96e8-05636eb60122', 'created_at': datetime.datetime(2022, 7, 2, 23, 4, 16, 460854), 'updated_at': datetime.datetime(2022, 7, 2, 23, 4, 16, 460854), 'first_name': 'Zenkaiser', 'age': '89'}"]
(hbnb)
python3 -m unittest discover tests
=============Output================
.............................................................
----------------------------------------------------------------------
Ran 32 tests in 0.231s
OK
with patch('sys.stdout', new=StringIO()) as f:
HBNBCommand().onecmd("help show")
Fernando J. Gonzales Pradinett - linkedin
Paolo Abarca - linkedin