From 3c4af49eb004853c11ffe70c065330f8ef6914bc Mon Sep 17 00:00:00 2001 From: Adil Mohak Date: Sun, 6 Oct 2024 08:31:35 +0300 Subject: [PATCH] pylint ignore tests and apps.py --- .pylintrc | 2 +- core/tests.py | 2 +- core/utils.py | 9 +++----- scripts/generate_fake_accounts_data.py | 25 +++++++++++++-------- scripts/generate_fake_core_data.py | 21 +++++++++++++----- scripts/generate_fake_data.py | 30 +++++++++++++++++++++----- 6 files changed, 62 insertions(+), 27 deletions(-) diff --git a/.pylintrc b/.pylintrc index 567845c..7329386 100644 --- a/.pylintrc +++ b/.pylintrc @@ -663,4 +663,4 @@ redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io # Ignore migrations file [MASTER] -ignore=migrations \ No newline at end of file +ignore=migrations,tests.py,tests,apps.py \ No newline at end of file diff --git a/core/tests.py b/core/tests.py index a79ca8b..7ce503c 100644 --- a/core/tests.py +++ b/core/tests.py @@ -1,3 +1,3 @@ -# from django.test import TestCase +from django.test import TestCase # Create your tests here. diff --git a/core/utils.py b/core/utils.py index 5bd2d5d..6705be0 100644 --- a/core/utils.py +++ b/core/utils.py @@ -5,7 +5,6 @@ from django.template.loader import render_to_string from django.utils.html import strip_tags from django.conf import settings -from django.utils.text import slugify def send_email(user, subject, msg): @@ -50,11 +49,9 @@ def unique_slug_generator(instance, new_slug=None): else: slug = slugify(instance.title) - Klass = instance.__class__ - qs_exists = Klass.objects.filter(slug=slug).exists() + klass = instance.__class__ + qs_exists = klass.objects.filter(slug=slug).exists() if qs_exists: - new_slug = "{slug}-{randstr}".format( - slug=slug, randstr=random_string_generator(size=4) - ) + new_slug = f"{slug}-{random_string_generator(size=4)}" return unique_slug_generator(instance, new_slug=new_slug) return slug diff --git a/scripts/generate_fake_accounts_data.py b/scripts/generate_fake_accounts_data.py index 5f28770..8feb75d 100644 --- a/scripts/generate_fake_accounts_data.py +++ b/scripts/generate_fake_accounts_data.py @@ -16,10 +16,11 @@ fake = Faker() + class UserFactory(DjangoModelFactory): """ Factory for creating User instances with optional flags. - + Attributes: username (str): The generated username. first_name (str): The generated first name. @@ -33,7 +34,7 @@ class UserFactory(DjangoModelFactory): is_parent (bool): Flag indicating if the user is a parent. is_dep_head (bool): Flag indicating if the user is a department head. """ - + class Meta: model = User @@ -53,7 +54,7 @@ class Meta: def _create(cls, model_class: type, *args, **kwargs) -> User: """ Create a User instance with optional flags. - + Args: model_class (type): The class of the model to create. @@ -71,6 +72,7 @@ def _create(cls, model_class: type, *args, **kwargs) -> User: user.save() return user + class ProgramFactory(DjangoModelFactory): """ Factory for creating Program instances. @@ -90,20 +92,23 @@ class Meta: def _create(cls, model_class: type, *args, **kwargs) -> Program: """ Create a Program instance using get_or_create to avoid duplicates. - + Args: model_class (type): The class of the model to create. Returns: Program: The created Program instance. """ - program, created = Program.objects.get_or_create(title=kwargs.get("title"), defaults=kwargs) + program, created = Program.objects.get_or_create( + title=kwargs.get("title"), defaults=kwargs + ) return program + class StudentFactory(DjangoModelFactory): """ Factory for creating Student instances with associated User and Program. - + Attributes: student (User): The associated User instance. level (str): The level of the student. @@ -117,10 +122,11 @@ class Meta: level: str = Iterator([choice[0] for choice in LEVEL]) program: Program = SubFactory(ProgramFactory) + class ParentFactory(DjangoModelFactory): """ Factory for creating Parent instances with associated User, Student, and Program. - + Attributes: user (User): The associated User instance. student (Student): The associated Student instance. @@ -143,7 +149,9 @@ class Meta: relation_ship: str = Iterator([choice[0] for choice in RELATION_SHIP]) -def generate_fake_accounts_data(num_programs: int, num_students: int, num_parents: int) -> None: +def generate_fake_accounts_data( + num_programs: int, num_students: int, num_parents: int +) -> None: """ Generate fake data for Programs, Students, Parents, and DepartmentHeads. @@ -162,4 +170,3 @@ def generate_fake_accounts_data(num_programs: int, num_students: int, num_parent generate_fake_accounts_data(10, 10, 10) - diff --git a/scripts/generate_fake_core_data.py b/scripts/generate_fake_core_data.py index 7914051..c9e9f24 100644 --- a/scripts/generate_fake_core_data.py +++ b/scripts/generate_fake_core_data.py @@ -14,6 +14,7 @@ fake = Faker() + class NewsAndEventsFactory(DjangoModelFactory): """ Factory for creating NewsAndEvents instances. @@ -35,6 +36,7 @@ class Meta: updated_date: timezone.datetime = fake.date_time_this_year() upload_time: timezone.datetime = fake.date_time_this_year() + class SessionFactory(DjangoModelFactory): """ Factory for creating Session instances. @@ -51,7 +53,7 @@ class Meta: session: str = LazyAttribute(lambda x: fake.sentence(nb_words=2)) is_current_session: bool = fake.boolean(chance_of_getting_true=50) next_session_begins = LazyAttribute(lambda x: fake.future_datetime()) - + class SemesterFactory(DjangoModelFactory): """ @@ -72,6 +74,7 @@ class Meta: session: Session = SubFactory(SessionFactory) next_semester_begins = LazyAttribute(lambda x: fake.future_datetime()) + class ActivityLogFactory(DjangoModelFactory): """ Factory for creating ActivityLog instances. @@ -86,7 +89,12 @@ class Meta: message: str = LazyAttribute(lambda x: fake.text()) -def generate_fake_core_data(num_news_and_events: int, num_sessions: int, num_semesters: int, num_activity_logs: int) -> None: +def generate_fake_core_data( + num_news_and_events: int, + num_sessions: int, + num_semesters: int, + num_activity_logs: int, +) -> None: """ Generate fake data for core models: NewsAndEvents, Session, Semester, and ActivityLog. @@ -97,7 +105,9 @@ def generate_fake_core_data(num_news_and_events: int, num_sessions: int, num_sem num_activity_logs (int): Number of ActivityLog instances to generate. """ # Generate fake NewsAndEvents instances - news_and_events: List[NewsAndEvents] = NewsAndEventsFactory.create_batch(num_news_and_events) + news_and_events: List[NewsAndEvents] = NewsAndEventsFactory.create_batch( + num_news_and_events + ) print(f"Generated {num_news_and_events} NewsAndEvents instances.") # Generate fake Session instances @@ -109,6 +119,7 @@ def generate_fake_core_data(num_news_and_events: int, num_sessions: int, num_sem print(f"Generated {num_semesters} Semester instances.") # Generate fake ActivityLog instances - activity_logs: List[ActivityLog] = ActivityLogFactory.create_batch(num_activity_logs) + activity_logs: List[ActivityLog] = ActivityLogFactory.create_batch( + num_activity_logs + ) print(f"Generated {num_activity_logs} ActivityLog instances.") - diff --git a/scripts/generate_fake_data.py b/scripts/generate_fake_data.py index 8bebc77..cdd0b0f 100644 --- a/scripts/generate_fake_data.py +++ b/scripts/generate_fake_data.py @@ -3,7 +3,15 @@ from factory import SubFactory, LazyAttribute, Iterator from faker import Faker -from course.models import Program, Course, CourseAllocation,Upload, UploadVideo,CourseOffer, SEMESTER +from course.models import ( + Program, + Course, + CourseAllocation, + Upload, + UploadVideo, + CourseOffer, + SEMESTER, +) from accounts.models import User, DepartmentHead from core.models import Session @@ -12,6 +20,7 @@ fake = Faker() + class DepartmentHeadFactory(DjangoModelFactory): class Meta: model = DepartmentHead @@ -35,6 +44,7 @@ class Meta: title: str = LazyAttribute(lambda x: fake.sentence(nb_words=3)) summary: str = LazyAttribute(lambda x: fake.paragraph()) + class CourseFactory(DjangoModelFactory): """ Factory for creating Course instances. @@ -66,6 +76,7 @@ class Meta: semester: str = Iterator([choice[0] for choice in SEMESTER]) is_elective: bool = LazyAttribute(lambda x: fake.boolean()) + class CourseAllocationFactory(DjangoModelFactory): """ Factory for creating CourseAllocation instances. @@ -81,6 +92,7 @@ class Meta: lecturer: Type[User] = SubFactory(UserFactory, is_lecturer=True) session: Type[Session] = SubFactory(SessionFactory) + class UploadFactory(DjangoModelFactory): """ Factory for creating Upload instances. @@ -102,6 +114,7 @@ class Meta: updated_date = fake.date_time_this_year() upload_time = fake.date_time_this_year() + class UploadVideoFactory(DjangoModelFactory): """ Factory for creating UploadVideo instances. @@ -125,6 +138,7 @@ class Meta: summary: str = LazyAttribute(lambda x: fake.paragraph()) timestamp = fake.date_time_this_year() + class CourseOfferFactory(DjangoModelFactory): """ Factory for creating CourseOffer instances. @@ -136,10 +150,17 @@ class CourseOfferFactory(DjangoModelFactory): class Meta: model = CourseOffer - dep_head = SubFactory(DepartmentHeadFactory) + dep_head = SubFactory(DepartmentHeadFactory) -def generate_fake_course_data(num_programs: int, num_courses: int, num_course_allocations: int, num_uploads: int, num_upload_videos: int, num_course_offers: int) -> None: +def generate_fake_course_data( + num_programs: int, + num_courses: int, + num_course_allocations: int, + num_uploads: int, + num_upload_videos: int, + num_course_offers: int, +) -> None: """Generate fake data using various factories. Args: @@ -175,5 +196,4 @@ def generate_fake_course_data(num_programs: int, num_courses: int, num_course_al print(f"Created {len(course_offers)} course offers.") - -generate_fake_course_data(10, 10, 10, 10, 10, 10) \ No newline at end of file +generate_fake_course_data(10, 10, 10, 10, 10, 10)