From 14822229bb3f42fe948536d55f1794a9a5671b5a Mon Sep 17 00:00:00 2001 From: Erez Cohen Date: Sun, 1 May 2022 09:29:00 +0300 Subject: [PATCH] Create shared conftets file There is shared conftest file that create fixture of all models to be used in the tests, And from now on, any model that is required to put information in a conftest file, it will put in the shared conftest file Signed-off-by: Erez Cohen --- conftest.py | 102 ++++++++++++++++++++-- dogowner/test_dog_owner.py | 169 +++++++++++++++++-------------------- main/tests.py | 42 +-------- message/tests.py | 33 -------- orders/tests.py | 10 --- review/conftest.py | 33 -------- review/tests.py | 25 +++--- 7 files changed, 188 insertions(+), 226 deletions(-) delete mode 100644 review/conftest.py diff --git a/conftest.py b/conftest.py index 5234bb2..39d2db9 100644 --- a/conftest.py +++ b/conftest.py @@ -1,13 +1,91 @@ import pytest +import datetime +from django.utils import timezone +from message.models import Message, AuthorOptions from daycare.models import DayCare, Image +from dogowner.models import DogOwner +from orders.models import Order +from review.models import Review @pytest.fixture -def create_daycare_user(): - return DayCare.create(email="test@gmail.com", username="testuser01", password="pass", - name="Puppies", description="This is the first daycare test", - price_per_day=10, - capacity=50, area="Merkaz", city="Tel-Aviv", address="The best street 5") +def create_order(): + return Order.create(dog_owner_id=DogOwner.objects.get(id=1), + daycare_id=DayCare.objects.get(id=1), + start_date=timezone.now(), + end_date=timezone.now() + datetime.timedelta(days=3), + price_per_day=100, + ) + + +@pytest.fixture +def dogowner_message_to_daycare1(): + return Message.create(author=AuthorOptions.DogOwner, + dogowner_id=DogOwner.objects.get(pk=1), + daycare_id=DayCare.objects.get(pk=1), + text='Hello this is the test message1 from owner to day care') + + +@pytest.fixture +def daycare1_reply_to_dogonwer_message(): + return Message.create(author=AuthorOptions.DayCare, + dogowner_id=DogOwner.objects.get(pk=1), + daycare_id=DayCare.objects.get(pk=1), + text='This is reply to first message from daycare to owner') + + +@pytest.fixture +def daycare2_message_to_dogowner(): + return Message.create(author=AuthorOptions.DayCare, + dogowner_id=DogOwner.objects.get(pk=1), + daycare_id=DayCare.objects.get(pk=2), + text='Hello this new chat between daycare2 and dogowner') + + +@pytest.fixture +def daycare3_message_to_dogowner(): + return Message.create(author=AuthorOptions.DayCare, + dogowner_id=DogOwner.objects.get(pk=1), + daycare_id=DayCare.objects.get(pk=3), + text='new chat between daycare3 and dogowner') + + +@pytest.fixture +def create_dog_owner_user(): + return DogOwner.create(email='testuser@gmail.com', + username='testDogOwner', + password='testpassowrd', + dog_name='kliford', + first_name='NEW', + last_name='USER', + phone_number=1234567890, + dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, + dog_weight=6, + dog_gender='M' + ) + + +@pytest.fixture +def daycare_data(): + pytest.EMAIL = "test@gmail.com" + pytest.DAYCARE_USERNAME = "testDayCare" + pytest.DAYCARE_PASSWORD = "pass" + pytest.NAME = "Puppies" + pytest.DESCRIPTION = "This is the first daycare test" + pytest.PRICE_PER_DAY = 10 + pytest.CAPACITY = 50 + pytest.AREA = "Merkaz" + pytest.CITY = "Tel-Aviv" + pytest.ADDRESS = "The best street 5" + + +@pytest.fixture +def create_daycare_user(daycare_data): + return DayCare.create(email=pytest.EMAIL, username=pytest.DAYCARE_USERNAME, password=pytest.DAYCARE_PASSWORD, + name=pytest.NAME, description=pytest.DESCRIPTION, price_per_day=pytest.CAPACITY, + capacity=pytest.CAPACITY, area=pytest.AREA, city=pytest.CITY, address=pytest.ADDRESS) @pytest.fixture @@ -18,3 +96,17 @@ def create_image1(create_daycare_user): @pytest.fixture def create_image2(create_daycare_user): return Image.create(url="../../static/images/daycare_image_test_02.jpeg", daycare_id=create_daycare_user) + + +@pytest.fixture +def review_data(create_dog_owner_user, create_daycare_user): + pytest.REVIEW = 'sample review' + pytest.RATING = 5 + pytest.DAY_CARE_ID = create_daycare_user.id + pytest.DOG_OWNER_ID = create_dog_owner_user.id + + +@pytest.fixture +def review(review_data): + return Review.create(review=pytest.REVIEW, rating=pytest.RATING, daycare_id=pytest.DAY_CARE_ID, + dogowner_id=pytest.DOG_OWNER_ID) diff --git a/dogowner/test_dog_owner.py b/dogowner/test_dog_owner.py index 924329c..97dba7d 100644 --- a/dogowner/test_dog_owner.py +++ b/dogowner/test_dog_owner.py @@ -4,36 +4,6 @@ from .validators import MaxLength import pytest -EMAIL = 'testuser@gmail.com' -USERNAME = 'testuser01' -PASSWORD = 'testpassowrd' -DOG_NAME = 'kliford' -FIRST_NAME = 'NEW' -LAST_NAME = 'USER' -PHONE_NUMBER = 1234567890 -DOG_RACE = 'lavrador' -DOG_PICTURE_URL = "https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg" -DOG_AGE = 10 -DOG_WEIGHT = 6 -DOG_GENDER = 'M' - - -@pytest.fixture -def create_dog_owner_user(): - return DogOwner.create(email=EMAIL, - username=USERNAME, - password=PASSWORD, - dog_name=DOG_NAME, - first_name=FIRST_NAME, - last_name=LAST_NAME, - phone_number=PHONE_NUMBER, - dog_race=DOG_RACE, - dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, - dog_weight=DOG_WEIGHT, - dog_gender=DOG_GENDER - ) - @pytest.mark.django_db class TestDogOwnerModel: @@ -43,7 +13,7 @@ def test_create_dog_owner(self, create_dog_owner_user): assert create_dog_owner_user in DogOwner.objects.all() def test_del_dogowner(self, create_dog_owner_user): - dogOwner_01 = DogOwner.objects.get(first_name=FIRST_NAME) + dogOwner_01 = DogOwner.objects.get(first_name='NEW') dogOwner_01.user.delete() assert dogOwner_01 not in DogOwner.objects.all() assert dogOwner_01.user not in User.objects.all() @@ -51,132 +21,145 @@ def test_del_dogowner(self, create_dog_owner_user): def test_duplicate_creation_dog_owner_user(self): with pytest.raises(ValidationError, match="Invalid username - username already exist"): for i in range(2): - DogOwner.create(email=EMAIL, username='SAME_USER_NAME_03', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='SAME_USER_NAME_03', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='USER', + phone_number=1234567890, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06" + "/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_invalid_email(self): with pytest.raises(ValidationError, match="'Enter a valid email address.'", ): - DogOwner.create(email='INVALID_EMAIL', username='testuser04', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='INVALID_EMAIL', username='testuser04', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='USER', + phone_number=1234567890, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_invalid_phone_as_txt(self): with pytest.raises(ValidationError, match="Invalid phone - phone should be number."): - DogOwner.create(email=EMAIL, username='testuser05', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number='tests', dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser05', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='USER', + phone_number='tests', dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_invalid_phone_short(self): with pytest.raises(ValidationError, match="Invalid phone - phone should be 10 digits."): - DogOwner.create(email=EMAIL, username='testuser06', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=123456789, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser06', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='USER', + phone_number=123456789, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_invalid_phone_long(self): with pytest.raises(ValidationError, match="Invalid phone - phone should be 10 digits."): - DogOwner.create(email=EMAIL, username='testuser06', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=123456789123, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser06', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='USER', + phone_number=123456789123, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_invalid_dog_gender(self): with pytest.raises(ValidationError, match="Invalid gender - please choose 'M','F' or 'UN."): - DogOwner.create(email=EMAIL, username='testuser07', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender='NOT_FROM_CHOICES' + DogOwner.create(email='testuser@gmail.com', username='testuser07', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='USER', + phone_number=1234567890, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='NOT_FROM_CHOICES' ) def test_dog_owner_user_creation_with_long_first_name(self): with pytest.raises(ValidationError, match=f"""Invalid FIRST_NAME - max length is {MaxLength["FIRST_NAME"].value}."""): - DogOwner.create(email=EMAIL, username='testuser08', password=PASSWORD, - dog_name=DOG_NAME, first_name='THIS FIRST NAME IS TOO LONG', last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser08', password='testpassowrd', + dog_name='kliford', first_name='THIS FIRST NAME IS TOO LONG', last_name='USER', + phone_number=1234567890, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_long_last_name(self): with pytest.raises(ValidationError, match=f"""Invalid LAST_NAME - max length is {MaxLength["LAST_NAME"].value}."""): - DogOwner.create(email=EMAIL, username='testuser09', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name='THIS LAST NAME IS TOO LONG', - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser09', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='THIS LAST NAME IS TOO LONG', + phone_number=1234567890, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_long_dog_race(self): with pytest.raises(ValidationError, match=f"""Invalid DOG_RACE - max length is {MaxLength["DOG_RACE"].value}."""): - DogOwner.create(email=EMAIL, username='testuser10', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race='THIS DOG RACE IS TOO LONG WAY TOO LONG ', - dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser10', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='USER', + phone_number=1234567890, dog_race='THIS DOG RACE IS TOO LONG WAY TOO LONG ', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_long_dog_name(self): with pytest.raises(ValidationError, match=f"""Invalid DOG_NAME - max length is {MaxLength["DOG_NAME"].value}."""): - DogOwner.create(email=EMAIL, username='testuser11', password=PASSWORD, - dog_name='THIS DOG NAME IS TOO LONG', first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, - dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser11', password='testpassowrd', + dog_name='THIS DOG NAME IS TOO LONG', first_name='NEW', last_name='USER', + phone_number=1234567890, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_non_alfa_first_name(self): with pytest.raises(ValidationError, match="Invalid FIRST_NAME -" " please enter only alphabet and space characters."): - DogOwner.create(email=EMAIL, username='testuser12', password=PASSWORD, - dog_name=DOG_NAME, first_name='FIRSTNAME1', last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser12', password='testpassowrd', + dog_name='kliford', first_name='FIRSTNAME1', last_name='USER', + phone_number=1234567890, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_non_alfa_last_name(self): with pytest.raises(ValidationError, match="Invalid LAST_NAME -" " please enter only alphabet and space characters."): - DogOwner.create(email=EMAIL, username='testuser13', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name='LASTNAME2', - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser13', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='LASTNAME2', + phone_number=1234567890, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_non_alfa_dog_race(self): with pytest.raises(ValidationError, match="Invalid DOG_RACE -" " please enter only alphabet and space characters."): - DogOwner.create(email=EMAIL, username='testuser14', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race='DOGRACE1', dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser14', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='USER', + phone_number=1234567890, dog_race='DOGRACE1', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_non_alfa_dog_name(self): with pytest.raises(ValidationError, match="Invalid DOG_NAME -" " please enter only alphabet and space characters."): - DogOwner.create(email=EMAIL, username='testuser15', password=PASSWORD, - dog_name='DOGNAME1', first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, dog_picture_url=DOG_PICTURE_URL, - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + DogOwner.create(email='testuser@gmail.com', username='testuser15', password='testpassowrd', + dog_name='DOGNAME1', first_name='NEW', last_name='USER', + phone_number=1234567890, dog_race='lavrador', + dog_picture_url="https://www.akc.org/wp-content/uploads/2019/06/Bohemian-Shepherd.1.jpg", + dog_age=10, dog_weight=6, dog_gender='M' ) def test_dog_owner_user_creation_with_url_not_an_image(self): with pytest.raises(ValidationError, match="""Invalid image URL - URL should end with '.png', '.jpg' or '.jpeg'."""): - DogOwner.create(email=EMAIL, username='testuser17', password=PASSWORD, - dog_name=DOG_NAME, first_name=FIRST_NAME, last_name=LAST_NAME, - phone_number=PHONE_NUMBER, dog_race=DOG_RACE, + DogOwner.create(email='testuser@gmail.com', username='testuser17', password='testpassowrd', + dog_name='kliford', first_name='NEW', last_name='USER', + phone_number=1234567890, dog_race='lavrador', dog_picture_url="https://www.not/an/image.com", - dog_age=DOG_AGE, dog_weight=DOG_WEIGHT, dog_gender=DOG_GENDER + dog_age=10, dog_weight=6, dog_gender='M' ) diff --git a/main/tests.py b/main/tests.py index 83033b4..a2731e1 100644 --- a/main/tests.py +++ b/main/tests.py @@ -1,22 +1,4 @@ import pytest -from dogowner.models import DogOwner - - -@pytest.fixture -def create_dog_owner_user(): - return DogOwner.create(email='dogowner@address.com', - username='dogOwnerUser01', - password='password123', - dog_name='dog name', - first_name='test', - last_name='user', - phone_number=1234567890, - dog_race='dog race', - dog_picture_url='https://www.google.com/user1.jpg', - dog_age=4, - dog_weight=2, - dog_gender='M' - ) @pytest.mark.django_db @@ -34,28 +16,10 @@ def test_enter_login_page(self, client): response = client.get('/login/') assert response.status_code == 200 - def test_valid_login_dog_owner_user_info(self, client, create_dog_owner_user): - previous_logged_user = client.get('/').wsgi_request.user - form = {'username': 'dogOwnerUser01', - 'password': 'password123', - } - - response = client.post('/login/', form, follow=True) - current_log_user = response.wsgi_request.user - assert current_log_user == create_dog_owner_user.user - assert previous_logged_user != current_log_user - - def test_invalid_login_dog_owner_user_info(self, client): - form = {'username': "daycare@address.com", - 'password': "incorrect", - } - response = client.post('/login/', form, follow=True) - assert response.wsgi_request.user.is_anonymous - - def test_valid_login_daycare_user_info(self, client, create_daycare_user): + def test_valid_login_daycare_user_info(self, client, create_daycare_user, daycare_data): previous_logged_user = client.get('/').wsgi_request.user - form = {'username': 'testuser01', - 'password': 'pass', + form = {'username': pytest.DAYCARE_USERNAME, + 'password': pytest.DAYCARE_PASSWORD, } response = client.post('/login/', form, follow=True) diff --git a/message/tests.py b/message/tests.py index 77e5044..43239c7 100644 --- a/message/tests.py +++ b/message/tests.py @@ -1,42 +1,9 @@ from .models import Message from dogowner.models import DogOwner from daycare.models import DayCare -from .models import AuthorOptions import pytest -@pytest.fixture -def dogowner_message_to_daycare1(): - return Message.create(author=AuthorOptions.DogOwner, - dogowner_id=DogOwner.objects.get(pk=1), - daycare_id=DayCare.objects.get(pk=1), - text='Hello this is the test message1 from owner to day care') - - -@pytest.fixture -def daycare1_reply_to_dogonwer_message(): - return Message.create(author=AuthorOptions.DayCare, - dogowner_id=DogOwner.objects.get(pk=1), - daycare_id=DayCare.objects.get(pk=1), - text='This is reply to first message from daycare to owner') - - -@pytest.fixture -def daycare2_message_to_dogowner(): - return Message.create(author=AuthorOptions.DayCare, - dogowner_id=DogOwner.objects.get(pk=1), - daycare_id=DayCare.objects.get(pk=2), - text='Hello this new chat between daycare2 and dogowner') - - -@pytest.fixture -def daycare3_message_to_dogowner(): - return Message.create(author=AuthorOptions.DayCare, - dogowner_id=DogOwner.objects.get(pk=1), - daycare_id=DayCare.objects.get(pk=3), - text='new chat between daycare3 and dogowner') - - @pytest.mark.django_db() class TestMessageModel: def test_create_message(self, dogowner_message_to_daycare1): diff --git a/orders/tests.py b/orders/tests.py index a55305a..e9259ab 100644 --- a/orders/tests.py +++ b/orders/tests.py @@ -7,16 +7,6 @@ import pytest -@pytest.fixture -def create_order(): - return Order.create(dog_owner_id=DogOwner.objects.get(id=1), - daycare_id=DayCare.objects.get(id=1), - start_date=timezone.now(), - end_date=timezone.now() + datetime.timedelta(days=3), - price_per_day=100, - ) - - @pytest.mark.django_db class TestOrderModel: def test_create_order(self, create_order): diff --git a/review/conftest.py b/review/conftest.py deleted file mode 100644 index b8e3f9b..0000000 --- a/review/conftest.py +++ /dev/null @@ -1,33 +0,0 @@ -import pytest -from daycare.models import DayCare -from dogowner.models import DogOwner -from review.models import Review - - -@pytest.fixture -def daycare(): - return DayCare.create(email="daycare_review@gmail.com", username="daycare_review", password="pass", - name="reviewDayCare", description="This is test daycare for review", price_per_day=10, - capacity=50, area="Merkaz", city="Tel-Aviv", address="The best review") - - -@pytest.fixture -def dogowner(): - return DogOwner.create(email="dogowner_review@gmail.com", username='dogowner_review', password='pass', - dog_name='dogReview', first_name='firstNameReview', last_name='lastNameReview', - phone_number=1234567890, dog_race='review', - dog_picture_url='https://www.google.com/review.jpg', dog_age=1, dog_weight=1, dog_gender='M') - - -@pytest.fixture -def review_data(): - pytest.REVIEW = 'sample review' - pytest.RATING = 5 - pytest.DAY_CARE_ID = 1 - pytest.DOG_OWNER_ID = 1 - - -@pytest.fixture -def review(review_data): - return Review.create(review=pytest.REVIEW, rating=pytest.RATING, daycare_id=pytest.DAY_CARE_ID, - dogowner_id=pytest.DOG_OWNER_ID) diff --git a/review/tests.py b/review/tests.py index 358dc56..1984deb 100644 --- a/review/tests.py +++ b/review/tests.py @@ -19,30 +19,29 @@ def test_rating_limit_min(self, rating, review_data): Review.create(review=pytest.REVIEW, rating=rating, daycare_id=pytest.DAY_CARE_ID, dogowner_id=pytest.DOG_OWNER_ID) - def test_delete_related_daycare(self, review, review_data): - daycare = DayCare.objects.get(pk=pytest.DAY_CARE_ID) - - assert daycare in DayCare.objects.all() + def test_delete_related_daycare(self, create_daycare_user, review, review_data): + assert create_daycare_user in DayCare.objects.all() assert review in Review.objects.all() - daycare.delete() - assert daycare not in DayCare.objects.all() + create_daycare_user.delete() + assert create_daycare_user not in DayCare.objects.all() assert review not in Review.objects.all() - def test_delete_related_dogowner(self, dogowner, review, review_data): - assert dogowner in DogOwner.objects.all() + def test_delete_related_dogowner(self, create_dog_owner_user, review, review_data): + assert create_dog_owner_user in DogOwner.objects.all() assert review in Review.objects.all() - dogowner.delete() - assert dogowner not in DogOwner.objects.all() + create_dog_owner_user.delete() + assert create_dog_owner_user not in DogOwner.objects.all() assert review in Review.objects.all() @pytest.mark.parametrize("number_of_reviews", [0, 1, 3]) - def test_get_review_by_daycare_id(self, number_of_reviews, dogowner, daycare): - review_list = [Review.create(review='review', rating=1, daycare_id=daycare.id, dogowner_id=dogowner.id) + def test_get_review_by_daycare_id(self, number_of_reviews, create_dog_owner_user, create_daycare_user): + review_list = [Review.create(review='review', rating=1, daycare_id=create_daycare_user.id, + dogowner_id=create_dog_owner_user.id) for _ in range(number_of_reviews)] - reviews_by_id_list = Review.get_review_by_daycare_id(daycare.id) + reviews_by_id_list = Review.get_review_by_daycare_id(create_daycare_user.id) assert len(reviews_by_id_list) == number_of_reviews for position, review in enumerate(reviews_by_id_list):