From 462c77c935faf0fa5cceb363b4ae26aeb59387e9 Mon Sep 17 00:00:00 2001 From: Walexero Date: Mon, 10 Oct 2022 08:40:58 -0400 Subject: [PATCH 1/4] Updated repo to upstream commits with fix for issue:#1346 --- project/accounts/factory.py | 70 ++++++++++++++ project/categories/factory.py | 11 +++ project/notification/factory.py | 17 ++++ project/threads/factory.py | 164 ++++++++++++++++++++++++++++++++ 4 files changed, 262 insertions(+) create mode 100644 project/accounts/factory.py create mode 100644 project/categories/factory.py create mode 100644 project/notification/factory.py create mode 100644 project/threads/factory.py diff --git a/project/accounts/factory.py b/project/accounts/factory.py new file mode 100644 index 000000000..041fd00ab --- /dev/null +++ b/project/accounts/factory.py @@ -0,0 +1,70 @@ +from turtle import color +import factory +from . import models +from categories.factory import CategoryFactory + +class UserFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.User + + +class ProfileFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.Profile + + profile = factory.RelatedFactory(UserFactory, factory_related_name="profile") + first_name = factory.Faker('first_name') + last_name = factory.Faker('last_name') + about_me = factory.Faker('sentence', nb_words=20) + + @factory.post_generation + def categories(self, create, extracted, **kwargs): + if not create or not extracted: + # Simple build, or nothing to add, do nothing. + return + + # Add the iterable of categores using bulk addition + self.categories.add(*extracted) + + @factory.post_generation + def tags(self, create, extracted, **kwargs): + self.tags.add(u'abc, cde', u'xzy') + + @factory.post_generation + def followers(self, create, extracted, **kwargs): + if not create or not extracted: + # Simple build, or nothing to add, do nothing. + return + + # Add the iterable of following using bulk addition + self.followers.add(*extracted) + + @factory.post_generation + def following(self, create, extracted, **kwargs): + if not create or not extracted: + # Simple build, or nothing to add, do nothing. + return + + # Add the iterable of following using bulk addition + self.following.add(*extracted) + + is_verified = factory.Faker().pybool() + full_profile = factory.Faker().pybool() + profile_image = factory.django.ImageField(color='blue') + profile_image_thumb = factory.django.ImageField(color='blue') + + #defining the ProfileManager for the objects field + @classmethod + def _create(cls, model_class, *args, **kwargs): + """Override the default ``_create`` with our custom call.""" + manager = cls._get_manager(model_class) + # The default would use ``manager.create(*args, **kwargs)`` + return manager.summarize(*args, **kwargs) + + + + + + + + diff --git a/project/categories/factory.py b/project/categories/factory.py new file mode 100644 index 000000000..1f27d018b --- /dev/null +++ b/project/categories/factory.py @@ -0,0 +1,11 @@ +import factory +from . import models +from shared_factory.shared_factory import FreezeTimeModelFactory + +class CategoryFactory(FreezeTimeModelFactory): + class Meta: + model = models.Category + + name = factory.Iterator(["Politics","Voting","Referendum"]) + + diff --git a/project/notification/factory.py b/project/notification/factory.py new file mode 100644 index 000000000..b98143e9f --- /dev/null +++ b/project/notification/factory.py @@ -0,0 +1,17 @@ +import factory +from . import models +from shared_factory.shared_factory import FreezeTimeModelFactory +from accounts.factory import ProfileFactory +from threads.factory import ThreadFactory, CiviFactory + +class NotificationFactory(FreezeTimeModelFactory): + class Meta: + model = models.Notification + + account = factory.SubFactory(ProfileFactory) + thread = factory.SubFactory(ThreadFactory) + civi = factory.SubFactory(CiviFactory) + activity_type = factory.fuzzy.FuzzyChoice(models.Notification.activity_CHOICES, getter=lambda c: c[0]) + read = factory.Faker().pybool() + + diff --git a/project/threads/factory.py b/project/threads/factory.py new file mode 100644 index 000000000..823262cda --- /dev/null +++ b/project/threads/factory.py @@ -0,0 +1,164 @@ +from turtle import title +import factory +from . import models +from shared_factory.shared_factory import FreezeTimeModelFactory +from accounts.factory import UserFactory +from categories.factory import CategoryFactory +from core.constants import CIVI_TYPES + +class FactFactory(FreezeTimeModelFactory): + class Meta: + model = models.Fact + + body = factory.Faker('sentence', nb_words=100) + + +class ThreadFactory(FreezeTimeModelFactory): + class Meta: + model = models.Thread + + author = factory.SubFactory(UserFactory) + category = factory.SubFactory(CategoryFactory) + + @factory.post_generation + def facts(self, create, extracted, **kwargs): + if not create or not extracted: + # Simple build, or nothing to add, do nothing. + return + # Add the iterable of categores using bulk addition + self.facts.add(*extracted) + + @factory.post_generation + def tags(self, create, extracted, **kwargs): + self.tags.add(u'abc, cde', u'xzy') + + title = factory.Faker('sentence', nb_words= 4) + summary = factory.Faker('sentence', nb_words= 30) + image = factory.django.ImageField(color='blue') + is_draft = factory.Faker().pybool() + num_views = factory.fuzzy.FuzzyInteger(0, 30) + num_civis = factory.fuzzy.FuzzyInteger(0, 30) + num_solutions = factory.fuzzy.FuzzyInteger(0, 30) + + #defining the ThreadManager for the objects field + @classmethod + def _create(cls, model_class, *args, **kwargs): + """Override the default ``_create`` with our custom call.""" + manager = cls._get_manager(model_class) + # The default would use ``manager.create(*args, **kwargs)`` + return manager.summarize(*args, **kwargs) + + +class CiviFactory(FreezeTimeModelFactory): + class Meta: + model = models.Civi + + authors = factory.SubFactory(UserFactory) + thread = factory.SubFactory(ThreadFactory) + + @factory.post_generation + def tags(self, create, extracted, **kwargs): + self.tags.add(u'abc, cde', u'xzy') + + @factory.post_generation + def linked_civis(self, create, extracted, **kwargs): + if not create or not extracted: + # Simple build, or nothing to add, do nothing. + return + # Add the iterable of following using bulk addition + self.linked_civis.add(*extracted) + + title = factory.Faker('sentence', nb_words= 4) + body = factory.Faker('sentence', nb_words= 100) + c_type = factory.fuzzy.FuzzyChoice(CIVI_TYPES, getter=lambda c: c[0]) + votes_vneg = factory.fuzzy.FuzzyInteger(0, 30) + votes_neg = factory.fuzzy.FuzzyInteger(0, 30) + votes_neutral = factory.fuzzy.FuzzyInteger(0, 30) + votes_pos = factory.fuzzy.FuzzyInteger(0, 30) + votes_vpos = factory.fuzzy.FuzzyInteger(0, 30) + + #Please verify if this is the right implementation for votes = property(_get_votes) + @classmethod + def _create(cls, model_class, *args, **kwargs): + votes = model_class(*args, **kwargs) + return votes._get_votes() + + #defining the CiViManager for the objects field + @classmethod + def _create(cls, model_class, *args, **kwargs): + """Override the default ``_create`` with our custom call.""" + manager = cls._get_manager(model_class) + # The default would use ``manager.create(*args, **kwargs)`` + return manager.summarize(*args, **kwargs) + + +class ResponseFactory(factory.Factory): + class Meta: + model = models.Response + + author = factory.SubFactory(UserFactory) + civi = factory.SubFactory(CiviFactory) + title = factory.Faker('sentence', nb_words= 4) + body = factory.Faker('sentence', nb_words= 100) + votes_vneg = factory.fuzzy.FuzzyInteger(0, 30) + votes_neg = factory.fuzzy.FuzzyInteger(0, 30) + votes_neutral = factory.fuzzy.FuzzyInteger(0, 30) + votes_pos = factory.fuzzy.FuzzyInteger(0, 30) + votes_vpos = factory.fuzzy.FuzzyInteger(0, 30) + + +class CiviImageFactory(FreezeTimeModelFactory): + class Meta: + model = models.CiviImage + + civi = factory.SubFactory(CiviFactory) + title = factory.Faker('sentence', nb_words= 4) + image = factory.django.ImageField(color='blue') + + + #defining the CiViManager for the objects field + @classmethod + def _create(cls, model_class, *args, **kwargs): + """Override the default ``_create`` with our custom call.""" + manager = cls._get_manager(model_class) + # The default would use ``manager.create(*args, **kwargs)`` + return manager.get_images(*args, **kwargs) + + +class ActivityFactory(FreezeTimeModelFactory): + class Meta: + model = models.Activity + + user = factory.SubFactory(UserFactory) + thread = factory.SubFactory(ThreadFactory) + civi = factory.SubFactory(CiviFactory) + activity_type = factory.fuzzy.FuzzyChoice(models.Activity.activity_CHOICES) + read = factory.Faker().pybool() + + +class RebuttalFactory(FreezeTimeModelFactory): + class Meta: + model = models.Rebuttal + + author = factory.SubFactory(UserFactory) + response = factory.SubFactory(ResponseFactory) + body = factory.Faker('sentence', nb_words= 100) + votes_vneg = factory.fuzzy.FuzzyInteger(0, 30) + votes_neg = factory.fuzzy.FuzzyInteger(0, 30) + votes_neutral = factory.fuzzy.FuzzyInteger(0, 30) + votes_pos = factory.fuzzy.FuzzyInteger(0, 30) + votes_vpos = factory.fuzzy.FuzzyInteger(0, 30) + + +class RationaleFactory(FreezeTimeModelFactory): + class Meta: + model = models.Rationale + + title = factory.Faker('sentence', nb_words= 4) + body = factory.Faker('sentence', nb_words= 100) + votes_vneg = factory.fuzzy.FuzzyInteger(0, 30) + votes_neg = factory.fuzzy.FuzzyInteger(0, 30) + votes_neutral = factory.fuzzy.FuzzyInteger(0, 30) + votes_pos = factory.fuzzy.FuzzyInteger(0, 30) + votes_vpos = factory.fuzzy.FuzzyInteger(0, 30) + From 021531d479adb02a98384c9afcee7afb870f2db3 Mon Sep 17 00:00:00 2001 From: Walexero Date: Mon, 10 Oct 2022 08:48:57 -0400 Subject: [PATCH 2/4] Synced repo with Upstream and Closes:Add development fixtures for #1350 and Add django-browser-reload #1346 --- project/core/settings.py | 2 ++ project/core/urls.py | 1 + 2 files changed, 3 insertions(+) diff --git a/project/core/settings.py b/project/core/settings.py index c7274c366..a4125e770 100644 --- a/project/core/settings.py +++ b/project/core/settings.py @@ -25,6 +25,7 @@ "django.contrib.staticfiles", "django_extensions", "django_linear_migrations", + "django_browser_reload", "storages", "core", "rest_framework", @@ -50,6 +51,7 @@ # 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + "django_browser_reload.middleware.BrowserReloadMiddleware", ] INTERNAL_IPS = [ diff --git a/project/core/urls.py b/project/core/urls.py index 1769322e6..2bd22421a 100644 --- a/project/core/urls.py +++ b/project/core/urls.py @@ -50,6 +50,7 @@ ), re_path(r"^media/(?P.*)$", serve, {"document_root": settings.MEDIA_ROOT}), path("__debug__/", include("debug_toolbar.urls")), + path("__reload__/", include("django_browser_reload.urls")), ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) From aa323d592324e09139371c868edbc3000438be98 Mon Sep 17 00:00:00 2001 From: Walexero Date: Mon, 10 Oct 2022 08:48:57 -0400 Subject: [PATCH 3/4] Synced repo with Upstream and Closes:Add development fixtures for #1350 and Add django-browser-reload #1346 --- poetry.lock | 20 +++++++++++++++++++- pyproject.toml | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index e9cd52ab5..ec5cd442e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -176,6 +176,17 @@ tzdata = {version = "*", markers = "sys_platform == \"win32\""} argon2 = ["argon2-cffi (>=19.1.0)"] bcrypt = ["bcrypt"] +[[package]] +name = "django-browser-reload" +version = "1.6.0" +description = "Automatically reload your browser in development." +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +Django = ">=3.2" + [[package]] name = "django-cors-headers" version = "3.13.0" @@ -935,7 +946,7 @@ brotli = ["Brotli"] [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "491a7a2661f59ec87999797bf91b3900e7b0c37584794895e4d51535c4ace9bf" +content-hash = "68de52bf82026fee2f307122bc84883dd21dc11517948321616722a71c9f32d9" [metadata.files] appnope = [ @@ -1071,6 +1082,10 @@ Django = [ {file = "Django-4.1.2-py3-none-any.whl", hash = "sha256:26dc24f99c8956374a054bcbf58aab8dc0cad2e6ac82b0fe036b752c00eee793"}, {file = "Django-4.1.2.tar.gz", hash = "sha256:b8d843714810ab88d59344507d4447be8b2cf12a49031363b6eed9f1b9b2280f"}, ] +django-browser-reload = [ + {file = "django-browser-reload-1.6.0.tar.gz", hash = "sha256:9ca69c71796f53868bdc7421f120d147f7a64faa0d5d8c06970ba3f8061af63c"}, + {file = "django_browser_reload-1.6.0-py3-none-any.whl", hash = "sha256:31b8b2d51e8faa5878f21e6b60b8f43e1123907c6e082e9e967962ba63958829"}, +] django-cors-headers = [ {file = "django-cors-headers-3.13.0.tar.gz", hash = "sha256:f9dc6b4e3f611c3199700b3e5f3398c28757dcd559c2f82932687f3d0443cfdf"}, {file = "django_cors_headers-3.13.0-py3-none-any.whl", hash = "sha256:37e42883b5f1f2295df6b4bba96eb2417a14a03270cb24b2a07f021cd4487cf4"}, @@ -1292,6 +1307,7 @@ prompt-toolkit = [ psycopg2-binary = [ {file = "psycopg2-binary-2.9.3.tar.gz", hash = "sha256:761df5313dc15da1502b21453642d7599d26be88bff659382f8f9747c7ebea4e"}, {file = "psycopg2_binary-2.9.3-cp310-cp310-macosx_10_14_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl", hash = "sha256:539b28661b71da7c0e428692438efbcd048ca21ea81af618d845e06ebfd29478"}, + {file = "psycopg2_binary-2.9.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2f2534ab7dc7e776a263b463a16e189eb30e85ec9bbe1bff9e78dae802608932"}, {file = "psycopg2_binary-2.9.3-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6e82d38390a03da28c7985b394ec3f56873174e2c88130e6966cb1c946508e65"}, {file = "psycopg2_binary-2.9.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:57804fc02ca3ce0dbfbef35c4b3a4a774da66d66ea20f4bda601294ad2ea6092"}, {file = "psycopg2_binary-2.9.3-cp310-cp310-manylinux_2_24_aarch64.whl", hash = "sha256:083a55275f09a62b8ca4902dd11f4b33075b743cf0d360419e2051a8a5d5ff76"}, @@ -1325,6 +1341,7 @@ psycopg2-binary = [ {file = "psycopg2_binary-2.9.3-cp37-cp37m-win32.whl", hash = "sha256:adf20d9a67e0b6393eac162eb81fb10bc9130a80540f4df7e7355c2dd4af9fba"}, {file = "psycopg2_binary-2.9.3-cp37-cp37m-win_amd64.whl", hash = "sha256:2f9ffd643bc7349eeb664eba8864d9e01f057880f510e4681ba40a6532f93c71"}, {file = "psycopg2_binary-2.9.3-cp38-cp38-macosx_10_14_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl", hash = "sha256:def68d7c21984b0f8218e8a15d514f714d96904265164f75f8d3a70f9c295667"}, + {file = "psycopg2_binary-2.9.3-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:e6aa71ae45f952a2205377773e76f4e3f27951df38e69a4c95440c779e013560"}, {file = "psycopg2_binary-2.9.3-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:dffc08ca91c9ac09008870c9eb77b00a46b3378719584059c034b8945e26b272"}, {file = "psycopg2_binary-2.9.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:280b0bb5cbfe8039205c7981cceb006156a675362a00fe29b16fbc264e242834"}, {file = "psycopg2_binary-2.9.3-cp38-cp38-manylinux_2_24_aarch64.whl", hash = "sha256:af9813db73395fb1fc211bac696faea4ca9ef53f32dc0cfa27e4e7cf766dcf24"}, @@ -1336,6 +1353,7 @@ psycopg2-binary = [ {file = "psycopg2_binary-2.9.3-cp38-cp38-win32.whl", hash = "sha256:6472a178e291b59e7f16ab49ec8b4f3bdada0a879c68d3817ff0963e722a82ce"}, {file = "psycopg2_binary-2.9.3-cp38-cp38-win_amd64.whl", hash = "sha256:35168209c9d51b145e459e05c31a9eaeffa9a6b0fd61689b48e07464ffd1a83e"}, {file = "psycopg2_binary-2.9.3-cp39-cp39-macosx_10_14_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl", hash = "sha256:47133f3f872faf28c1e87d4357220e809dfd3fa7c64295a4a148bcd1e6e34ec9"}, + {file = "psycopg2_binary-2.9.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:b3a24a1982ae56461cc24f6680604fffa2c1b818e9dc55680da038792e004d18"}, {file = "psycopg2_binary-2.9.3-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:91920527dea30175cc02a1099f331aa8c1ba39bf8b7762b7b56cbf54bc5cce42"}, {file = "psycopg2_binary-2.9.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:887dd9aac71765ac0d0bac1d0d4b4f2c99d5f5c1382d8b770404f0f3d0ce8a39"}, {file = "psycopg2_binary-2.9.3-cp39-cp39-manylinux_2_24_aarch64.whl", hash = "sha256:1f14c8b0942714eb3c74e1e71700cbbcb415acbc311c730370e70c578a44a25c"}, diff --git a/pyproject.toml b/pyproject.toml index 5f1aa20c4..490c6cc98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ django-stubs = "^1.12.0" django-debug-toolbar = "^3.7.0" django-linear-migrations = "^2.5.1" pre-commit = "^2.20.0" +django-browser-reload = "^1.6.0" [tool.mypy] plugins = ["mypy_django_plugin.main"] From f20a8efb28ec9ad8c66bb3293c644ed0ce906ca1 Mon Sep 17 00:00:00 2001 From: Walexero Date: Thu, 20 Oct 2022 15:01:16 +0000 Subject: [PATCH 4/4] Added development fixtures for #1350 --- project/core/settings.py | 2 -- project/core/urls.py | 1 - 2 files changed, 3 deletions(-) diff --git a/project/core/settings.py b/project/core/settings.py index a4125e770..c7274c366 100644 --- a/project/core/settings.py +++ b/project/core/settings.py @@ -25,7 +25,6 @@ "django.contrib.staticfiles", "django_extensions", "django_linear_migrations", - "django_browser_reload", "storages", "core", "rest_framework", @@ -51,7 +50,6 @@ # 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", - "django_browser_reload.middleware.BrowserReloadMiddleware", ] INTERNAL_IPS = [ diff --git a/project/core/urls.py b/project/core/urls.py index 2bd22421a..1769322e6 100644 --- a/project/core/urls.py +++ b/project/core/urls.py @@ -50,7 +50,6 @@ ), re_path(r"^media/(?P.*)$", serve, {"document_root": settings.MEDIA_ROOT}), path("__debug__/", include("debug_toolbar.urls")), - path("__reload__/", include("django_browser_reload.urls")), ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)