pylint ignore tests and apps.py
This commit is contained in:
parent
e736b4419b
commit
3c4af49eb0
@ -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
|
||||
@ -1,3 +1,3 @@
|
||||
# from django.test import TestCase
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
@ -5,7 +5,6 @@ from django.core.mail import send_mail
|
||||
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
|
||||
|
||||
@ -16,6 +16,7 @@ from course.models import Program
|
||||
|
||||
fake = Faker()
|
||||
|
||||
|
||||
class UserFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory for creating User instances with optional flags.
|
||||
@ -71,6 +72,7 @@ class UserFactory(DjangoModelFactory):
|
||||
user.save()
|
||||
return user
|
||||
|
||||
|
||||
class ProgramFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory for creating Program instances.
|
||||
@ -97,9 +99,12 @@ class ProgramFactory(DjangoModelFactory):
|
||||
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.
|
||||
@ -117,6 +122,7 @@ class StudentFactory(DjangoModelFactory):
|
||||
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.
|
||||
@ -143,7 +149,9 @@ class ParentFactory(DjangoModelFactory):
|
||||
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)
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ django.setup()
|
||||
|
||||
fake = Faker()
|
||||
|
||||
|
||||
class NewsAndEventsFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory for creating NewsAndEvents instances.
|
||||
@ -35,6 +36,7 @@ class NewsAndEventsFactory(DjangoModelFactory):
|
||||
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.
|
||||
@ -72,6 +74,7 @@ class SemesterFactory(DjangoModelFactory):
|
||||
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 ActivityLogFactory(DjangoModelFactory):
|
||||
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.")
|
||||
|
||||
|
||||
@ -3,7 +3,15 @@ from factory.django import DjangoModelFactory
|
||||
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 @@ from .generate_fake_core_data import SessionFactory
|
||||
|
||||
fake = Faker()
|
||||
|
||||
|
||||
class DepartmentHeadFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = DepartmentHead
|
||||
@ -35,6 +44,7 @@ class ProgramFactory(DjangoModelFactory):
|
||||
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 CourseFactory(DjangoModelFactory):
|
||||
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 CourseAllocationFactory(DjangoModelFactory):
|
||||
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 UploadFactory(DjangoModelFactory):
|
||||
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 UploadVideoFactory(DjangoModelFactory):
|
||||
summary: str = LazyAttribute(lambda x: fake.paragraph())
|
||||
timestamp = fake.date_time_this_year()
|
||||
|
||||
|
||||
class CourseOfferFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory for creating CourseOffer instances.
|
||||
@ -139,7 +153,14 @@ class CourseOfferFactory(DjangoModelFactory):
|
||||
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)
|
||||
Loading…
x
Reference in New Issue
Block a user