Skip to content

Commit

Permalink
Merge pull request #1507 from breatheco-de/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
tommygonzaleza authored Nov 26, 2024
2 parents 21bbc88 + 1f5dfba commit 5292691
Show file tree
Hide file tree
Showing 19 changed files with 936 additions and 49 deletions.
24 changes: 24 additions & 0 deletions breathecode/events/migrations/0060_eventtype_technologies.py
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,
),
),
]
21 changes: 21 additions & 0 deletions breathecode/events/migrations/0061_event_is_public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.1.2 on 2024-11-25 17:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("events", "0060_eventtype_technologies"),
]

operations = [
migrations.AddField(
model_name="event",
name="is_public",
field=models.BooleanField(
default=True,
help_text="If true, then it will be shown in cards and the workshop's landing page. Otherwise it will be hidden.",
),
),
]
11 changes: 11 additions & 0 deletions breathecode/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class EventType(models.Model):
default=True, help_text="Other academies are allowed to create events of this type"
)

technologies = models.CharField(
max_length=200, null=True, default=None, blank=True, help_text="Add comma-separated list of technologies"
)

created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)

Expand Down Expand Up @@ -272,6 +276,13 @@ def __init__(self, *args, **kwargs):
created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)

is_public = models.BooleanField(
default=True,
blank=False,
null=False,
help_text="If true, then it will be shown in cards and the workshop's landing page. Otherwise it will be hidden.",
)

def __str__(self):
return self.title or "No title"

Expand Down
4 changes: 4 additions & 0 deletions breathecode/events/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class EventTypeSmallSerializer(serpy.Serializer):
id = serpy.Field()
slug = serpy.Field()
name = serpy.Field()
technologies = serpy.Field()


class EventTypeSerializer(EventTypeSmallSerializer):
Expand Down Expand Up @@ -189,6 +190,7 @@ class EventSmallSerializer(EventTinySerializer):
host_user = UserBigSerializer(required=False)
author = UserSerializer(required=False)
asset = serpy.MethodField()
is_public = serpy.Field()

def get_asset(self, obj):
if obj.asset_slug is not None:
Expand Down Expand Up @@ -244,6 +246,7 @@ class EventSmallSerializerNoAcademy(serpy.Serializer):
eventbrite_sync_status = serpy.Field()
eventbrite_sync_description = serpy.Field()
tags = serpy.Field()
is_public = serpy.Field()


class EventPublicBigSerializer(EventSmallSerializer):
Expand Down Expand Up @@ -295,6 +298,7 @@ class AcademyEventSmallSerializer(serpy.Serializer):
author = UserSerializer(required=False)
free_for_all = serpy.Field()
asset = serpy.MethodField()
is_public = serpy.Field()

def get_asset(self, obj):
if obj.asset_slug is not None:
Expand Down
9 changes: 6 additions & 3 deletions breathecode/events/tests/mixins/new_events_tests_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
"""

import os

from django.urls import reverse_lazy
from rest_framework.test import APITestCase

from breathecode.tests.mixins import (
GenerateModelsMixin,
BreathecodeMixin,
CacheMixin,
DatetimeMixin,
GenerateModelsMixin,
GenerateQueriesMixin,
HeadersMixin,
DatetimeMixin,
ICallMixin,
BreathecodeMixin,
)


Expand Down Expand Up @@ -78,6 +80,7 @@ def check_all_academy_events(self, models=None):
"sync_with_eventbrite": model["event"].sync_with_eventbrite,
"eventbrite_sync_description": model["event"].eventbrite_sync_description,
"eventbrite_sync_status": model["event"].eventbrite_sync_status,
"is_public": model["event"].is_public,
}
for model in models
]
Expand Down
172 changes: 172 additions & 0 deletions breathecode/events/tests/urls/tests_academy_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def post_serializer(data={}):
"currency": "USD",
"live_stream_url": None,
"host_user": None,
"is_public": True,
**data,
}

Expand Down Expand Up @@ -95,6 +96,7 @@ def event_table(data={}):
"live_stream_url": None,
"sync_with_eventbrite": False,
"currency": "",
"is_public": True,
**data,
}

Expand Down Expand Up @@ -192,6 +194,7 @@ def test_all_academy_events_correct_city(self):
"sync_with_eventbrite": model["event"].sync_with_eventbrite,
"eventbrite_sync_description": model["event"].eventbrite_sync_description,
"eventbrite_sync_status": model["event"].eventbrite_sync_status,
"is_public": model["event"].is_public,
}
]

Expand Down Expand Up @@ -265,6 +268,7 @@ def test_all_academy_events_correct_country(self):
"sync_with_eventbrite": model["event"].sync_with_eventbrite,
"eventbrite_sync_description": model["event"].eventbrite_sync_description,
"eventbrite_sync_status": model["event"].eventbrite_sync_status,
"is_public": model["event"].is_public,
}
]

Expand Down Expand Up @@ -338,6 +342,7 @@ def test_all_academy_events_correct_zip_code(self):
"sync_with_eventbrite": model["event"].sync_with_eventbrite,
"eventbrite_sync_description": model["event"].eventbrite_sync_description,
"eventbrite_sync_status": model["event"].eventbrite_sync_status,
"is_public": model["event"].is_public,
}
]

Expand Down Expand Up @@ -392,6 +397,7 @@ def test_all_academy_events_upcoming(self):
"sync_with_eventbrite": model["event"].sync_with_eventbrite,
"eventbrite_sync_description": model["event"].eventbrite_sync_description,
"eventbrite_sync_status": model["event"].eventbrite_sync_status,
"is_public": model["event"].is_public,
}
]

Expand Down Expand Up @@ -628,6 +634,172 @@ def test_all_academy_events__post__bad_tags__one_of_two_tags_not_exists(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(self.bc.database.list_of("events.Event"), [])

"""
🔽🔽🔽 Post is_public
"""

def test_all_academy_events__post_with_event_is_public_true(self):
self.headers(academy=1)
model = self.generate_models(
authenticate=True,
profile_academy=True,
capability="read_event",
role="potato",
syllabus=True,
venue=True,
event=True,
is_public=True,
)
url = reverse_lazy("events:academy_event")

response = self.client.get(url)
json = response.json()

expected = [
{
"banner": model["event"].banner,
"ending_at": datetime_to_iso_format(model["event"].ending_at),
"event_type": model["event"].event_type,
"excerpt": model["event"].excerpt,
"tags": model["event"].tags,
"slug": model["event"].slug,
"id": model["event"].id,
"lang": model["event"].lang,
"online_event": model["event"].online_event,
"starting_at": datetime_to_iso_format(model["event"].starting_at),
"ended_at": model["event"].ended_at,
"status": model["event"].status,
"title": model["event"].title,
"url": model["event"].url,
"host": model["event"].host,
"asset_slug": model["event"].asset_slug,
"capacity": model["event"].capacity,
"venue": {
"city": model["event"].venue.city,
"id": model["event"].id,
"state": model["event"].venue.state,
"street_address": model["event"].venue.street_address,
"title": model["event"].venue.title,
"zip_code": model["event"].venue.zip_code,
"updated_at": self.bc.datetime.to_iso_string(model.venue.updated_at),
},
"sync_with_eventbrite": model["event"].sync_with_eventbrite,
"eventbrite_sync_description": model["event"].eventbrite_sync_description,
"eventbrite_sync_status": model["event"].eventbrite_sync_status,
"is_public": model["event"].is_public,
}
]
self.assertEqual(json, expected)
self.assertEqual(response.status_code, 200)

def test_all_academy_events__post_with_event_is_public_false(self):
self.headers(academy=1)
model = self.generate_models(
authenticate=True,
profile_academy=True,
capability="read_event",
role="potato",
syllabus=True,
venue=True,
event=True,
is_public=False,
)
url = reverse_lazy("events:academy_event")

response = self.client.get(url)
json = response.json()

expected = [
{
"banner": model["event"].banner,
"ending_at": datetime_to_iso_format(model["event"].ending_at),
"event_type": model["event"].event_type,
"excerpt": model["event"].excerpt,
"tags": model["event"].tags,
"slug": model["event"].slug,
"id": model["event"].id,
"lang": model["event"].lang,
"online_event": model["event"].online_event,
"starting_at": datetime_to_iso_format(model["event"].starting_at),
"ended_at": model["event"].ended_at,
"status": model["event"].status,
"title": model["event"].title,
"url": model["event"].url,
"host": model["event"].host,
"asset_slug": model["event"].asset_slug,
"capacity": model["event"].capacity,
"venue": {
"city": model["event"].venue.city,
"id": model["event"].id,
"state": model["event"].venue.state,
"street_address": model["event"].venue.street_address,
"title": model["event"].venue.title,
"zip_code": model["event"].venue.zip_code,
"updated_at": self.bc.datetime.to_iso_string(model.venue.updated_at),
},
"sync_with_eventbrite": model["event"].sync_with_eventbrite,
"eventbrite_sync_description": model["event"].eventbrite_sync_description,
"eventbrite_sync_status": model["event"].eventbrite_sync_status,
"is_public": model["event"].is_public,
}
]
self.assertEqual(json, expected)
self.assertEqual(response.status_code, 200)

def test_all_academy_events__post_with_event_is_public_empty(self):
self.headers(academy=1)
model = self.generate_models(
authenticate=True,
profile_academy=True,
capability="read_event",
role="potato",
syllabus=True,
venue=True,
event=True,
)
url = reverse_lazy("events:academy_event")

response = self.client.get(url)
json = response.json()

expected = [
{
"banner": model["event"].banner,
"ending_at": datetime_to_iso_format(model["event"].ending_at),
"event_type": model["event"].event_type,
"excerpt": model["event"].excerpt,
"tags": model["event"].tags,
"slug": model["event"].slug,
"id": model["event"].id,
"lang": model["event"].lang,
"online_event": model["event"].online_event,
"starting_at": datetime_to_iso_format(model["event"].starting_at),
"ended_at": model["event"].ended_at,
"status": model["event"].status,
"title": model["event"].title,
"url": model["event"].url,
"host": model["event"].host,
"asset_slug": model["event"].asset_slug,
"capacity": model["event"].capacity,
"venue": {
"city": model["event"].venue.city,
"id": model["event"].id,
"state": model["event"].venue.state,
"street_address": model["event"].venue.street_address,
"title": model["event"].venue.title,
"zip_code": model["event"].venue.zip_code,
"updated_at": self.bc.datetime.to_iso_string(model.venue.updated_at),
},
"sync_with_eventbrite": model["event"].sync_with_eventbrite,
"eventbrite_sync_description": model["event"].eventbrite_sync_description,
"eventbrite_sync_status": model["event"].eventbrite_sync_status,
"is_public": model["event"].is_public,
}
]

self.assertEqual(json, expected)
self.assertEqual(response.status_code, 200)

"""
🔽🔽🔽 Post bad slug
"""
Expand Down
Loading

0 comments on commit 5292691

Please sign in to comment.