Skip to content

Commit

Permalink
Merge branch 'main' into chatHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuval-Vino authored May 4, 2022
2 parents aef44e3 + 467add9 commit 3069644
Show file tree
Hide file tree
Showing 19 changed files with 484 additions and 234 deletions.
112 changes: 112 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
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_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='[email protected]',
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 = "[email protected]"
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
def create_image1(create_daycare_user):
return Image.create(url="../../static/images/daycare_image_test_01.jpeg", daycare_id=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)
20 changes: 0 additions & 20 deletions daycare/conftest.py

This file was deleted.

3 changes: 1 addition & 2 deletions daycare/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def create(email, username, password, name, description, price_per_day, capacity
validate_max_length(address, 50, "address")
validate_price(price_per_day)

new_daycare = DayCare(user=User.objects.create_user(email=email, username=username, password=password,
),
new_daycare = DayCare(user=User.objects.create_user(email=email, username=username, password=password),
name=name, description=description, price_per_day=price_per_day,
capacity=capacity, area=area, city=city, address=address)

Expand Down
132 changes: 132 additions & 0 deletions daycare/templates/daycare/daycare-homepage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{% extends "main/base_template.html" %}

{% block stylesheets %}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css"
integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<style>
/* Make the image fully responsive */
.img {
float: left;
width: 100px;
height: 100px;
object-fit:cover;
}
</style>
{% endblock %}

{% block content %}
<div class="card mb-2">
<div class="row row-cols-md-2">
<div class="col-md-7">
<hr>
<div class="mt-5 mb-5">
<h5> <i class="fas fa-user"></i> Hello {{ daycare.name }}</h5>
<h6>This is where you can manage your daycare.
<br> You will be able:</h6>
<p class="text-muted"># Manage your booking schedule</p>
<p class="text-muted"># Set filters of approved dogs and services you provide</p>
<p class="text-muted"># Read / write reviews of dog owners and their dogs</p>
<p class="text-muted"># Chat with dog owners</p>
</div>
<hr>
<div class="mt-5">
<h5>Have a look at your reviews</h5>
<table class="table table-hover table-bordered table-responsive">
<thead class="table-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Date</th>
<th scope="col">Review</th>
<th scope="col">Rating</th>
</tr>
</thead>
<tbody>
{% for review in reviews %}
<tr>
<th scope="row">{{ forloop.counter }}</th>
<td>{{ review.dogowner_id }}</td>
<td>{{ review.creation_date }}</td>
<td>{{ review.review }}</td>
<td>{{ review.rating }}</td>
</tr>
{% endfor %}
</tbody>
</table>

</div>
</div>
<div class="col-md-5">
<div class="card h-100">
<ul class="nav nav-pills" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="apt-tab-{{daycare.id}}" data-toggle="tab"
href="#apt-{{daycare.id}}" role="tab" aria-controls="apt-{{daycare.id}}"
aria-selected="true">Daycare Profile Details</a>
</li>
</ul>

<div class="tab-content" id="card-tab-content">
<div class="tab-pane fade show active" id="apt-{{daycare.id}}" role="tabpanel"
aria-labelledby="apt-tab-{{daycare.id}}">

<div id="imageSlides" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ul class="carousel-indicators">
{% for image in images %}
{% if forloop.counter == 1 %}
<li data-target="#imageSlides" data-slide-to={{image.id}} class="active"></li>
{% else %}
<li data-target="#imageSlides" data-slide-to={{image.id}}></li>
{% endif %}
{% endfor%}
</ul>


<!-- The slideshow -->
<div class="carousel-inner">
{% for image in images %}
{% if forloop.counter == 1 %}
<div class="carousel-item active">
<img src={{image.url}} class="img-fluid" width="900" height="400">
</div>
{% else %}
<div class="carousel-item">
<img src={{image.url}} class="img-fluid" width="900" height="400">
</div>
{% endif %}
{% endfor %}
</div>

<!-- Left and right controls -->
<a class="carousel-control-prev" href="#imageSlides" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#imageSlides" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<div class="card-body">
<h5 class="card-title">{{daycare.address}}, {{daycare.city}}</h5>
<br>
<h6><i class="fas fa-dog"></i> Capacity: {{daycare.capacity}}
<br>
<br>
<i class="fas fa-coins"></i> Price: {{daycare.price_per_day}}
</h6>
<br>
<h6><strong>About</strong></h6>
<p class="card-text">{{daycare.description}}</p>
</div>
</div>
</div>
</div>
</div>

</div>
</div>

{% endblock %}
26 changes: 26 additions & 0 deletions daycare/test_daycare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from .models import DayCare
from django.core.exceptions import ValidationError
from django.contrib.auth.models import User
from .models import Image
import random
from review.models import Review


@pytest.mark.django_db()
Expand Down Expand Up @@ -61,3 +64,26 @@ def test_daycare_user_creation_with_same_user_name(self, create_daycare_user):
DayCare.create(username='testUser01', email="[email protected]", password='pass123', name='daycare',
description='new description', price_per_day=10, capacity=50,
area='north', city='haifa', address='new address')

def test_daycare_redirected_homepage_after_login(self, client, create_daycare_user):
client.force_login(user=create_daycare_user.user)
response = client.get('/')
assert response.status_code == 302
assert response['Location'] == '/homepage/'

def test_relevant_daycare_homepage_with_static_data(self, client, create_daycare_user):
dayCare = random.choice([daycare for daycare in DayCare.objects.all() if 'static' in daycare.user.username])
client.force_login(user=dayCare.user)

response = client.get('/homepage/')

daycare_shown_in_homepage = response.context['daycare']
assert daycare_shown_in_homepage == dayCare

images_shown_in_homepage = set(response.context['images'])
daycare_images = set(Image.get_images_by_daycare_id(daycare_id=dayCare.id))
assert images_shown_in_homepage == daycare_images

reviews_shown_in_homepage = set(response.context['reviews'])
daycare_reviews = set(Review.get_review_by_daycare_id(daycare_id=dayCare.id))
assert reviews_shown_in_homepage == daycare_reviews
11 changes: 11 additions & 0 deletions daycare/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .models import Image
from django.core.exceptions import ValidationError

DEFAULT_DAYCARE_PROFILE_URL = "../../static/images/daycare-default-profile-image.jpeg"


@pytest.mark.django_db()
class TestImageModel:
Expand All @@ -20,3 +22,12 @@ def test_image_creation_with_invalid_image_url(self, create_daycare_user):
with pytest.raises(ValidationError,
match="Invalid URL image - URL should end with \'.gif\', \'.png\', \'.jpg\' or \'.jpeg\'."):
Image.create(url="NOT_VALID_URL", daycare_id=DayCare.objects.get(id=create_daycare_user.id))

def test_daycare_has_customized_profile_image(self, create_image1, create_image2, create_daycare_user):
daycare_profile_image = create_daycare_user.get_daycare_primary_image_url()
assert daycare_profile_image != DEFAULT_DAYCARE_PROFILE_URL
assert daycare_profile_image is not None

def test_daycare_has_default_profile_image_when_no_customized_picture_was_found(self, create_daycare_user):
daycare_profile_image = create_daycare_user.get_daycare_primary_image_url()
assert daycare_profile_image == DEFAULT_DAYCARE_PROFILE_URL
16 changes: 14 additions & 2 deletions daycare/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# from django.shortcuts import render
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from .models import Image
from review.models import Review

# Create your views here.

@login_required(login_url='login')
def daycare_home(request):
context = {
'daycare': request.user.daycare,
'reviews': Review.get_review_by_daycare_id(request.user.daycare.id),
'images': Image.get_images_by_daycare_id(request.user.daycare.id)
}

return render(request, 'daycare/daycare-homepage.html', context)
26 changes: 26 additions & 0 deletions dogowner/templates/dogowner/dog_owner_homepage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "main/base_template.html" %}
{% load static %}

{% block stylesheets %}
<link rel="stylesheet" href="{% static 'CSS/dog_owner_homepage.css' %}">
{% endblock %}

{% block content %}
<div class="row row-cols-1 g-3 cards">
<div style="display: flex; flex-direction: row; flex-wrap: wrap">
{% for daycare in daycares %}
<div class="card">
<img src="{{ daycare.get_daycare_primary_image_url }}" alt="{{ daycare.name }} image" class="card-img-top">
<div class="card-body">
<div style="display: flex; flex-direction: row">
<h5 class="card-title">{{ daycare.name }}</h5>
</div>
<p class="card-text">{{ daycare.description | truncatechars:250 }}</p>
<a href="/daycare/{{ daycare.id }}" class="btn btn-primary">Daycare Profile</a>
</div>
</div>
{% endfor %}
</div>
</div>

{% endblock %}
Loading

0 comments on commit 3069644

Please sign in to comment.