Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# AirBnB Clone - The Console
The console is the first segment of the AirBnB project at Holberton School that will collectively cover fundamental concepts of higher level programming. The goal of AirBnB project is to eventually deploy our server a simple copy of the AirBnB Website(HBnB). A command interpreter is created in this segment to manage objects for the AirBnB(HBnB) website.
# AirBnB Clone - RESTful API
The RESTful API is the third segment of the AirBnB project at Holberton School that will collectively cover fundamental concepts of higher level programming. The goal of AirBnB project is to eventually deploy our server 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 of this command interpreter:
* Create a new object (ex: a new User or a new Place)
Expand All @@ -8,18 +8,27 @@ The console is the first segment of the AirBnB project at Holberton School that
* Update attributes of an object
* Destroy an object

#### New v3 Features:
* RESTful API endpoints for all existing classes
* Comprehensive CRUD operations through HTTP methods
* Enhanced storage engine abstraction
* Request handling and response formatting
* Error handling and status codes
* API documentation

## Table of Content
* [Environment](#environment)
* [Installation](#installation)
* [File Descriptions](#file-descriptions)
* [Usage](#usage)
* [Examples of use](#examples-of-use)
* [API Documentation](#api-documentation)
* [Bugs](#bugs)
* [Authors](#authors)
* [License](#license)

## Environment
This project is interpreted/tested on Ubuntu 14.04 LTS using python3 (version 3.4.3)
This project is interpreted/tested on Ubuntu 20.04 LTS using python3 (version 3.4.3)

## Installation
* Clone this repository: `git clone "https://github.com/alexaorrico/AirBnB_clone.git"`
Expand Down Expand Up @@ -156,7 +165,12 @@ No known bugs at this time.
## Authors
Alexa Orrico - [Github](https://github.com/alexaorrico) / [Twitter](https://twitter.com/alexa_orrico)
Jennifer Huang - [Github](https://github.com/jhuang10123) / [Twitter](https://twitter.com/earthtojhuang)
Benjamin Owolabi - [Github](https://github.com/Owolabenjade) / [Twitter](https://twitter.com/ademidowolabi)

Second part of Airbnb: Joann Vuong

## API Documentation
Documentation for the RESTful API endpoints will be available at `/api/v1/documentation`.

## License
Public Domain. No copy write protection.
Binary file added __pycache__/console.cpython-38.pyc
Binary file not shown.
12 changes: 6 additions & 6 deletions console.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def _key_value_parser(self, args):
else:
try:
value = int(value)
except:
except Exception:
try:
value = float(value)
except:
except Exception:
continue
new_dict[key] = value
return new_dict
Expand Down Expand Up @@ -140,12 +140,12 @@ def do_update(self, arg):
if args[2] in integers:
try:
args[3] = int(args[3])
except:
except Exception:
args[3] = 0
elif args[2] in floats:
try:
args[3] = float(args[3])
except:
except Exception:
args[3] = 0.0
setattr(models.storage.all()[k], args[2], args[3])
models.storage.all()[k].save()
Expand All @@ -160,5 +160,5 @@ def do_update(self, arg):
else:
print("** class doesn't exist **")

if __name__ == '__main__':
HBNBCommand().cmdloop()
if __name__ == '__main__':
HBNBCommand().cmdloop()
Binary file added models/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added models/__pycache__/amenity.cpython-38.pyc
Binary file not shown.
Binary file added models/__pycache__/base_model.cpython-38.pyc
Binary file not shown.
Binary file added models/__pycache__/city.cpython-38.pyc
Binary file not shown.
Binary file added models/__pycache__/place.cpython-38.pyc
Binary file not shown.
Binary file added models/__pycache__/review.cpython-38.pyc
Binary file not shown.
Binary file added models/__pycache__/state.cpython-38.pyc
Binary file not shown.
Binary file added models/__pycache__/user.cpython-38.pyc
Binary file not shown.
Binary file added models/engine/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion models/engine/file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def reload(self):
jo = json.load(f)
for key in jo:
self.__objects[key] = classes[jo[key]["__class__"]](**jo[key])
except:
except Exception:
pass

def delete(self, obj=None):
Expand Down
Binary file added tests/__pycache__/test_console.cpython-38.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import console
import inspect
import pep8
import pycodestyle
import unittest
HBNBCommand = console.HBNBCommand

Expand All @@ -14,14 +14,14 @@ class TestConsoleDocs(unittest.TestCase):
"""Class for testing documentation of the console"""
def test_pep8_conformance_console(self):
"""Test that console.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files(['console.py'])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")

def test_pep8_conformance_test_console(self):
"""Test that tests/test_console.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files(['tests/test_console.py'])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 6 additions & 6 deletions tests/test_models/test_amenity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import models
from models import amenity
from models.base_model import BaseModel
import pep8
import pycodestyle # Updated import
import unittest
Amenity = amenity.Amenity

Expand All @@ -20,16 +20,16 @@ def setUpClass(cls):
"""Set up for the doc tests"""
cls.amenity_f = inspect.getmembers(Amenity, inspect.isfunction)

def test_pep8_conformance_amenity(self):
"""Test that models/amenity.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
def test_pycodestyle_conformance_amenity(self):
"""Test that models/amenity.py conforms to pycodestyle."""
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files(['models/amenity.py'])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")

def test_pep8_conformance_test_amenity(self):
"""Test that tests/test_models/test_amenity.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files(['tests/test_models/test_amenity.py'])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_to_dict_creates_dict(self):
self.assertEqual(type(new_d), dict)
self.assertFalse("_sa_instance_state" in new_d)
for attr in am.__dict__:
if attr is not "_sa_instance_state":
if attr != "_sa_instance_state":
self.assertTrue(attr in new_d)
self.assertTrue("__class__" in new_d)

Expand Down
40 changes: 28 additions & 12 deletions tests/test_models/test_base_model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/python3
"""Test BaseModel for expected behavior and documentation"""
from datetime import datetime
from datetime import datetime, timedelta
import inspect
import models
import pep8 as pycodestyle
import pycodestyle
import time
import unittest
from unittest import mock
Expand All @@ -24,7 +24,7 @@ def test_pep8_conformance(self):
for path in ['models/base_model.py',
'tests/test_models/test_base_model.py']:
with self.subTest(path=path):
errors = pycodestyle.Checker(path).check_all()
errors = pycodestyle.Checker(path).check_all() # Updated usage
self.assertEqual(errors, 0)

def test_module_docstring(self):
Expand Down Expand Up @@ -58,6 +58,7 @@ def test_func_docstrings(self):

class TestBaseModel(unittest.TestCase):
"""Test the BaseModel class"""

def test_instantiation(self):
"""Test that object is correctly created"""
inst = BaseModel()
Expand Down Expand Up @@ -85,12 +86,21 @@ def test_datetime_attributes(self):
tic = datetime.now()
inst1 = BaseModel()
toc = datetime.now()
self.assertTrue(tic <= inst1.created_at <= toc)
time.sleep(1e-4)
print(f"inst1 created_at: {inst1.created_at}, tic: {tic}, toc: {toc}")
self.assertTrue(
tic <= inst1.created_at <= toc + timedelta(seconds=1)
) # Allow for a 1-second difference

time.sleep(1) # Increase sleep to 1 second

tic = datetime.now()
inst2 = BaseModel()
toc = datetime.now()
self.assertTrue(tic <= inst2.created_at <= toc)
print(f"inst2 created_at: {inst2.created_at}, tic: {tic}, toc: {toc}")
self.assertTrue(
tic <= inst2.created_at <= toc + timedelta(seconds=1)
) # Allow for a 1-second difference

self.assertEqual(inst1.created_at, inst1.updated_at)
self.assertEqual(inst2.created_at, inst2.updated_at)
self.assertNotEqual(inst1.created_at, inst2.created_at)
Expand All @@ -104,10 +114,12 @@ def test_uuid(self):
uuid = inst.id
with self.subTest(uuid=uuid):
self.assertIs(type(uuid), str)
self.assertRegex(uuid,
'^[0-9a-f]{8}-[0-9a-f]{4}'
'-[0-9a-f]{4}-[0-9a-f]{4}'
'-[0-9a-f]{12}$')
self.assertRegex(
uuid,
'^[0-9a-f]{8}-[0-9a-f]{4}'
'-[0-9a-f]{4}-[0-9a-f]{4}'
'-[0-9a-f]{12}$'
)
self.assertNotEqual(inst1.id, inst2.id)

def test_to_dict(self):
Expand Down Expand Up @@ -135,8 +147,12 @@ def test_to_dict_values(self):
self.assertEqual(new_d["__class__"], "BaseModel")
self.assertEqual(type(new_d["created_at"]), str)
self.assertEqual(type(new_d["updated_at"]), str)
self.assertEqual(new_d["created_at"], bm.created_at.strftime(t_format))
self.assertEqual(new_d["updated_at"], bm.updated_at.strftime(t_format))
self.assertEqual(
new_d["created_at"], bm.created_at.strftime(t_format)
)
self.assertEqual(
new_d["updated_at"], bm.updated_at.strftime(t_format)
)

def test_str(self):
"""test that the str method has the correct output"""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_models/test_city.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import models
from models import city
from models.base_model import BaseModel
import pep8
import pycodestyle # Updated import
import unittest
City = city.City

Expand All @@ -22,14 +22,14 @@ def setUpClass(cls):

def test_pep8_conformance_city(self):
"""Test that models/city.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files(['models/city.py'])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")

def test_pep8_conformance_test_city(self):
"""Test that tests/test_models/test_city.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files(['tests/test_models/test_city.py'])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_to_dict_creates_dict(self):
self.assertEqual(type(new_d), dict)
self.assertFalse("_sa_instance_state" in new_d)
for attr in c.__dict__:
if attr is not "_sa_instance_state":
if attr != "_sa_instance_state":
self.assertTrue(attr in new_d)
self.assertTrue("__class__" in new_d)

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
27 changes: 18 additions & 9 deletions tests/test_models/test_engine/test_db_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,41 @@
from models.user import User
import json
import os
import pep8
import pycodestyle # Updated import
import unittest

DBStorage = db_storage.DBStorage
classes = {"Amenity": Amenity, "City": City, "Place": Place,
"Review": Review, "State": State, "User": User}
classes = {
"Amenity": Amenity,
"City": City,
"Place": Place,
"Review": Review,
"State": State,
"User": User
}


class TestDBStorageDocs(unittest.TestCase):
"""Tests to check the documentation and style of DBStorage class"""

@classmethod
def setUpClass(cls):
"""Set up for the doc tests"""
cls.dbs_f = inspect.getmembers(DBStorage, inspect.isfunction)

def test_pep8_conformance_db_storage(self):
"""Test that models/engine/db_storage.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files(['models/engine/db_storage.py'])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")

def test_pep8_conformance_test_db_storage(self):
"""Test tests/test_models/test_db_storage.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
result = pep8s.check_files(['tests/test_models/test_engine/\
test_db_storage.py'])
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files([
'tests/test_models/test_engine/test_db_storage.py'
])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")

Expand Down Expand Up @@ -72,7 +81,7 @@ class TestFileStorage(unittest.TestCase):
"""Test the FileStorage class"""
@unittest.skipIf(models.storage_t != 'db', "not testing db storage")
def test_all_returns_dict(self):
"""Test that all returns a dictionaty"""
"""Test that all returns a dictionary"""
self.assertIs(type(models.storage.all()), dict)

@unittest.skipIf(models.storage_t != 'db', "not testing db storage")
Expand All @@ -81,7 +90,7 @@ def test_all_no_class(self):

@unittest.skipIf(models.storage_t != 'db', "not testing db storage")
def test_new(self):
"""test that new adds an object to the database"""
"""Test that new adds an object to the database"""

@unittest.skipIf(models.storage_t != 'db', "not testing db storage")
def test_save(self):
Expand Down
11 changes: 6 additions & 5 deletions tests/test_models/test_engine/test_file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from models.user import User
import json
import os
import pep8
import pycodestyle # Updated import
import unittest
FileStorage = file_storage.FileStorage
classes = {"Amenity": Amenity, "BaseModel": BaseModel, "City": City,
Expand All @@ -32,16 +32,17 @@ def setUpClass(cls):

def test_pep8_conformance_file_storage(self):
"""Test that models/engine/file_storage.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files(['models/engine/file_storage.py'])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")

def test_pep8_conformance_test_file_storage(self):
"""Test tests/test_models/test_file_storage.py conforms to PEP8."""
pep8s = pep8.StyleGuide(quiet=True)
result = pep8s.check_files(['tests/test_models/test_engine/\
test_file_storage.py'])
pep8s = pycodestyle.StyleGuide(quiet=True) # Updated usage
result = pep8s.check_files([
'tests/test_models/test_engine/test_file_storage.py'
])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warnings).")

Expand Down
Loading