pylint ignore tests and apps.py

This commit is contained in:
Adil Mohak 2024-10-06 08:31:35 +03:00
parent e736b4419b
commit 3c4af49eb0
6 changed files with 62 additions and 27 deletions

View File

@ -663,4 +663,4 @@ redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
# Ignore migrations file # Ignore migrations file
[MASTER] [MASTER]
ignore=migrations ignore=migrations,tests.py,tests,apps.py

View File

@ -1,3 +1,3 @@
# from django.test import TestCase from django.test import TestCase
# Create your tests here. # Create your tests here.

View File

@ -5,7 +5,6 @@ from django.core.mail import send_mail
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.html import strip_tags from django.utils.html import strip_tags
from django.conf import settings from django.conf import settings
from django.utils.text import slugify
def send_email(user, subject, msg): def send_email(user, subject, msg):
@ -50,11 +49,9 @@ def unique_slug_generator(instance, new_slug=None):
else: else:
slug = slugify(instance.title) slug = slugify(instance.title)
Klass = instance.__class__ klass = instance.__class__
qs_exists = Klass.objects.filter(slug=slug).exists() qs_exists = klass.objects.filter(slug=slug).exists()
if qs_exists: if qs_exists:
new_slug = "{slug}-{randstr}".format( new_slug = f"{slug}-{random_string_generator(size=4)}"
slug=slug, randstr=random_string_generator(size=4)
)
return unique_slug_generator(instance, new_slug=new_slug) return unique_slug_generator(instance, new_slug=new_slug)
return slug return slug

View File

@ -16,10 +16,11 @@ from course.models import Program
fake = Faker() fake = Faker()
class UserFactory(DjangoModelFactory): class UserFactory(DjangoModelFactory):
""" """
Factory for creating User instances with optional flags. Factory for creating User instances with optional flags.
Attributes: Attributes:
username (str): The generated username. username (str): The generated username.
first_name (str): The generated first name. 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_parent (bool): Flag indicating if the user is a parent.
is_dep_head (bool): Flag indicating if the user is a department head. is_dep_head (bool): Flag indicating if the user is a department head.
""" """
class Meta: class Meta:
model = User model = User
@ -53,7 +54,7 @@ class UserFactory(DjangoModelFactory):
def _create(cls, model_class: type, *args, **kwargs) -> User: def _create(cls, model_class: type, *args, **kwargs) -> User:
""" """
Create a User instance with optional flags. Create a User instance with optional flags.
Args: Args:
model_class (type): The class of the model to create. model_class (type): The class of the model to create.
@ -71,6 +72,7 @@ class UserFactory(DjangoModelFactory):
user.save() user.save()
return user return user
class ProgramFactory(DjangoModelFactory): class ProgramFactory(DjangoModelFactory):
""" """
Factory for creating Program instances. Factory for creating Program instances.
@ -90,20 +92,23 @@ class ProgramFactory(DjangoModelFactory):
def _create(cls, model_class: type, *args, **kwargs) -> Program: def _create(cls, model_class: type, *args, **kwargs) -> Program:
""" """
Create a Program instance using get_or_create to avoid duplicates. Create a Program instance using get_or_create to avoid duplicates.
Args: Args:
model_class (type): The class of the model to create. model_class (type): The class of the model to create.
Returns: Returns:
Program: The created Program instance. 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 return program
class StudentFactory(DjangoModelFactory): class StudentFactory(DjangoModelFactory):
""" """
Factory for creating Student instances with associated User and Program. Factory for creating Student instances with associated User and Program.
Attributes: Attributes:
student (User): The associated User instance. student (User): The associated User instance.
level (str): The level of the student. level (str): The level of the student.
@ -117,10 +122,11 @@ class StudentFactory(DjangoModelFactory):
level: str = Iterator([choice[0] for choice in LEVEL]) level: str = Iterator([choice[0] for choice in LEVEL])
program: Program = SubFactory(ProgramFactory) program: Program = SubFactory(ProgramFactory)
class ParentFactory(DjangoModelFactory): class ParentFactory(DjangoModelFactory):
""" """
Factory for creating Parent instances with associated User, Student, and Program. Factory for creating Parent instances with associated User, Student, and Program.
Attributes: Attributes:
user (User): The associated User instance. user (User): The associated User instance.
student (Student): The associated Student instance. student (Student): The associated Student instance.
@ -143,7 +149,9 @@ class ParentFactory(DjangoModelFactory):
relation_ship: str = Iterator([choice[0] for choice in RELATION_SHIP]) 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. 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) generate_fake_accounts_data(10, 10, 10)

View File

@ -14,6 +14,7 @@ django.setup()
fake = Faker() fake = Faker()
class NewsAndEventsFactory(DjangoModelFactory): class NewsAndEventsFactory(DjangoModelFactory):
""" """
Factory for creating NewsAndEvents instances. Factory for creating NewsAndEvents instances.
@ -35,6 +36,7 @@ class NewsAndEventsFactory(DjangoModelFactory):
updated_date: timezone.datetime = fake.date_time_this_year() updated_date: timezone.datetime = fake.date_time_this_year()
upload_time: timezone.datetime = fake.date_time_this_year() upload_time: timezone.datetime = fake.date_time_this_year()
class SessionFactory(DjangoModelFactory): class SessionFactory(DjangoModelFactory):
""" """
Factory for creating Session instances. Factory for creating Session instances.
@ -51,7 +53,7 @@ class SessionFactory(DjangoModelFactory):
session: str = LazyAttribute(lambda x: fake.sentence(nb_words=2)) session: str = LazyAttribute(lambda x: fake.sentence(nb_words=2))
is_current_session: bool = fake.boolean(chance_of_getting_true=50) is_current_session: bool = fake.boolean(chance_of_getting_true=50)
next_session_begins = LazyAttribute(lambda x: fake.future_datetime()) next_session_begins = LazyAttribute(lambda x: fake.future_datetime())
class SemesterFactory(DjangoModelFactory): class SemesterFactory(DjangoModelFactory):
""" """
@ -72,6 +74,7 @@ class SemesterFactory(DjangoModelFactory):
session: Session = SubFactory(SessionFactory) session: Session = SubFactory(SessionFactory)
next_semester_begins = LazyAttribute(lambda x: fake.future_datetime()) next_semester_begins = LazyAttribute(lambda x: fake.future_datetime())
class ActivityLogFactory(DjangoModelFactory): class ActivityLogFactory(DjangoModelFactory):
""" """
Factory for creating ActivityLog instances. Factory for creating ActivityLog instances.
@ -86,7 +89,12 @@ class ActivityLogFactory(DjangoModelFactory):
message: str = LazyAttribute(lambda x: fake.text()) 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. 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. num_activity_logs (int): Number of ActivityLog instances to generate.
""" """
# Generate fake NewsAndEvents instances # 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.") print(f"Generated {num_news_and_events} NewsAndEvents instances.")
# Generate fake Session 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.") print(f"Generated {num_semesters} Semester instances.")
# Generate fake ActivityLog 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.") print(f"Generated {num_activity_logs} ActivityLog instances.")

View File

@ -3,7 +3,15 @@ from factory.django import DjangoModelFactory
from factory import SubFactory, LazyAttribute, Iterator from factory import SubFactory, LazyAttribute, Iterator
from faker import Faker 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 accounts.models import User, DepartmentHead
from core.models import Session from core.models import Session
@ -12,6 +20,7 @@ from .generate_fake_core_data import SessionFactory
fake = Faker() fake = Faker()
class DepartmentHeadFactory(DjangoModelFactory): class DepartmentHeadFactory(DjangoModelFactory):
class Meta: class Meta:
model = DepartmentHead model = DepartmentHead
@ -35,6 +44,7 @@ class ProgramFactory(DjangoModelFactory):
title: str = LazyAttribute(lambda x: fake.sentence(nb_words=3)) title: str = LazyAttribute(lambda x: fake.sentence(nb_words=3))
summary: str = LazyAttribute(lambda x: fake.paragraph()) summary: str = LazyAttribute(lambda x: fake.paragraph())
class CourseFactory(DjangoModelFactory): class CourseFactory(DjangoModelFactory):
""" """
Factory for creating Course instances. Factory for creating Course instances.
@ -66,6 +76,7 @@ class CourseFactory(DjangoModelFactory):
semester: str = Iterator([choice[0] for choice in SEMESTER]) semester: str = Iterator([choice[0] for choice in SEMESTER])
is_elective: bool = LazyAttribute(lambda x: fake.boolean()) is_elective: bool = LazyAttribute(lambda x: fake.boolean())
class CourseAllocationFactory(DjangoModelFactory): class CourseAllocationFactory(DjangoModelFactory):
""" """
Factory for creating CourseAllocation instances. Factory for creating CourseAllocation instances.
@ -81,6 +92,7 @@ class CourseAllocationFactory(DjangoModelFactory):
lecturer: Type[User] = SubFactory(UserFactory, is_lecturer=True) lecturer: Type[User] = SubFactory(UserFactory, is_lecturer=True)
session: Type[Session] = SubFactory(SessionFactory) session: Type[Session] = SubFactory(SessionFactory)
class UploadFactory(DjangoModelFactory): class UploadFactory(DjangoModelFactory):
""" """
Factory for creating Upload instances. Factory for creating Upload instances.
@ -102,6 +114,7 @@ class UploadFactory(DjangoModelFactory):
updated_date = fake.date_time_this_year() updated_date = fake.date_time_this_year()
upload_time = fake.date_time_this_year() upload_time = fake.date_time_this_year()
class UploadVideoFactory(DjangoModelFactory): class UploadVideoFactory(DjangoModelFactory):
""" """
Factory for creating UploadVideo instances. Factory for creating UploadVideo instances.
@ -125,6 +138,7 @@ class UploadVideoFactory(DjangoModelFactory):
summary: str = LazyAttribute(lambda x: fake.paragraph()) summary: str = LazyAttribute(lambda x: fake.paragraph())
timestamp = fake.date_time_this_year() timestamp = fake.date_time_this_year()
class CourseOfferFactory(DjangoModelFactory): class CourseOfferFactory(DjangoModelFactory):
""" """
Factory for creating CourseOffer instances. Factory for creating CourseOffer instances.
@ -136,10 +150,17 @@ class CourseOfferFactory(DjangoModelFactory):
class Meta: class Meta:
model = CourseOffer 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. """Generate fake data using various factories.
Args: 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.") print(f"Created {len(course_offers)} course offers.")
generate_fake_course_data(10, 10, 10, 10, 10, 10)
generate_fake_course_data(10, 10, 10, 10, 10, 10)