-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1500 from lumi-tip/development-lumi-7920
add technologies filter into eventTypes
- Loading branch information
Showing
10 changed files
with
252 additions
and
6 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
breathecode/events/migrations/0060_eventtype_technologies.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 5.1.2 on 2024-11-18 15:58 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("events", "0059_event_asset_slug"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="eventtype", | ||
name="technologies", | ||
field=models.CharField( | ||
blank=True, | ||
default=None, | ||
help_text="Add comma-separated list of technologies", | ||
max_length=200, | ||
null=True, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
from datetime import datetime, timedelta, timezone | ||
|
||
import capyc.pytest as capy | ||
from django.urls.base import reverse_lazy | ||
|
||
|
||
def serialize_event(event): | ||
return { | ||
"id": event.id, | ||
"title": event.title, | ||
"starting_at": ( | ||
event.starting_at.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f") + "Z" | ||
if isinstance(event.starting_at, datetime) | ||
else None | ||
), | ||
"ending_at": ( | ||
event.ending_at.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f") + "Z" | ||
if isinstance(event.ending_at, datetime) | ||
else None | ||
), | ||
"event_type": { | ||
"id": event.event_type.id, | ||
"slug": event.event_type.slug, | ||
"name": event.event_type.name, | ||
"technologies": event.event_type.technologies, | ||
}, | ||
"slug": event.slug, | ||
"excerpt": event.excerpt, | ||
"lang": event.lang, | ||
"url": event.url, | ||
"banner": event.banner, | ||
"description": event.description, | ||
"capacity": event.capacity, | ||
"status": event.status, | ||
"host": event.host, | ||
"ended_at": ( | ||
event.ended_at.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f") + "Z" if event.ended_at else None | ||
), | ||
"online_event": event.online_event, | ||
"venue": ( | ||
None | ||
if not event.venue | ||
else { | ||
"id": event.venue.id, | ||
"title": event.venue.title, | ||
"street_address": event.venue.street_address, | ||
"city": event.venue.city.name, | ||
"zip_code": event.venue.zip_code, | ||
"state": event.venue.state, | ||
"updated_at": event.venue.updated_at.isoformat(), | ||
} | ||
), | ||
"academy": ( | ||
None | ||
if not event.academy | ||
else { | ||
"id": event.academy.id, | ||
"slug": event.academy.slug, | ||
"name": event.academy.name, | ||
"city": {"name": event.academy.city.name} if event.academy.city else None, | ||
} | ||
), | ||
"sync_with_eventbrite": event.sync_with_eventbrite, | ||
"eventbrite_sync_status": event.eventbrite_sync_status, | ||
"eventbrite_sync_description": event.eventbrite_sync_description, | ||
"tags": event.tags, | ||
"asset_slug": event.asset_slug, | ||
"host_user": ( | ||
None | ||
if not event.host_user | ||
else { | ||
"id": event.host_user.id, | ||
"first_name": event.host_user.first_name, | ||
"last_name": event.host_user.last_name, | ||
} | ||
), | ||
"author": ( | ||
None | ||
if not event.author | ||
else { | ||
"id": event.author.id, | ||
"first_name": event.author.first_name, | ||
"last_name": event.author.last_name, | ||
} | ||
), | ||
"asset": None, | ||
} | ||
|
||
|
||
def test_filter_by_technologies(client: capy.Client, database: capy.Database, fake: capy.Fake): | ||
url = reverse_lazy("events:all") | ||
|
||
model = database.create( | ||
city=1, | ||
country=1, | ||
academy={ | ||
"slug": fake.slug(), | ||
"name": fake.name(), | ||
"logo_url": "https://example.com/logo.jpg", | ||
"street_address": "Address", | ||
}, | ||
event_type=[ | ||
{ | ||
"slug": fake.slug(), | ||
"name": fake.name(), | ||
"description": "description1", | ||
"technologies": "python, flask", | ||
}, | ||
{ | ||
"slug": fake.slug(), | ||
"name": fake.name(), | ||
"description": "description2", | ||
"technologies": "flask, pandas", | ||
}, | ||
], | ||
event=[ | ||
{ | ||
"title": "My First Event", | ||
"capacity": 100, | ||
"banner": "https://example.com/banner.jpg", | ||
"starting_at": datetime.now(), | ||
"ending_at": datetime.now() + timedelta(hours=2), | ||
"status": "ACTIVE", | ||
"event_type_id": n + 1, | ||
} | ||
for n in range(0, 2) | ||
], | ||
) | ||
|
||
response = client.get(f"{url}?technologies=python") | ||
json = response.json() | ||
|
||
expected = [serialize_event(event) for event in model.event if "python" in event.event_type.technologies] | ||
|
||
assert response.status_code == 200 | ||
assert len(json) == 1 | ||
assert expected == json | ||
|
||
|
||
def test_filter_by_technologies_obtain_two(client: capy.Client, database: capy.Database, fake: capy.Fake): | ||
url = reverse_lazy("events:all") | ||
|
||
model = database.create( | ||
city=1, | ||
country=1, | ||
academy={ | ||
"slug": fake.slug(), | ||
"name": fake.name(), | ||
"logo_url": "https://example.com/logo.jpg", | ||
"street_address": "Address", | ||
}, | ||
event_type=[ | ||
{ | ||
"slug": fake.slug(), | ||
"name": fake.name(), | ||
"description": "description1", | ||
"technologies": "python, flask", | ||
}, | ||
{ | ||
"slug": fake.slug(), | ||
"name": fake.name(), | ||
"description": "description2", | ||
"technologies": "flask, pandas", | ||
}, | ||
{ | ||
"slug": fake.slug(), | ||
"name": fake.name(), | ||
"description": "description3", | ||
"technologies": "javascript, java", | ||
}, | ||
], | ||
event=[ | ||
{ | ||
"title": f"My Event {n + 1}", | ||
"capacity": 100, | ||
"banner": "https://example.com/banner.jpg", | ||
"starting_at": datetime.now(), | ||
"ending_at": datetime.now() + timedelta(hours=2), | ||
"status": "ACTIVE", | ||
"event_type_id": n + 1, | ||
} | ||
for n in range(3) | ||
], | ||
) | ||
|
||
response = client.get(f"{url}?technologies=python,java") | ||
json = response.json() | ||
|
||
technologies_to_filter = {"python", "java"} | ||
expected = [ | ||
serialize_event(event) | ||
for event in model.event | ||
if any(tech in event.event_type.technologies.split(", ") for tech in technologies_to_filter) | ||
] | ||
|
||
assert response.status_code == 200 | ||
assert len(json) == 2 | ||
assert expected == json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters