Skip to content

Commit

Permalink
Add autopublish to dating, plus basic sanity test (refs #491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Almad committed Jan 16, 2025
1 parent c100ef6 commit b98a7a0
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 2 deletions.
18 changes: 18 additions & 0 deletions ddcz/migrations/0011_dating_autopublish_20250116_2222.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.14 on 2025-01-16 21:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ddcz', '0010_dating_20241230_1327'),
]

operations = [
migrations.AlterField(
model_name='dating',
name='published',
field=models.DateTimeField(auto_now_add=True, db_column='datum', null=True, verbose_name='Datum'),
),
]
6 changes: 5 additions & 1 deletion ddcz/models/used/social.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ class Dating(models.Model):
verbose_name="Doba hraní DrD",
)
published = models.DateTimeField(
blank=True, null=True, db_column="datum", verbose_name="Datum"
blank=True,
null=True,
db_column="datum",
verbose_name="Datum",
auto_now_add=True,
)
text = MisencodedTextField(db_column="text")
group = MisencodedCharField(
Expand Down
2 changes: 1 addition & 1 deletion ddcz/templates/base/light-dark/left_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<li>
<span class="list_subheading">Kontakt</span>
<ul class="list_box">
<li><a href="{% url 'ddcz:dating' %}">Seznamka</a></li>
<li><a href="{% url 'ddcz:dating' %}" id="ddcz_nav_dating">Seznamka</a></li>
<li><a href="{% url 'ddcz:market' %}" id="ddcz_nav_market">Inzerce</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions ddcz/tests/test_ui/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MainPage(Enum):
NAVIGATION_TAVERN = '//*[@id="ddcz_nav_tavern"]'
NAVIGATION_PHORUM = '//*[@id="ddcz_nav_phorum"]'
NAVIGATION_MARKET = '//*[@id="ddcz_nav_market"]'
NAVIGATION_DATING = '//*[@id="ddcz_nav_dating"]'


class SeleniumTestCase(StaticLiveServerTestCase):
Expand Down
24 changes: 24 additions & 0 deletions ddcz/tests/test_ui/pages_dating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from enum import Enum


class DatingListPage(Enum):
"""Selectors for the dating list page"""

FIRST_TEXT = "//article[@class='dating'][1]//span[@class='label'][text()='Text:']/following-sibling::span[@class='value']"
CREATE_DATING_LINK = "//a[contains(@href, 'seznamka/pridat')]"
NAVIGATION_DATING = "//a[contains(@href, 'seznamka')]"


class DatingCreatePage(Enum):
"""Selectors for the dating creation page"""

NAME_INPUT = "id_name"
EMAIL_INPUT = "id_email"
AREA_INPUT = "id_area"
TEXT_INPUT = "id_text"
GROUP_SELECT = "id_group"
AGE_INPUT = "id_age"
PHONE_INPUT = "id_phone"
MOBILE_INPUT = "id_mobil"
EXPERIENCE_INPUT = "id_experience"
SUBMIT_BUTTON = "//button[@type='submit']"
108 changes: 108 additions & 0 deletions ddcz/tests/test_ui/test_dating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from .cases import SeleniumTestCase, MainPage
from ..model_generator import get_alphabetic_user_profiles
from .pages_dating import DatingListPage, DatingCreatePage
from ddcz.models import Dating
from ddcz.geo import CZECHOSLOVAK_REGIONS


class TestDating(SeleniumTestCase):
reset_sequences = True

def setUp(self):
super().setUp()
self.user = get_alphabetic_user_profiles(
number_of_users=1, saved=True, with_corresponding_user=True
)[0]
self.existing_dating_entry = Dating.objects.create(
user_profile=self.user,
name="Test User",
area=CZECHOSLOVAK_REGIONS[1][1],
text="Zahrál bych si",
email="[email protected]",
)
self.selenium.get(self.live_server_url)

def navigate_to_dating(self, user_profile=None):
if user_profile:
return self.navigate_as_authenticated_user(
user_profile,
navigation_element=MainPage.NAVIGATION_DATING,
expected_title="Seznamka",
)
else:
self.selenium.find_element(
By.XPATH, MainPage.NAVIGATION_DATING.value
).click()

def navigate_to_dating_create(self, user_profile=None):
self.navigate_to_dating(user_profile)
self.selenium.find_element(
By.XPATH, DatingListPage.CREATE_DATING_LINK.value
).click()

def create_dating_entry(
self,
name,
area,
text,
email=None,
group=None,
age=None,
phone=None,
mobile=None,
experience=None,
):
"""Helper method to fill and submit dating entry form"""
self.selenium.find_element(By.ID, DatingCreatePage.NAME_INPUT.value).send_keys(
name
)
if email:
self.selenium.find_element(
By.ID, DatingCreatePage.EMAIL_INPUT.value
).send_keys(email)
self.selenium.find_element(By.ID, DatingCreatePage.AREA_INPUT.value).send_keys(
area
)
self.selenium.find_element(By.ID, DatingCreatePage.TEXT_INPUT.value).send_keys(
text
)

if group:
select = Select(
self.selenium.find_element(By.ID, DatingCreatePage.GROUP_SELECT.value)
)
select.select_by_visible_text(group)
if age:
self.selenium.find_element(
By.ID, DatingCreatePage.AGE_INPUT.value
).send_keys(age)
if phone:
self.selenium.find_element(
By.ID, DatingCreatePage.PHONE_INPUT.value
).send_keys(phone)
if mobile:
self.selenium.find_element(
By.ID, DatingCreatePage.MOBILE_INPUT.value
).send_keys(mobile)
if experience:
self.selenium.find_element(
By.ID, DatingCreatePage.EXPERIENCE_INPUT.value
).send_keys(experience)

self.selenium.find_element(
By.XPATH, DatingCreatePage.SUBMIT_BUTTON.value
).click()

def test_can_view_dating_list_anonymous(self):
"""Test that anonymous user can view dating list"""
self.navigate_to_dating()
text = self.selenium.find_element(By.XPATH, '//h1[@class="page-heading"]').text
self.assertEquals("Seznamka", text)

text = self.selenium.find_element(
By.XPATH, DatingListPage.FIRST_TEXT.value
).text
self.assertEquals(self.existing_dating_entry.text, text)

0 comments on commit b98a7a0

Please sign in to comment.