5
5
6
6
from datetime import datetime
7
7
import inspect
8
+ import models
8
9
from models import place
9
10
from models .base_model import BaseModel
10
11
import pep8
@@ -70,68 +71,99 @@ def test_city_id_attr(self):
70
71
"""Test Place has attr city_id, and it's an empty string"""
71
72
place = Place ()
72
73
self .assertTrue (hasattr (place , "city_id" ))
73
- self .assertEqual (place .city_id , "" )
74
+ if models .storage_t == 'db' :
75
+ self .assertEqual (place .city_id , None )
76
+ else :
77
+ self .assertEqual (place .city_id , "" )
74
78
75
79
def test_user_id_attr (self ):
76
80
"""Test Place has attr user_id, and it's an empty string"""
77
81
place = Place ()
78
82
self .assertTrue (hasattr (place , "user_id" ))
79
- self .assertEqual (place .user_id , "" )
83
+ if models .storage_t == 'db' :
84
+ self .assertEqual (place .user_id , None )
85
+ else :
86
+ self .assertEqual (place .user_id , "" )
80
87
81
88
def test_name_attr (self ):
82
89
"""Test Place has attr name, and it's an empty string"""
83
90
place = Place ()
84
91
self .assertTrue (hasattr (place , "name" ))
85
- self .assertEqual (place .name , "" )
92
+ if models .storage_t == 'db' :
93
+ self .assertEqual (place .name , None )
94
+ else :
95
+ self .assertEqual (place .name , "" )
86
96
87
97
def test_description_attr (self ):
88
98
"""Test Place has attr description, and it's an empty string"""
89
99
place = Place ()
90
100
self .assertTrue (hasattr (place , "description" ))
91
- self .assertEqual (place .description , "" )
101
+ if models .storage_t == 'db' :
102
+ self .assertEqual (place .description , None )
103
+ else :
104
+ self .assertEqual (place .description , "" )
92
105
93
106
def test_number_rooms_attr (self ):
94
107
"""Test Place has attr number_rooms, and it's an int == 0"""
95
108
place = Place ()
96
109
self .assertTrue (hasattr (place , "number_rooms" ))
97
- self .assertEqual (type (place .number_rooms ), int )
98
- self .assertEqual (place .number_rooms , 0 )
110
+ if models .storage_t == 'db' :
111
+ self .assertEqual (place .number_rooms , None )
112
+ else :
113
+ self .assertEqual (type (place .number_rooms ), int )
114
+ self .assertEqual (place .number_rooms , 0 )
99
115
100
116
def test_number_bathrooms_attr (self ):
101
117
"""Test Place has attr number_bathrooms, and it's an int == 0"""
102
118
place = Place ()
103
119
self .assertTrue (hasattr (place , "number_bathrooms" ))
104
- self .assertEqual (type (place .number_bathrooms ), int )
105
- self .assertEqual (place .number_bathrooms , 0 )
120
+ if models .storage_t == 'db' :
121
+ self .assertEqual (place .number_bathrooms , None )
122
+ else :
123
+ self .assertEqual (type (place .number_bathrooms ), int )
124
+ self .assertEqual (place .number_bathrooms , 0 )
106
125
107
126
def test_max_guest_attr (self ):
108
127
"""Test Place has attr max_guest, and it's an int == 0"""
109
128
place = Place ()
110
129
self .assertTrue (hasattr (place , "max_guest" ))
111
- self .assertEqual (type (place .max_guest ), int )
112
- self .assertEqual (place .max_guest , 0 )
130
+ if models .storage_t == 'db' :
131
+ self .assertEqual (place .max_guest , None )
132
+ else :
133
+ self .assertEqual (type (place .max_guest ), int )
134
+ self .assertEqual (place .max_guest , 0 )
113
135
114
136
def test_price_by_night_attr (self ):
115
137
"""Test Place has attr price_by_night, and it's an int == 0"""
116
138
place = Place ()
117
139
self .assertTrue (hasattr (place , "price_by_night" ))
118
- self .assertEqual (type (place .price_by_night ), int )
119
- self .assertEqual (place .price_by_night , 0 )
140
+ if models .storage_t == 'db' :
141
+ self .assertEqual (place .price_by_night , None )
142
+ else :
143
+ self .assertEqual (type (place .price_by_night ), int )
144
+ self .assertEqual (place .price_by_night , 0 )
120
145
121
146
def test_latitude_attr (self ):
122
147
"""Test Place has attr latitude, and it's a float == 0.0"""
123
148
place = Place ()
124
149
self .assertTrue (hasattr (place , "latitude" ))
125
- self .assertEqual (type (place .latitude ), float )
126
- self .assertEqual (place .latitude , 0.0 )
150
+ if models .storage_t == 'db' :
151
+ self .assertEqual (place .latitude , None )
152
+ else :
153
+ self .assertEqual (type (place .latitude ), float )
154
+ self .assertEqual (place .latitude , 0.0 )
127
155
128
- def test_latitude_attr (self ):
156
+ def test_longitude_attr (self ):
129
157
"""Test Place has attr longitude, and it's a float == 0.0"""
130
158
place = Place ()
131
159
self .assertTrue (hasattr (place , "longitude" ))
132
- self .assertEqual (type (place .longitude ), float )
133
- self .assertEqual (place .longitude , 0.0 )
160
+ if models .storage_t == 'db' :
161
+ self .assertEqual (place .longitude , None )
162
+ else :
163
+ self .assertEqual (type (place .longitude ), float )
164
+ self .assertEqual (place .longitude , 0.0 )
134
165
166
+ @unittest .skipIf (models .storage_t == 'db' , "not testing File Storage" )
135
167
def test_amenity_ids_attr (self ):
136
168
"""Test Place has attr amenity_ids, and it's an empty list"""
137
169
place = Place ()
@@ -144,9 +176,11 @@ def test_to_dict_creates_dict(self):
144
176
p = Place ()
145
177
new_d = p .to_dict ()
146
178
self .assertEqual (type (new_d ), dict )
179
+ self .assertFalse ("_sa_instance_state" in new_d )
147
180
for attr in p .__dict__ :
148
- self .assertTrue (attr in new_d )
149
- self .assertTrue ("__class__" in new_d )
181
+ if attr is not "_sa_instance_state" :
182
+ self .assertTrue (attr in new_d )
183
+ self .assertTrue ("__class__" in new_d )
150
184
151
185
def test_to_dict_values (self ):
152
186
"""test that values in dict returned from to_dict are correct"""
0 commit comments