From 04e16bc3c116b2409378b6c83e216f4e34797e86 Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Thu, 14 Nov 2024 16:35:54 +0000 Subject: [PATCH 01/20] Add is_public in Event model and run migrations successfully --- .../events/migrations/0060_event_is_public.py | 21 +++++++++++++++++++ breathecode/events/models.py | 7 +++++++ 2 files changed, 28 insertions(+) create mode 100644 breathecode/events/migrations/0060_event_is_public.py diff --git a/breathecode/events/migrations/0060_event_is_public.py b/breathecode/events/migrations/0060_event_is_public.py new file mode 100644 index 000000000..cc57b349c --- /dev/null +++ b/breathecode/events/migrations/0060_event_is_public.py @@ -0,0 +1,21 @@ +# Generated by Django 5.1.2 on 2024-11-14 16:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("events", "0059_event_asset_slug"), + ] + + 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.", + ), + ), + ] diff --git a/breathecode/events/models.py b/breathecode/events/models.py index 466dbe5f5..7bf124e4b 100644 --- a/breathecode/events/models.py +++ b/breathecode/events/models.py @@ -272,6 +272,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" From 299bcd3f8e1707684c8cc0c3329a9c9d378cf8d9 Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Fri, 15 Nov 2024 00:30:57 +0000 Subject: [PATCH 02/20] Add is_public lookup in get_events --- breathecode/events/views.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/breathecode/events/views.py b/breathecode/events/views.py index bf7625fcf..a13bed120 100644 --- a/breathecode/events/views.py +++ b/breathecode/events/views.py @@ -131,6 +131,15 @@ def get_events(request): elif online_event == "false": lookup["online_event"] = False + is_public = request.GET.get("is_public", None) + print(f"Valor de is_public: {is_public}") + + if is_public == "true": + lookup["is_public"] = True + elif is_public == "false": + lookup["is_public"] = False + print(f"Filtro is_public aplicado: {lookup['is_public']}") + lookup["ending_at__gte"] = timezone.now() if "past" in request.GET: if request.GET.get("past") == "true": From 20ab305b814ebd2c8347fad36c22b4b7ea5f9c75 Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Fri, 15 Nov 2024 16:33:28 +0000 Subject: [PATCH 03/20] Add 'is_public' serialized --- breathecode/events/serializers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/breathecode/events/serializers.py b/breathecode/events/serializers.py index d3d86812e..710f9abc9 100644 --- a/breathecode/events/serializers.py +++ b/breathecode/events/serializers.py @@ -189,6 +189,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: From 98227bae345dcd036ebf69b8014ab67a5be9785e Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Fri, 15 Nov 2024 20:53:02 +0000 Subject: [PATCH 04/20] Add 'is_public' serialized in academy_event --- breathecode/events/serializers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/breathecode/events/serializers.py b/breathecode/events/serializers.py index 710f9abc9..41130ae80 100644 --- a/breathecode/events/serializers.py +++ b/breathecode/events/serializers.py @@ -245,6 +245,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): From e1e60c705752a919302c0764c8eb4b0a96faf6fc Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Sat, 16 Nov 2024 23:32:20 +0000 Subject: [PATCH 05/20] Delete console lines --- breathecode/events/views.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/breathecode/events/views.py b/breathecode/events/views.py index a13bed120..b1a9ca3ba 100644 --- a/breathecode/events/views.py +++ b/breathecode/events/views.py @@ -132,13 +132,11 @@ def get_events(request): lookup["online_event"] = False is_public = request.GET.get("is_public", None) - print(f"Valor de is_public: {is_public}") if is_public == "true": lookup["is_public"] = True elif is_public == "false": lookup["is_public"] = False - print(f"Filtro is_public aplicado: {lookup['is_public']}") lookup["ending_at__gte"] = timezone.now() if "past" in request.GET: From a02bc5507c13615c20fda3546c5e1c88ec77974d Mon Sep 17 00:00:00 2001 From: Luis Miguel Del Valle Date: Mon, 18 Nov 2024 18:56:04 +0000 Subject: [PATCH 06/20] add technologies filter into eventTypes --- .../migrations/0060_eventtype_technologies.py | 24 +++++++++++++++++++ breathecode/events/models.py | 4 ++++ breathecode/events/serializers.py | 1 + .../tests/urls/tests_academy_eventype.py | 2 ++ .../tests/urls/tests_academy_eventype_slug.py | 10 +++++--- .../events/tests/urls/tests_eventype.py | 10 +++++--- breathecode/events/tests/urls/tests_me.py | 1 + .../events/tests/urls/tests_me_event_id.py | 1 + breathecode/events/views.py | 4 ++++ 9 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 breathecode/events/migrations/0060_eventtype_technologies.py diff --git a/breathecode/events/migrations/0060_eventtype_technologies.py b/breathecode/events/migrations/0060_eventtype_technologies.py new file mode 100644 index 000000000..e3ecbfba6 --- /dev/null +++ b/breathecode/events/migrations/0060_eventtype_technologies.py @@ -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, + ), + ), + ] diff --git a/breathecode/events/models.py b/breathecode/events/models.py index 466dbe5f5..4e6f2d7de 100644 --- a/breathecode/events/models.py +++ b/breathecode/events/models.py @@ -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) diff --git a/breathecode/events/serializers.py b/breathecode/events/serializers.py index d3d86812e..1a025c905 100644 --- a/breathecode/events/serializers.py +++ b/breathecode/events/serializers.py @@ -80,6 +80,7 @@ class EventTypeSmallSerializer(serpy.Serializer): id = serpy.Field() slug = serpy.Field() name = serpy.Field() + technologies = serpy.Field() class EventTypeSerializer(EventTypeSmallSerializer): diff --git a/breathecode/events/tests/urls/tests_academy_eventype.py b/breathecode/events/tests/urls/tests_academy_eventype.py index eb9936c3f..e123d4f2e 100644 --- a/breathecode/events/tests/urls/tests_academy_eventype.py +++ b/breathecode/events/tests/urls/tests_academy_eventype.py @@ -34,6 +34,7 @@ def get_serializer(event_type, academy=None, city=None, data={}): "slug": event_type.slug, "lang": event_type.lang, "description": event_type.description, + "technologies": event_type.technologies, **data, } @@ -288,6 +289,7 @@ def test_post_event_type(self): "description": "Potato", "icon_url": "https://www.google.com", "lang": "en", + "technologies": "", } url = reverse_lazy("events:academy_eventype") diff --git a/breathecode/events/tests/urls/tests_academy_eventype_slug.py b/breathecode/events/tests/urls/tests_academy_eventype_slug.py index 916d6fd73..f0fe91b41 100644 --- a/breathecode/events/tests/urls/tests_academy_eventype_slug.py +++ b/breathecode/events/tests/urls/tests_academy_eventype_slug.py @@ -1,11 +1,13 @@ from unittest.mock import MagicMock, call, patch -from breathecode.events.caches import EventCache + from django.urls.base import reverse_lazy +from django.utils import timezone +from breathecode.events.caches import EventCache +from breathecode.services import datetime_to_iso_format from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers + from ..mixins.new_events_tests_case import EventTestCase -from breathecode.services import datetime_to_iso_format -from django.utils import timezone def get_serializer(event_type, academy=None, city=None, data={}): @@ -35,6 +37,7 @@ def get_serializer(event_type, academy=None, city=None, data={}): "allow_shared_creation": event_type.allow_shared_creation, "description": event_type.description, "visibility_settings": event_type.visibility_settings, + "technologies": event_type.technologies, **data, } @@ -51,6 +54,7 @@ def put_serializer(event_type, data={}): "allow_shared_creation": event_type.allow_shared_creation, "free_for_bootcamps": event_type.free_for_bootcamps, "description": event_type.description, + "technologies": event_type.technologies, **data, } diff --git a/breathecode/events/tests/urls/tests_eventype.py b/breathecode/events/tests/urls/tests_eventype.py index 9288d87f3..b31ccef5b 100644 --- a/breathecode/events/tests/urls/tests_eventype.py +++ b/breathecode/events/tests/urls/tests_eventype.py @@ -1,11 +1,13 @@ from unittest.mock import MagicMock, call, patch -from breathecode.events.caches import EventCache + from django.urls.base import reverse_lazy +from django.utils import timezone +from breathecode.events.caches import EventCache +from breathecode.services import datetime_to_iso_format from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers + from ..mixins.new_events_tests_case import EventTestCase -from breathecode.services import datetime_to_iso_format -from django.utils import timezone def get_serializer(event_type, academy=None, city=None, data={}): @@ -32,6 +34,7 @@ def get_serializer(event_type, academy=None, city=None, data={}): "slug": event_type.slug, "lang": event_type.lang, "description": event_type.description, + "technologies": event_type.technologies, **data, } @@ -73,6 +76,7 @@ def test_academy_event_type_with_results(self): "created_at": timezone.now(), "updated_at": timezone.now(), "icon_url": "https://www.google.com", + "technologies": None, } model = self.generate_models( authenticate=True, event=True, event_type=True, event_type_kwargs=event_type_kwargs diff --git a/breathecode/events/tests/urls/tests_me.py b/breathecode/events/tests/urls/tests_me.py index fb8866420..5dfd0e330 100644 --- a/breathecode/events/tests/urls/tests_me.py +++ b/breathecode/events/tests/urls/tests_me.py @@ -114,6 +114,7 @@ def get_serializer( "allow_shared_creation": event_type.allow_shared_creation, "description": event_type.description, "visibility_settings": visibility_settings_serializer(event_type.visibility_settings), + "technologies": event_type.technologies, }, "eventbrite_id": event.eventbrite_id, "eventbrite_organizer_id": event.eventbrite_organizer_id, diff --git a/breathecode/events/tests/urls/tests_me_event_id.py b/breathecode/events/tests/urls/tests_me_event_id.py index d1ed7837a..913c33133 100644 --- a/breathecode/events/tests/urls/tests_me_event_id.py +++ b/breathecode/events/tests/urls/tests_me_event_id.py @@ -121,6 +121,7 @@ def get_serializer( "allow_shared_creation": event_type.allow_shared_creation, "description": event_type.description, "visibility_settings": visibility_settings_serializer(event_type.visibility_settings), + "technologies": event_type.technologies, }, "eventbrite_id": event.eventbrite_id, "eventbrite_organizer_id": event.eventbrite_organizer_id, diff --git a/breathecode/events/views.py b/breathecode/events/views.py index bf7625fcf..e6205eb5c 100644 --- a/breathecode/events/views.py +++ b/breathecode/events/views.py @@ -131,6 +131,10 @@ def get_events(request): elif online_event == "false": lookup["online_event"] = False + if "technology" in request.GET: + value = request.GET.get("technology") + lookup["event_type__technologies__icontains"] = value + lookup["ending_at__gte"] = timezone.now() if "past" in request.GET: if request.GET.get("past") == "true": From 63cd8118dd7e5a1451928ff4e8d4830dc27bcdff Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Tue, 19 Nov 2024 23:18:41 +0000 Subject: [PATCH 07/20] Add is_public serialized --- breathecode/events/serializers.py | 1 + breathecode/events/views.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/breathecode/events/serializers.py b/breathecode/events/serializers.py index 41130ae80..99d26f383 100644 --- a/breathecode/events/serializers.py +++ b/breathecode/events/serializers.py @@ -297,6 +297,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: diff --git a/breathecode/events/views.py b/breathecode/events/views.py index b1a9ca3ba..b9e1e9c31 100644 --- a/breathecode/events/views.py +++ b/breathecode/events/views.py @@ -132,7 +132,6 @@ def get_events(request): lookup["online_event"] = False is_public = request.GET.get("is_public", None) - if is_public == "true": lookup["is_public"] = True elif is_public == "false": From fd44e99992c347b1899d63bb2bbd4ca49b1819f0 Mon Sep 17 00:00:00 2001 From: Luis Miguel Del Valle Date: Thu, 21 Nov 2024 19:46:07 +0000 Subject: [PATCH 08/20] changes requested --- breathecode/events/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/breathecode/events/views.py b/breathecode/events/views.py index e6205eb5c..8ede45899 100644 --- a/breathecode/events/views.py +++ b/breathecode/events/views.py @@ -131,9 +131,12 @@ def get_events(request): elif online_event == "false": lookup["online_event"] = False - if "technology" in request.GET: - value = request.GET.get("technology") - lookup["event_type__technologies__icontains"] = value + if "technologies" in request.GET: + values = request.GET.get("technologies").split(",") + tech_query = Q() + for value in values: + tech_query |= Q(event_type__technologies__icontains=value.strip()) + items = items.filter(tech_query) lookup["ending_at__gte"] = timezone.now() if "past" in request.GET: From 54d0b19be4f75f16c15d10189d59a510657dc892 Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Thu, 21 Nov 2024 23:59:10 +0000 Subject: [PATCH 09/20] Add test GET's academy_event and event_id, PUT event_id) --- .../events/tests/urls/tests_academy_event.py | 163 ++++++++++++++ .../tests/urls/tests_academy_event_id.py | 201 ++++++++++++++++++ breathecode/events/tests/urls/tests_me.py | 1 + .../events/tests/urls/tests_me_event_id.py | 1 + 4 files changed, 366 insertions(+) diff --git a/breathecode/events/tests/urls/tests_academy_event.py b/breathecode/events/tests/urls/tests_academy_event.py index 943f0a1dc..eac010c51 100644 --- a/breathecode/events/tests/urls/tests_academy_event.py +++ b/breathecode/events/tests/urls/tests_academy_event.py @@ -53,6 +53,7 @@ def post_serializer(data={}): "currency": "USD", "live_stream_url": None, "host_user": None, + "is_public": True, **data, } @@ -95,6 +96,7 @@ def event_table(data={}): "live_stream_url": None, "sync_with_eventbrite": False, "currency": "", + "is_public": True, **data, } @@ -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, } ] @@ -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, } ] @@ -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, } ] @@ -392,12 +397,170 @@ 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, } ] self.assertEqual(json, expected) self.assertEqual(response.status_code, 200) + def test_all_academy_events_get_with_event_is_public_true_in_filter_is_public_true(self): + self.headers(academy=1) + event_kwargs = {"is_public": True} + model = self.generate_models( + authenticate=True, + profile_academy=True, + capability="read_event", + role="potato", + syllabus=True, + venue=True, + event=True, + event_kwargs=event_kwargs, + ) + url = reverse_lazy("events:academy_event") + "?is_public=true" + + 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_get_with_event_is_public_true_in_filter_is_public_false(self): + self.headers(academy=1) + event_kwargs = {"is_public": True} + model = self.generate_models( + authenticate=True, + profile_academy=True, + capability="read_event", + role="potato", + syllabus=True, + venue=True, + event=True, + event_kwargs=event_kwargs, + ) + url = reverse_lazy("events:academy_event") + "?is_public=false" + + response = self.client.get(url) + json = response.json() + + expected = [] + + self.assertEqual(json, expected) + self.assertEqual(response.status_code, 200) + + def test_all_academy_events_get_with_event_is_public_false_in_filter_is_public_false(self): + self.headers(academy=1) + event_kwargs = {"is_public": False} + model = self.generate_models( + authenticate=True, + profile_academy=True, + capability="read_event", + role="potato", + syllabus=True, + venue=True, + event=True, + event_kwargs=event_kwargs, + ) + url = reverse_lazy("events:academy_event") + "?is_public=false" + + 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_get_with_event_is_public_false_in_filter_is_public_true(self): + self.headers(academy=1) + event_kwargs = {"is_public": False} + model = self.generate_models( + authenticate=True, + profile_academy=True, + capability="read_event", + role="potato", + syllabus=True, + venue=True, + event=True, + event_kwargs=event_kwargs, + ) + url = reverse_lazy("events:academy_event") + "?is_public=true" + + response = self.client.get(url) + json = response.json() + + expected = [] + + self.assertEqual(json, expected) + self.assertEqual(response.status_code, 200) + def test_all_academy_events_not_found(self): self.headers(academy=1) url = reverse_lazy("events:academy_event") diff --git a/breathecode/events/tests/urls/tests_academy_event_id.py b/breathecode/events/tests/urls/tests_academy_event_id.py index 2186d0d6e..a73072318 100644 --- a/breathecode/events/tests/urls/tests_academy_event_id.py +++ b/breathecode/events/tests/urls/tests_academy_event_id.py @@ -70,6 +70,7 @@ def get_serializer(event, academy, asset=None, data={}): "eventbrite_sync_status": event.eventbrite_sync_status, "eventbrite_sync_description": event.eventbrite_sync_description, "asset": asset_serializer(asset) if asset else None, + "is_public": event.is_public, **data, } @@ -140,6 +141,203 @@ def test_academy_event_id_valid_id(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, 200) + """ + 🔽🔽🔽 Put, is_public true + """ + + @patch("breathecode.marketing.signals.downloadable_saved.send_robust", MagicMock()) + @patch("uuid.uuid4", PropertyMock(MagicMock=uuid)) + @patch("os.urandom", MagicMock(return_value=seed)) + def test_academy_event_id__put__is_public_true(self): + """Test /cohort without auth""" + self.headers(academy=1) + event_kwargs = {"is_public": True} + model = self.generate_models( + authenticate=True, + organization=True, + profile_academy=True, + academy=True, + active_campaign_academy=True, + tag=(2, {"tag_type": "DISCOVERY"}), + capability="crud_event", + role="potato2", + event_type=1, + event=True, + event_kwargs=event_kwargs, + ) + + url = reverse_lazy("events:academy_event_id", kwargs={"event_id": 1}) + current_date = self.datetime_now() + data = { + "id": 1, + "url": "https://www.google.com/", + "banner": "https://www.google.com/banner", + "tags": ",".join([x.slug for x in model.tag]), + "capacity": 11, + "starting_at": self.datetime_to_iso(current_date), + "ending_at": self.datetime_to_iso(current_date), + } + + response = self.client.put(url, data, format="json") + json = response.json() + + del json["updated_at"] + del json["created_at"] + + expected = { + "academy": 1, + "author": 1, + "description": None, + "event_type": 1, + "eventbrite_id": None, + "eventbrite_organizer_id": None, + "eventbrite_status": None, + "eventbrite_url": None, + "excerpt": None, + "host": model["event"].host, + "id": 2, + "lang": "en", + "slug": None, + "online_event": False, + "free_for_all": False, + "organization": 1, + "published_at": None, + "asset_slug": None, + "status": "DRAFT", + "eventbrite_sync_description": None, + "eventbrite_sync_status": "PENDING", + "title": None, + "venue": None, + "sync_with_eventbrite": False, + "ended_at": None, + "eventbrite_sync_status": "PENDING", + "currency": "USD", + "live_stream_url": None, + "host_user": 1, + "free_for_bootcamps": True, + "free_for_all": False, + "uuid": str(uuid), + "is_public": True, + **data, + } + + self.assertEqual(json, expected) + self.assertEqual(response.status_code, 200) + self.assertEqual( + self.bc.database.list_of("events.Event"), + [ + { + **self.model_to_dict(model, "event"), + **data, + "organization_id": 1, + "starting_at": current_date, + "ending_at": current_date, + "free_for_bootcamps": True, + "event_type_id": 1, + "lang": "en", + } + ], + ) + + """ + 🔽🔽🔽 Put, is_public false + """ + + @patch("breathecode.marketing.signals.downloadable_saved.send_robust", MagicMock()) + @patch("uuid.uuid4", PropertyMock(MagicMock=uuid)) + @patch("os.urandom", MagicMock(return_value=seed)) + def test_academy_event_id__put__is_public_false(self): + """Test /cohort without auth""" + self.headers(academy=1) + event_kwargs = {"is_public": False} + model = self.generate_models( + authenticate=True, + organization=True, + profile_academy=True, + academy=True, + active_campaign_academy=True, + tag=(2, {"tag_type": "DISCOVERY"}), + capability="crud_event", + role="potato2", + event_type=1, + event=True, + event_kwargs=event_kwargs, + ) + + url = reverse_lazy("events:academy_event_id", kwargs={"event_id": 1}) + current_date = self.datetime_now() + data = { + "id": 1, + "url": "https://www.google.com/", + "banner": "https://www.google.com/banner", + "tags": ",".join([x.slug for x in model.tag]), + "capacity": 11, + "starting_at": self.datetime_to_iso(current_date), + "ending_at": self.datetime_to_iso(current_date), + } + + response = self.client.put(url, data, format="json") + json = response.json() + + del json["updated_at"] + del json["created_at"] + + expected = { + "academy": 1, + "author": 1, + "description": None, + "event_type": 1, + "eventbrite_id": None, + "eventbrite_organizer_id": None, + "eventbrite_status": None, + "eventbrite_url": None, + "excerpt": None, + "host": model["event"].host, + "id": 2, + "lang": "en", + "slug": None, + "online_event": False, + "free_for_all": False, + "organization": 1, + "published_at": None, + "asset_slug": None, + "status": "DRAFT", + "eventbrite_sync_description": None, + "eventbrite_sync_status": "PENDING", + "title": None, + "venue": None, + "sync_with_eventbrite": False, + "ended_at": None, + "eventbrite_sync_status": "PENDING", + "currency": "USD", + "live_stream_url": None, + "host_user": 1, + "free_for_bootcamps": True, + "free_for_all": False, + "uuid": str(uuid), + "is_public": False, + **data, + } + + self.assertEqual(json, expected) + self.assertEqual(response.status_code, 200) # Verificamos que la respuesta sea correcta + self.assertEqual( + self.bc.database.list_of("events.Event"), + [ + { + **self.model_to_dict(model, "event"), + **data, + "organization_id": 1, + "starting_at": current_date, + "ending_at": current_date, + "free_for_bootcamps": True, + "event_type_id": 1, + "lang": "en", + "is_public": False, + } + ], + ) + """ 🔽🔽🔽 Put - bad tags """ @@ -467,6 +665,7 @@ def test_academy_cohort_id__put(self): "free_for_bootcamps": True, "free_for_all": False, "uuid": str(uuid), + "is_public": True, **data, } @@ -700,6 +899,7 @@ def test_academy_cohort_id__put__with_tags(self): "free_for_bootcamps": True, "free_for_all": False, "uuid": str(uuid), + "is_public": True, **data, } @@ -800,6 +1000,7 @@ def test_academy_cohort_id__put__with_duplicate_tags(self): "free_for_bootcamps": True, "free_for_all": False, "uuid": str(uuid), + "is_public": True, **data, } diff --git a/breathecode/events/tests/urls/tests_me.py b/breathecode/events/tests/urls/tests_me.py index fb8866420..253e443f2 100644 --- a/breathecode/events/tests/urls/tests_me.py +++ b/breathecode/events/tests/urls/tests_me.py @@ -142,6 +142,7 @@ def get_serializer( "updated_at": self.bc.datetime.to_iso_string(event.updated_at), "url": event.url, "venue": event.venue, + "is_public": event.is_public, **data, } diff --git a/breathecode/events/tests/urls/tests_me_event_id.py b/breathecode/events/tests/urls/tests_me_event_id.py index d1ed7837a..0639d4d70 100644 --- a/breathecode/events/tests/urls/tests_me_event_id.py +++ b/breathecode/events/tests/urls/tests_me_event_id.py @@ -144,6 +144,7 @@ def get_serializer( "updated_at": self.bc.datetime.to_iso_string(event.updated_at), "url": event.url, "venue": event.venue, + "is_public": event.is_public, **data, } From c2736fccbcd85b7841b702746af83ddcab4a8358 Mon Sep 17 00:00:00 2001 From: Luis Miguel Del Valle Date: Fri, 22 Nov 2024 05:24:51 +0000 Subject: [PATCH 10/20] changes requested --- breathecode/events/tests/urls/tests_all.py | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 breathecode/events/tests/urls/tests_all.py diff --git a/breathecode/events/tests/urls/tests_all.py b/breathecode/events/tests/urls/tests_all.py new file mode 100644 index 000000000..751831a68 --- /dev/null +++ b/breathecode/events/tests/urls/tests_all.py @@ -0,0 +1,90 @@ +from datetime import datetime, timedelta + +import capyc.pytest as capy +from django.urls.base import reverse_lazy + +from breathecode.admissions.models import Academy, City, Country +from breathecode.events.models import EventType + + +def test_filter_by_status(client: capy.Client, database: capy.Database): + url = reverse_lazy("events:all") + + database.create( + country={ + "code": "ES", + "name": "Spain", + } + ) + country_instance = Country.objects.get(code="ES") + + database.create( + city={ + "name": "Madrid", + "country": country_instance, + } + ) + city_instance = City.objects.get(name="Madrid") + + academy = database.create( + academy={ + "slug": "academy-1", + "name": "My Academy", + "logo_url": "https://example.com/logo.jpg", + "street_address": "Address", + "city": city_instance, + "country": country_instance, + } + ) + academy_instance = Academy.objects.get(slug="academy-1") + + event_type1 = database.create( + event_type={ + "slug": "EventType1", + "name": "EventType 1", + "description": "description1", + "technologies": "python, flask", + "academy": academy_instance, + } + ) + event_type1_instance = EventType.objects.get(slug="EventType1") + event_type2 = database.create( + event_type={ + "slug": "EventType2", + "name": "EventType 2", + "description": "description2", + "technologies": "flask, pandas", + "academy": academy_instance, + } + ) + event_type2_instance = EventType.objects.get(slug="EventType2") + + event1 = database.create( + 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": event_type1_instance, + } + ) + event2 = database.create( + event={ + "title": "My Second Event", + "capacity": 100, + "banner": "https://example.com/banner.jpg", + "starting_at": datetime.now(), + "ending_at": datetime.now() + timedelta(hours=2), + "status": "ACTIVE", + "event_type": event_type2_instance, + } + ) + + response = client.get(f"{url}?technologies=python") + json = response.json() + + assert response.status_code == 200 + assert len(json) == 1 + assert json[0]["event_type"]["technologies"] == "python, flask" From c82afe3d961b0db37f78e6d61f91901498262d8a Mon Sep 17 00:00:00 2001 From: Luis Miguel Del Valle Date: Fri, 22 Nov 2024 17:04:31 +0000 Subject: [PATCH 11/20] test fixed --- breathecode/events/tests/urls/tests_all.py | 176 +++++++++++++-------- 1 file changed, 106 insertions(+), 70 deletions(-) diff --git a/breathecode/events/tests/urls/tests_all.py b/breathecode/events/tests/urls/tests_all.py index 751831a68..c0c0bab77 100644 --- a/breathecode/events/tests/urls/tests_all.py +++ b/breathecode/events/tests/urls/tests_all.py @@ -3,88 +3,124 @@ import capyc.pytest as capy from django.urls.base import reverse_lazy -from breathecode.admissions.models import Academy, City, Country -from breathecode.events.models import EventType +def serialize_event(event): + return { + "id": event.id, + "title": event.title, + "starting_at": event.starting_at.isoformat() if isinstance(event.starting_at, datetime) else event.starting_at, + "ending_at": event.ending_at.isoformat() if isinstance(event.ending_at, datetime) else event.ending_at, + "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 or None, + "lang": event.lang or None, + "url": event.url or None, + "banner": event.banner, + "description": event.description or None, + "capacity": event.capacity, + "status": event.status, + "host": event.host or None, + "ended_at": event.ended_at.isoformat() if event.ended_at else None, + "online_event": event.online_event, + "venue": ( + { + "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(), + } + if event.venue + else None + ), + "academy": ( + { + "id": event.academy.id, + "slug": event.academy.slug, + "name": event.academy.name, + "city": {"name": event.academy.city.name} if event.academy.city else None, + } + if event.academy + else None + ), + "sync_with_eventbrite": event.sync_with_eventbrite, + "eventbrite_sync_status": event.eventbrite_sync_status or None, + "eventbrite_sync_description": event.eventbrite_sync_description or None, + "tags": event.tags or None, + "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, + } + ), + } -def test_filter_by_status(client: capy.Client, database: capy.Database): - url = reverse_lazy("events:all") - - database.create( - country={ - "code": "ES", - "name": "Spain", - } - ) - country_instance = Country.objects.get(code="ES") - database.create( - city={ - "name": "Madrid", - "country": country_instance, - } - ) - city_instance = City.objects.get(name="Madrid") +def test_filter_by_status(client: capy.Client, database: capy.Database, fake: capy.Fake): + url = reverse_lazy("events:all") - academy = database.create( + model = database.create( + city=1, + country=1, academy={ - "slug": "academy-1", - "name": "My Academy", + "slug": fake.slug(), + "name": fake.name(), "logo_url": "https://example.com/logo.jpg", "street_address": "Address", - "city": city_instance, - "country": country_instance, - } - ) - academy_instance = Academy.objects.get(slug="academy-1") - - event_type1 = database.create( - event_type={ - "slug": "EventType1", - "name": "EventType 1", - "description": "description1", - "technologies": "python, flask", - "academy": academy_instance, - } - ) - event_type1_instance = EventType.objects.get(slug="EventType1") - event_type2 = database.create( - event_type={ - "slug": "EventType2", - "name": "EventType 2", - "description": "description2", - "technologies": "flask, pandas", - "academy": academy_instance, - } - ) - event_type2_instance = EventType.objects.get(slug="EventType2") - - event1 = database.create( - 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": event_type1_instance, - } - ) - event2 = database.create( - event={ - "title": "My Second Event", - "capacity": 100, - "banner": "https://example.com/banner.jpg", - "starting_at": datetime.now(), - "ending_at": datetime.now() + timedelta(hours=2), - "status": "ACTIVE", - "event_type": event_type2_instance, - } + }, + 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 json[0]["event_type"]["technologies"] == "python, flask" From 1c879718d64e88ef9e7401bcff310e8da63d57b1 Mon Sep 17 00:00:00 2001 From: Luis Miguel Del Valle Date: Fri, 22 Nov 2024 18:02:32 +0000 Subject: [PATCH 12/20] changes in test --- breathecode/events/tests/urls/tests_all.py | 49 +++++++++++++--------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/breathecode/events/tests/urls/tests_all.py b/breathecode/events/tests/urls/tests_all.py index c0c0bab77..4fe0d032c 100644 --- a/breathecode/events/tests/urls/tests_all.py +++ b/breathecode/events/tests/urls/tests_all.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone import capyc.pytest as capy from django.urls.base import reverse_lazy @@ -8,8 +8,16 @@ def serialize_event(event): return { "id": event.id, "title": event.title, - "starting_at": event.starting_at.isoformat() if isinstance(event.starting_at, datetime) else event.starting_at, - "ending_at": event.ending_at.isoformat() if isinstance(event.ending_at, datetime) else event.ending_at, + "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, @@ -17,18 +25,22 @@ def serialize_event(event): "technologies": event.event_type.technologies, }, "slug": event.slug, - "excerpt": event.excerpt or None, - "lang": event.lang or None, - "url": event.url or None, + "excerpt": event.excerpt, + "lang": event.lang, + "url": event.url, "banner": event.banner, - "description": event.description or None, + "description": event.description, "capacity": event.capacity, "status": event.status, - "host": event.host or None, - "ended_at": event.ended_at.isoformat() if event.ended_at else None, + "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, @@ -37,23 +49,21 @@ def serialize_event(event): "state": event.venue.state, "updated_at": event.venue.updated_at.isoformat(), } - if event.venue - else None ), "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, } - if event.academy - else None ), "sync_with_eventbrite": event.sync_with_eventbrite, - "eventbrite_sync_status": event.eventbrite_sync_status or None, - "eventbrite_sync_description": event.eventbrite_sync_description or None, - "tags": event.tags or None, + "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 @@ -73,6 +83,7 @@ def serialize_event(event): "last_name": event.author.last_name, } ), + "asset": None, } @@ -123,4 +134,4 @@ def test_filter_by_status(client: capy.Client, database: capy.Database, fake: ca assert response.status_code == 200 assert len(json) == 1 - assert json[0]["event_type"]["technologies"] == "python, flask" + assert expected == json From 8db17e34f4e70b1936b33fdfb2df27fcbdfe8cc1 Mon Sep 17 00:00:00 2001 From: Luis Miguel Del Valle Date: Fri, 22 Nov 2024 18:04:25 +0000 Subject: [PATCH 13/20] change --- breathecode/events/tests/urls/tests_all.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/breathecode/events/tests/urls/tests_all.py b/breathecode/events/tests/urls/tests_all.py index 4fe0d032c..2cf47bdfd 100644 --- a/breathecode/events/tests/urls/tests_all.py +++ b/breathecode/events/tests/urls/tests_all.py @@ -87,7 +87,7 @@ def serialize_event(event): } -def test_filter_by_status(client: capy.Client, database: capy.Database, fake: capy.Fake): +def test_filter_by_technologies(client: capy.Client, database: capy.Database, fake: capy.Fake): url = reverse_lazy("events:all") model = database.create( From 6dab58edecea954a6b58e58a55b78698803d23c9 Mon Sep 17 00:00:00 2001 From: Luis Miguel Del Valle Date: Fri, 22 Nov 2024 18:48:07 +0000 Subject: [PATCH 14/20] adding another test using , --- breathecode/events/tests/urls/tests_all.py | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/breathecode/events/tests/urls/tests_all.py b/breathecode/events/tests/urls/tests_all.py index 2cf47bdfd..3201ce064 100644 --- a/breathecode/events/tests/urls/tests_all.py +++ b/breathecode/events/tests/urls/tests_all.py @@ -135,3 +135,64 @@ def test_filter_by_technologies(client: capy.Client, database: capy.Database, fa 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 From 29f08212f2f9e348834e3a194e0cdf183566d956 Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Fri, 22 Nov 2024 23:44:38 +0000 Subject: [PATCH 15/20] Add test and create tests_events_all file --- .../events/tests/urls/tests_academy_event.py | 166 +++++++++++ .../events/tests/urls/tests_events_all.py | 274 ++++++++++++++++++ 2 files changed, 440 insertions(+) create mode 100644 breathecode/events/tests/urls/tests_events_all.py diff --git a/breathecode/events/tests/urls/tests_academy_event.py b/breathecode/events/tests/urls/tests_academy_event.py index eac010c51..e0ce1db2a 100644 --- a/breathecode/events/tests/urls/tests_academy_event.py +++ b/breathecode/events/tests/urls/tests_academy_event.py @@ -791,6 +791,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 """ diff --git a/breathecode/events/tests/urls/tests_events_all.py b/breathecode/events/tests/urls/tests_events_all.py new file mode 100644 index 000000000..613479e3e --- /dev/null +++ b/breathecode/events/tests/urls/tests_events_all.py @@ -0,0 +1,274 @@ +import os +from unittest.mock import MagicMock, PropertyMock, call, patch +from uuid import UUID + +from django.urls.base import reverse_lazy +from django.utils import timezone + +from breathecode.events.caches import EventCache +from breathecode.services import datetime_to_iso_format +from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers + +from ..mixins.new_events_tests_case import EventTestCase + +seed = os.urandom(16) +uuid = UUID(bytes=seed, version=4) + + +def post_serializer(data={}): + return { + "tags": "", + "url": "", + "banner": "", + "capacity": 0, + "starting_at": ..., + "ending_at": ..., + "academy": 0, + "author": None, + "description": None, + "free_for_bootcamps": None, + "event_type": None, + "eventbrite_id": None, + "eventbrite_organizer_id": None, + "eventbrite_status": None, + "eventbrite_url": None, + "slug": None, + "excerpt": None, + "host": None, + "id": 0, + "lang": None, + "online_event": False, + "live_stream_url": None, + "free_for_bootcamps": True, + "asset_slug": None, + "ended_at": None, + "organization": 0, + "published_at": None, + "status": "DRAFT", + "eventbrite_sync_description": None, + "eventbrite_sync_status": "PENDING", + "title": None, + "venue": None, + "sync_with_eventbrite": False, + "currency": "USD", + "live_stream_url": None, + "host_user": None, + "is_public": True, + **data, + } + + +def event_table(data={}): + return { + "academy_id": 0, + "author_id": None, + "banner": "", + "capacity": 0, + "description": None, + "ending_at": ..., + "event_type_id": None, + "eventbrite_id": None, + "eventbrite_organizer_id": None, + "eventbrite_status": None, + "eventbrite_url": None, + "free_for_bootcamps": None, + "excerpt": None, + "tags": "", + "slug": None, + "host": None, + "id": 0, + "lang": None, + "online_event": False, + "live_stream_url": None, + "free_for_bootcamps": True, + "asset_slug": None, + "organization_id": 0, + "host_user_id": None, + "published_at": None, + "starting_at": ..., + "status": "DRAFT", + "eventbrite_sync_description": None, + "eventbrite_sync_status": "", + "title": None, + "ended_at": None, + "url": "", + "venue_id": None, + "live_stream_url": None, + "sync_with_eventbrite": False, + "currency": "", + "is_public": True, + **data, + } + + +def test_all_events_get_all_events_with_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:all_events") + + 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_events_get_all_events_with_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=True, + ) + + url = reverse_lazy("events:all_events") + + 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_events_get_all_events_with_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:all_events") + + 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) From 6da552394ac269293362df14c2060448458477a4 Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Mon, 25 Nov 2024 00:38:15 +0000 Subject: [PATCH 16/20] Add tests --- ...gies.py => 0061_eventtype_technologies.py} | 0 .../tests/mixins/new_events_tests_case.py | 9 +- .../events/tests/urls/tests_academy_event.py | 157 ---------- breathecode/events/tests/urls/tests_all.py | 221 ++++++++++++++ .../events/tests/urls/tests_events_all.py | 274 ------------------ 5 files changed, 227 insertions(+), 434 deletions(-) rename breathecode/events/migrations/{0060_eventtype_technologies.py => 0061_eventtype_technologies.py} (100%) delete mode 100644 breathecode/events/tests/urls/tests_events_all.py diff --git a/breathecode/events/migrations/0060_eventtype_technologies.py b/breathecode/events/migrations/0061_eventtype_technologies.py similarity index 100% rename from breathecode/events/migrations/0060_eventtype_technologies.py rename to breathecode/events/migrations/0061_eventtype_technologies.py diff --git a/breathecode/events/tests/mixins/new_events_tests_case.py b/breathecode/events/tests/mixins/new_events_tests_case.py index cb4055556..50d047987 100644 --- a/breathecode/events/tests/mixins/new_events_tests_case.py +++ b/breathecode/events/tests/mixins/new_events_tests_case.py @@ -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, ) @@ -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 ] diff --git a/breathecode/events/tests/urls/tests_academy_event.py b/breathecode/events/tests/urls/tests_academy_event.py index e0ce1db2a..47763d1e5 100644 --- a/breathecode/events/tests/urls/tests_academy_event.py +++ b/breathecode/events/tests/urls/tests_academy_event.py @@ -404,163 +404,6 @@ def test_all_academy_events_upcoming(self): self.assertEqual(json, expected) self.assertEqual(response.status_code, 200) - def test_all_academy_events_get_with_event_is_public_true_in_filter_is_public_true(self): - self.headers(academy=1) - event_kwargs = {"is_public": True} - model = self.generate_models( - authenticate=True, - profile_academy=True, - capability="read_event", - role="potato", - syllabus=True, - venue=True, - event=True, - event_kwargs=event_kwargs, - ) - url = reverse_lazy("events:academy_event") + "?is_public=true" - - 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_get_with_event_is_public_true_in_filter_is_public_false(self): - self.headers(academy=1) - event_kwargs = {"is_public": True} - model = self.generate_models( - authenticate=True, - profile_academy=True, - capability="read_event", - role="potato", - syllabus=True, - venue=True, - event=True, - event_kwargs=event_kwargs, - ) - url = reverse_lazy("events:academy_event") + "?is_public=false" - - response = self.client.get(url) - json = response.json() - - expected = [] - - self.assertEqual(json, expected) - self.assertEqual(response.status_code, 200) - - def test_all_academy_events_get_with_event_is_public_false_in_filter_is_public_false(self): - self.headers(academy=1) - event_kwargs = {"is_public": False} - model = self.generate_models( - authenticate=True, - profile_academy=True, - capability="read_event", - role="potato", - syllabus=True, - venue=True, - event=True, - event_kwargs=event_kwargs, - ) - url = reverse_lazy("events:academy_event") + "?is_public=false" - - 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_get_with_event_is_public_false_in_filter_is_public_true(self): - self.headers(academy=1) - event_kwargs = {"is_public": False} - model = self.generate_models( - authenticate=True, - profile_academy=True, - capability="read_event", - role="potato", - syllabus=True, - venue=True, - event=True, - event_kwargs=event_kwargs, - ) - url = reverse_lazy("events:academy_event") + "?is_public=true" - - response = self.client.get(url) - json = response.json() - - expected = [] - - self.assertEqual(json, expected) - self.assertEqual(response.status_code, 200) - def test_all_academy_events_not_found(self): self.headers(academy=1) url = reverse_lazy("events:academy_event") diff --git a/breathecode/events/tests/urls/tests_all.py b/breathecode/events/tests/urls/tests_all.py index 3201ce064..be805e75e 100644 --- a/breathecode/events/tests/urls/tests_all.py +++ b/breathecode/events/tests/urls/tests_all.py @@ -37,6 +37,7 @@ def serialize_event(event): 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, + "is_public": event.is_public, "venue": ( None if not event.venue @@ -196,3 +197,223 @@ def test_filter_by_technologies_obtain_two(client: capy.Client, database: capy.D assert response.status_code == 200 assert len(json) == 2 assert expected == json + + +def test_all_academy_events_get_with_event_is_public_true_in_filter_is_public_true( + client: capy.Client, database: capy.Database, fake: capy.Fake +): + url = reverse_lazy("events:all") + + event_types = [ + { + "slug": fake.slug(), + "name": fake.name(), + "description": "description1", + "technologies": "python, flask", + }, + { + "slug": fake.slug(), + "name": fake.name(), + "description": "description2", + "technologies": "javascript, react", + }, + ] + + 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=event_types, + 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, + "is_public": True, + } + for n in range(len(event_types)) + ], + ) + + response = client.get(f"{url}?is_public=true") + json = response.json() + + expected = [serialize_event(event) for event in model.event if event.is_public] + + assert response.status_code == 200 + assert len(json) == len(expected) + assert expected == json + + +def test_all_academy_events_get_with_event_is_public_false_in_filter_is_public_true( + client: capy.Client, database: capy.Database, fake: capy.Fake +): + url = reverse_lazy("events:all") + + event_types = [ + { + "slug": fake.slug(), + "name": fake.name(), + "description": "description1", + "technologies": "python, flask", + }, + { + "slug": fake.slug(), + "name": fake.name(), + "description": "description2", + "technologies": "javascript, react", + }, + ] + + 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=event_types, + 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, + "is_public": False, + } + for n in range(len(event_types)) + ], + ) + + response = client.get(f"{url}?is_public=true") + json = response.json() + + expected = [serialize_event(event) for event in model.event if event.is_public] + + assert response.status_code == 200 + assert len(json) == len(expected) + assert expected == json + + +def test_all_academy_events_get_with_event_is_public_false_in_filter_is_public_false( + client: capy.Client, database: capy.Database, fake: capy.Fake +): + url = reverse_lazy("events:all") + + event_types = [ + { + "slug": fake.slug(), + "name": fake.name(), + "description": "description1", + "technologies": "python, flask", + }, + { + "slug": fake.slug(), + "name": fake.name(), + "description": "description2", + "technologies": "javascript, react", + }, + ] + + 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=event_types, + 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, + "is_public": False, + } + for n in range(len(event_types)) + ], + ) + + response = client.get(f"{url}?is_public=false") + json = response.json() + + expected = [serialize_event(event) for event in model.event if event.is_public == False] + + assert response.status_code == 200 + assert len(json) == len(expected) + assert expected == json + + +def test_all_academy_events_get_with_event_is_public_true_in_filter_is_public_false( + client: capy.Client, database: capy.Database, fake: capy.Fake +): + url = reverse_lazy("events:all") + + event_types = [ + { + "slug": fake.slug(), + "name": fake.name(), + "description": "description1", + "technologies": "python, flask", + }, + { + "slug": fake.slug(), + "name": fake.name(), + "description": "description2", + "technologies": "javascript, react", + }, + ] + + 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=event_types, + 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, + "is_public": True, + } + for n in range(len(event_types)) + ], + ) + + response = client.get(f"{url}?is_public=false") + json = response.json() + + expected = [serialize_event(event) for event in model.event if event.is_public == False] + + assert response.status_code == 200 + assert len(json) == len(expected) + assert expected == json diff --git a/breathecode/events/tests/urls/tests_events_all.py b/breathecode/events/tests/urls/tests_events_all.py deleted file mode 100644 index 613479e3e..000000000 --- a/breathecode/events/tests/urls/tests_events_all.py +++ /dev/null @@ -1,274 +0,0 @@ -import os -from unittest.mock import MagicMock, PropertyMock, call, patch -from uuid import UUID - -from django.urls.base import reverse_lazy -from django.utils import timezone - -from breathecode.events.caches import EventCache -from breathecode.services import datetime_to_iso_format -from breathecode.utils.api_view_extensions.api_view_extension_handlers import APIViewExtensionHandlers - -from ..mixins.new_events_tests_case import EventTestCase - -seed = os.urandom(16) -uuid = UUID(bytes=seed, version=4) - - -def post_serializer(data={}): - return { - "tags": "", - "url": "", - "banner": "", - "capacity": 0, - "starting_at": ..., - "ending_at": ..., - "academy": 0, - "author": None, - "description": None, - "free_for_bootcamps": None, - "event_type": None, - "eventbrite_id": None, - "eventbrite_organizer_id": None, - "eventbrite_status": None, - "eventbrite_url": None, - "slug": None, - "excerpt": None, - "host": None, - "id": 0, - "lang": None, - "online_event": False, - "live_stream_url": None, - "free_for_bootcamps": True, - "asset_slug": None, - "ended_at": None, - "organization": 0, - "published_at": None, - "status": "DRAFT", - "eventbrite_sync_description": None, - "eventbrite_sync_status": "PENDING", - "title": None, - "venue": None, - "sync_with_eventbrite": False, - "currency": "USD", - "live_stream_url": None, - "host_user": None, - "is_public": True, - **data, - } - - -def event_table(data={}): - return { - "academy_id": 0, - "author_id": None, - "banner": "", - "capacity": 0, - "description": None, - "ending_at": ..., - "event_type_id": None, - "eventbrite_id": None, - "eventbrite_organizer_id": None, - "eventbrite_status": None, - "eventbrite_url": None, - "free_for_bootcamps": None, - "excerpt": None, - "tags": "", - "slug": None, - "host": None, - "id": 0, - "lang": None, - "online_event": False, - "live_stream_url": None, - "free_for_bootcamps": True, - "asset_slug": None, - "organization_id": 0, - "host_user_id": None, - "published_at": None, - "starting_at": ..., - "status": "DRAFT", - "eventbrite_sync_description": None, - "eventbrite_sync_status": "", - "title": None, - "ended_at": None, - "url": "", - "venue_id": None, - "live_stream_url": None, - "sync_with_eventbrite": False, - "currency": "", - "is_public": True, - **data, - } - - -def test_all_events_get_all_events_with_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:all_events") - - 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_events_get_all_events_with_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=True, - ) - - url = reverse_lazy("events:all_events") - - 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_events_get_all_events_with_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:all_events") - - 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) From ef148243f8b86190cab607d41087c0443d074b1b Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Mon, 25 Nov 2024 00:52:33 +0000 Subject: [PATCH 17/20] rever consumable --- breathecode/payments/data.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/breathecode/payments/data.py b/breathecode/payments/data.py index b505d6cf7..3fb94e134 100644 --- a/breathecode/payments/data.py +++ b/breathecode/payments/data.py @@ -10,8 +10,6 @@ def get_virtual_consumables() -> list[ConsumableType]: return [ consumable( service_item=service_item(service=48, unit_type="unit", how_many=-1), - ), - consumable( service_item=service_item(service=93, unit_type="unit", how_many=-1), ), ] From 4d37a211b712fa01a0212214c44766920087538d Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Mon, 25 Nov 2024 16:36:39 +0000 Subject: [PATCH 18/20] Comment ldclient file --- ...gies.py => 0060_eventtype_technologies.py} | 0 ...t_is_public.py => 0061_event_is_public.py} | 4 +- breathecode/services/__init__.py | 5 +- .../services/launch_darkly/__init__.py | 2 +- breathecode/services/launch_darkly/client.py | 74 +++++++++---------- 5 files changed, 43 insertions(+), 42 deletions(-) rename breathecode/events/migrations/{0061_eventtype_technologies.py => 0060_eventtype_technologies.py} (100%) rename breathecode/events/migrations/{0060_event_is_public.py => 0061_event_is_public.py} (82%) diff --git a/breathecode/events/migrations/0061_eventtype_technologies.py b/breathecode/events/migrations/0060_eventtype_technologies.py similarity index 100% rename from breathecode/events/migrations/0061_eventtype_technologies.py rename to breathecode/events/migrations/0060_eventtype_technologies.py diff --git a/breathecode/events/migrations/0060_event_is_public.py b/breathecode/events/migrations/0061_event_is_public.py similarity index 82% rename from breathecode/events/migrations/0060_event_is_public.py rename to breathecode/events/migrations/0061_event_is_public.py index cc57b349c..40fc9a855 100644 --- a/breathecode/events/migrations/0060_event_is_public.py +++ b/breathecode/events/migrations/0061_event_is_public.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.2 on 2024-11-14 16:23 +# Generated by Django 5.1.2 on 2024-11-25 16:32 from django.db import migrations, models @@ -6,7 +6,7 @@ class Migration(migrations.Migration): dependencies = [ - ("events", "0059_event_asset_slug"), + ("events", "0060_eventtype_technologies"), ] operations = [ diff --git a/breathecode/services/__init__.py b/breathecode/services/__init__.py index 86f51a68e..acb1c6e75 100644 --- a/breathecode/services/__init__.py +++ b/breathecode/services/__init__.py @@ -1,6 +1,7 @@ from .datetime_to_iso_format import datetime_to_iso_format # noqa: F401 from .eventbrite import CAMPAIGN, SOURCE, Eventbrite # noqa: F401 +from .google_apps import * # noqa: F401 from .google_cloud import Datastore, Function, Storage # noqa: F401 from .google_meet import * # noqa: F401 -from .google_apps import * # noqa: F401 -from .launch_darkly import * # noqa: F401 + +# from .launch_darkly import * # noqa: F401 diff --git a/breathecode/services/launch_darkly/__init__.py b/breathecode/services/launch_darkly/__init__.py index a5658ab9b..5971ed15c 100644 --- a/breathecode/services/launch_darkly/__init__.py +++ b/breathecode/services/launch_darkly/__init__.py @@ -1 +1 @@ -from .client import * # noqa: F401 +# from .client import * # noqa: F401 diff --git a/breathecode/services/launch_darkly/client.py b/breathecode/services/launch_darkly/client.py index 5ff9bc0a6..5ee090542 100644 --- a/breathecode/services/launch_darkly/client.py +++ b/breathecode/services/launch_darkly/client.py @@ -1,53 +1,53 @@ -import logging, os -import re -from typing import Any -import ldclient -from ldclient.config import Config -from ldclient import Context, LDClient +# import logging, os +# import re +# from typing import Any +# import ldclient +# from ldclient.config import Config +# from ldclient import Context, LDClient -logger = logging.getLogger(__name__) +# logger = logging.getLogger(__name__) -__all__ = ["LaunchDarkly"] +# __all__ = ["LaunchDarkly"] -clients: dict[str, LDClient] = {} +# clients: dict[str, LDClient] = {} -# docs https://docs.launchdarkly.com/sdk/server-side/python/migration-7-to-8 -class LaunchDarkly: - client: LDClient +# # docs https://docs.launchdarkly.com/sdk/server-side/python/migration-7-to-8 +# class LaunchDarkly: +# client: LDClient - def __init__(self, api_key=None): - api_key = api_key or os.getenv("LAUNCH_DARKLY_API_KEY") +# def __init__(self, api_key=None): +# api_key = api_key or os.getenv("LAUNCH_DARKLY_API_KEY") - if api_key not in clients: - config = Config(api_key) - ldclient.set_config(config) - clients[api_key] = ldclient.get() +# if api_key not in clients: +# config = Config(api_key) +# ldclient.set_config(config) +# clients[api_key] = ldclient.get() - self.client = clients[api_key] +# self.client = clients[api_key] - def get(self, key, context, default=None) -> Any: - return self.client.variation(key, context, default) +# def get(self, key, context, default=None) -> Any: +# return self.client.variation(key, context, default) - def get_evaluation_reason(self, key, context, default=None) -> Any: - return self.client.variation_detail(key, context, default) +# def get_evaluation_reason(self, key, context, default=None) -> Any: +# return self.client.variation_detail(key, context, default) - def _validate_key(self, key): - if not re.findall(r"^[a-zA-Z0-9_\-\.]+$", key): - raise ValueError( - "The chosen key is invalid, it just must incluse letters, numbers, " "underscore, dash and dot" - ) +# def _validate_key(self, key): +# if not re.findall(r"^[a-zA-Z0-9_\-\.]+$", key): +# raise ValueError( +# "The chosen key is invalid, it just must incluse letters, numbers, " "underscore, dash and dot" +# ) - def context(self, key: str, name: str, kind: str, value: dict) -> Context: - self._validate_key(key) - self._validate_key(kind) +# def context(self, key: str, name: str, kind: str, value: dict) -> Context: +# self._validate_key(key) +# self._validate_key(kind) - context = Context.builder(key).name(name) +# context = Context.builder(key).name(name) - for x in value: - context = context.set(x, value[x]) +# for x in value: +# context = context.set(x, value[x]) - return context.kind(kind).build() +# return context.kind(kind).build() - def join_contexts(self, *contexts: Context): - return Context.create_multi(*contexts) +# def join_contexts(self, *contexts: Context): +# return Context.create_multi(*contexts) From e90f6d8dd253a56c60a9cde73569674f9d99af8c Mon Sep 17 00:00:00 2001 From: Angie Vanegas P Date: Mon, 25 Nov 2024 17:11:52 +0000 Subject: [PATCH 19/20] Add is_public migrations --- breathecode/events/migrations/0061_event_is_public.py | 2 +- postgresql-hook.bash | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 postgresql-hook.bash diff --git a/breathecode/events/migrations/0061_event_is_public.py b/breathecode/events/migrations/0061_event_is_public.py index 40fc9a855..2efd73db2 100644 --- a/breathecode/events/migrations/0061_event_is_public.py +++ b/breathecode/events/migrations/0061_event_is_public.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.2 on 2024-11-25 16:32 +# Generated by Django 5.1.2 on 2024-11-25 17:05 from django.db import migrations, models diff --git a/postgresql-hook.bash b/postgresql-hook.bash old mode 100644 new mode 100755 From a1e20a791877cb2690259363ecbb023ed3d14ea9 Mon Sep 17 00:00:00 2001 From: Luis Miguel Del Valle Date: Tue, 26 Nov 2024 19:33:41 +0000 Subject: [PATCH 20/20] adding visibility filter --- breathecode/registry/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/breathecode/registry/views.py b/breathecode/registry/views.py index 4a7911c28..bd7f63675 100644 --- a/breathecode/registry/views.py +++ b/breathecode/registry/views.py @@ -218,6 +218,10 @@ def get(self, request, tech_slug=None): if like and like not in ["undefined", ""]: items = items.filter(Q(slug__icontains=like) | Q(title__icontains=like)) + if "visibility" in request.GET: + visibility_param = request.GET.get("visibility") + items = items.filter(visibility__iexact=visibility_param) + items = handler.queryset(items) serializer = AssetTechnologySerializer(items, many=True)