-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconftest.py
239 lines (201 loc) · 6.29 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
from django.contrib.auth import get_user_model
from seekers.models import Seeker
from apartments.models import Apartment, City
from contacts.models import Connection
from seekers.forms import SeekerCreationForm
from apartments.forms import ApartmentCreationForm
from search.forms import SearchForm, PreferencesSearchForm
from users.forms import UserCreationForm
import pytest
@pytest.fixture
def superuser_model(db):
super_user = get_user_model().objects.create_superuser(
'[email protected]', 'first_name', 'last_name', '1900-01-01', 'password'
)
return super_user
@pytest.fixture
def user_model(db):
user = get_user_model().objects.create_user(
'[email protected]', 'first_name', 'last_name', '1900-01-01', 'password'
)
return user
@pytest.fixture
def city_model(db):
new_city = City(cityName='nice_city')
new_city.save()
return new_city
@pytest.fixture
def city_model_Tel_Aviv(db):
new_city = City(cityName='Tel Aviv')
new_city.save()
return new_city
@pytest.fixture
def seeker_model(db, city_model):
new_base_user = get_user_model().objects.create_user(
'[email protected]', 'seeker', 'macseek', '1900-01-01', 'password'
)
new_base_user.save()
new_seeker = Seeker(
base_user=new_base_user,
city=city_model,
start_date='1900-01-01',
min_rent=1,
max_rent=1000,
num_of_roomates=2,
num_of_rooms=2,
about='test-seeker'
)
new_seeker.save()
return new_seeker
@pytest.fixture
def apartment_model(db, city_model):
new_owner = get_user_model().objects.create_user(
'[email protected]', 'owner', 'own', '1900-01-01', 'password'
)
new_owner.save()
new_apartment = Apartment(
owner=new_owner,
city=city_model,
address='street',
rent=4500,
num_of_roomates=2,
num_of_rooms=3,
start_date='2021-1-1',
about='Hey!',
image_url='www.some-url.com',
)
new_apartment.save()
return new_apartment
@pytest.fixture
def apart_success_search(db, city_model_Tel_Aviv):
new_owner = get_user_model().objects.create_user(
'[email protected]', 'owner', 'own', '1900-01-01', 'password'
)
new_owner.save()
new_apartment = Apartment(
owner=new_owner,
city=city_model_Tel_Aviv,
address='street',
rent=2500,
num_of_roomates=2,
num_of_rooms=3,
start_date='2021-03-02',
about='Hey!',
image_url='www.some-url.com',
)
new_apartment.save()
return new_apartment
@pytest.fixture
def apart2_success_search(db, city_model_Tel_Aviv):
new_owner = get_user_model().objects.create_user(
'[email protected]', 'owner', 'own', '1900-01-01', 'password'
)
new_owner.save()
new_apartment = Apartment(
owner=new_owner,
city=city_model_Tel_Aviv,
address='street',
rent=2750,
num_of_roomates=2,
num_of_rooms=3,
start_date='2021-02-02',
about='Hey!',
image_url='www.some-url.com',
)
new_apartment.save()
return new_apartment
@pytest.fixture
def valid_user_creation_form(db):
return UserCreationForm(data={
'email': '[email protected]',
'first_name': 'first',
'last_name': 'last',
'birth_date': '1900-1-1',
'password1': 'pass123word',
'password2': 'pass123word',
})
@pytest.fixture
def valid_seeker_creation_form(db, city_model):
return SeekerCreationForm(data={
'city': city_model,
'start_date': '1900-1-1',
'min_rent': 1000,
'max_rent': 4000,
'num_of_roomates': 2,
'num_of_rooms': 3,
'about': 'about',
})
@pytest.fixture
def valid_apartment_creation_form(db, city_model):
return ApartmentCreationForm(data={
'city': city_model,
'address': 'address',
'rent': 10,
'num_of_roomates': 2,
'num_of_rooms': 2,
'start_date': '2020-1-1',
'about': 'about',
})
@pytest.fixture
def valid_search_form(db, city_model_Tel_Aviv):
return SearchForm(data={
'city': city_model_Tel_Aviv,
'start_date': '2021-03-03',
'min_rent': 2000,
'max_rent': 3000,
'num_of_roomates': 2,
'num_of_rooms': 3,
})
@pytest.fixture
def valid_preferences_form(db):
return PreferencesSearchForm()
@pytest.fixture
def make_seeker(city_model):
def _make_seeker(user, s_date, min_r, max_r, roomates, rooms, about):
seeker = Seeker(
base_user=user,
city=city_model,
start_date=s_date,
min_rent=min_r,
max_rent=max_r,
num_of_roomates=roomates,
num_of_rooms=rooms,
about=about
)
seeker.save()
return seeker
return _make_seeker
@pytest.fixture
def make_apartment(city_model):
def _make_apartment(user, addr, rent, roomates, rooms, s_date):
apartmant = Apartment(
owner=user,
city=city_model,
address=addr,
rent=rent,
num_of_roomates=roomates,
num_of_rooms=rooms,
start_date=s_date
)
apartmant.save()
return apartmant
return _make_apartment
@pytest.fixture
def sample_connection(db, make_seeker, make_apartment):
user1 = get_user_model().objects.create_user("[email protected]", "test1", "test", "1995-05-05", "testing")
seeker = make_seeker(user1, "2020-05-05", 100, 1000, 2, 2, "Hello")
user2 = get_user_model().objects.create_user("[email protected]", "test3", "test", "1995-05-05", "testing")
apartment = make_apartment(user2, "Hatotahim 5", 2500, 2, 3, "2020-05-05")
con = Connection(seeker=seeker, apartment=apartment)
con.save()
return con
@pytest.fixture
def log_in_sample_connection_seeker(db, sample_connection, client):
seeker_email = "[email protected]"
seeker_pass = "testing" # credentials for sample_connection.seeker
client.login(email=seeker_email, password=seeker_pass)
@pytest.fixture
def log_in_sample_connection_apartment(db, sample_connection, client):
owner_email = "[email protected]"
owner_pass = "testing" # credentials for sample_connection.apartment
client.login(email=owner_email, password=owner_pass)