Skip to content

Commit

Permalink
ADD Get and Count Test for DBStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
jzamora5 committed Apr 29, 2020
1 parent d555504 commit 7d97fb4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_models/test_engine/test_db_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import pep8
import unittest
from models import storage
DBStorage = db_storage.DBStorage
classes = {"Amenity": Amenity, "City": City, "Place": Place,
"Review": Review, "State": State, "User": User}
Expand Down Expand Up @@ -86,3 +87,24 @@ def test_new(self):
@unittest.skipIf(models.storage_t != 'db', "not testing db storage")
def test_save(self):
"""Test that save properly saves objects to file.json"""

def test_get_db(self):
""" Tests method for obtaining an instance db storage"""
dic = {"name": "Cundinamarca"}
instance = State(**dic)
storage.new(instance)
storage.save()
get_instance = storage.get(State, instance.id)
self.assertEqual(get_instance, instance)

def test_count(self):
""" Tests count method db storage """
dic = {"name": "Vecindad"}
state = State(**dic)
storage.new(state)
dic = {"name": "Mexico", "state_id": state.id}
city = City(**dic)
storage.new(city)
storage.save()
c = storage.count()
self.assertEqual(len(storage.all()), c)

0 comments on commit 7d97fb4

Please sign in to comment.