Skip to content

Commit

Permalink
pylint ignore tests and apps.py
Browse files Browse the repository at this point in the history
  • Loading branch information
adilmohak committed Oct 6, 2024
1 parent e736b44 commit 3c4af49
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,4 @@ redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io

# Ignore migrations file
[MASTER]
ignore=migrations
ignore=migrations,tests.py,tests,apps.py
2 changes: 1 addition & 1 deletion core/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# from django.test import TestCase
from django.test import TestCase

# Create your tests here.
9 changes: 3 additions & 6 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
25 changes: 16 additions & 9 deletions scripts/generate_fake_accounts_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -162,4 +170,3 @@ def generate_fake_accounts_data(num_programs: int, num_students: int, num_parent


generate_fake_accounts_data(10, 10, 10)

21 changes: 16 additions & 5 deletions scripts/generate_fake_core_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

fake = Faker()


class NewsAndEventsFactory(DjangoModelFactory):
"""
Factory for creating NewsAndEvents instances.
Expand All @@ -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.
Expand All @@ -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):
"""
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.")

30 changes: 25 additions & 5 deletions scripts/generate_fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -12,6 +20,7 @@

fake = Faker()


class DepartmentHeadFactory(DjangoModelFactory):
class Meta:
model = DepartmentHead
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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)
generate_fake_course_data(10, 10, 10, 10, 10, 10)

0 comments on commit 3c4af49

Please sign in to comment.