mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-04-13 09:42:01 +00:00
build factories for testing for profile, reader, rss_feeds models
This commit is contained in:
parent
85765025f0
commit
9221147309
3 changed files with 107 additions and 0 deletions
20
apps/profile/factories.py
Normal file
20
apps/profile/factories.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import factory
|
||||
from factory.django import DjangoModelFactory
|
||||
from django.contrib.auth.models import User
|
||||
from apps.profile.models import Profile
|
||||
|
||||
class UserFactory(DjangoModelFactory):
|
||||
first_name = factory.Faker('first_name')
|
||||
last_name = factory.Faker('last_name')
|
||||
username = factory.Faker('email')
|
||||
date_joined = factory.Faker('date_time')
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
|
||||
|
||||
|
||||
class ProfileFactory(DjangoModelFactory):
|
||||
user = factory.SubFactory(UserFactory)
|
||||
class Meta:
|
||||
model = Profile
|
56
apps/reader/factories.py
Normal file
56
apps/reader/factories.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
import factory
|
||||
from factory.fuzzy import FuzzyAttribute
|
||||
from factory.django import DjangoModelFactory
|
||||
from faker import Faker
|
||||
from apps.rss_feeds.factories import FeedFactory
|
||||
from apps.reader.models import Feature, UserSubscription, UserSubscriptionFolders
|
||||
from apps.profile.factories import UserFactory
|
||||
|
||||
fake = Faker()
|
||||
|
||||
def generate_folder():
|
||||
string = '{"'
|
||||
string += " ".join(fake.words(2))
|
||||
string += '": ['
|
||||
for _ in range(3):
|
||||
string += f"{fake.pyint()}, "
|
||||
string = string[:-2]
|
||||
string += "]},"
|
||||
return string
|
||||
|
||||
def generate_folders():
|
||||
"""
|
||||
"folders": "[5299728, 644144, 1187026, {\"Brainiacs & Opinion\": [569, 38, 3581, 183139, 1186180, 15]}, {\"Science & Technology\": [731503, 140145, 1272495, 76, 161, 39, {\"Hacker\": [5985150, 3323431]}]}, {\"Humor\": [212379, 3530, 5994357]}, {\"Videos\": [3240, 5168]}]"
|
||||
"""
|
||||
string = '"folders":['
|
||||
|
||||
for _ in range(3):
|
||||
string += f"{fake.pyint()}, "
|
||||
for _ in range(3):
|
||||
string += generate_folder()
|
||||
|
||||
string = string[:-1] + "]"
|
||||
return string
|
||||
|
||||
class UserSubscriptionFoldersFactory(DjangoModelFactory):
|
||||
user = factory.SubFactory(UserFactory)
|
||||
folders = FuzzyAttribute(generate_folders)
|
||||
|
||||
class Meta:
|
||||
model = UserSubscriptionFolders
|
||||
|
||||
|
||||
class UserSubscriptionFactory(DjangoModelFactory):
|
||||
user = factory.SubFactory(UserFactory)
|
||||
feed = FuzzyAttribute(FeedFactory)
|
||||
last_read_date = factory.Faker('date_time')
|
||||
|
||||
class Meta:
|
||||
model = UserSubscription
|
||||
|
||||
|
||||
class FeatureFactory(DjangoModelFactory):
|
||||
description = factory.Faker('text')
|
||||
date = factory.Faker('date_time')
|
||||
class Meta:
|
||||
model = Feature
|
31
apps/rss_feeds/factories.py
Normal file
31
apps/rss_feeds/factories.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from faker import Faker
|
||||
import factory
|
||||
from factory.django import DjangoModelFactory
|
||||
from factory.fuzzy import FuzzyAttribute
|
||||
from apps.rss_feeds.models import DuplicateFeed, Feed
|
||||
from django.conf import settings
|
||||
|
||||
NEWSBLUR_DIR = settings.NEWSBLUR_DIR
|
||||
fake = Faker()
|
||||
|
||||
def generate_address():
|
||||
return f"{NEWSBLUR_DIR}/apps/analyzer/fixtures/{fake.word()}.xml"
|
||||
|
||||
class FeedFactory(DjangoModelFactory):
|
||||
feed_address = FuzzyAttribute(generate_address)
|
||||
feed_link = FuzzyAttribute(generate_address)
|
||||
creation = factory.Faker('date')
|
||||
feed_title = factory.Faker('sentence')
|
||||
last_update = factory.Faker('date_time')
|
||||
next_scheduled_update = factory.Faker('date_time')
|
||||
last_story_date = factory.Faker('date_time')
|
||||
min_to_decay = 1
|
||||
last_modified = factory.Faker('date_time')
|
||||
hash_address_and_link = fake.sha1()
|
||||
|
||||
class Meta:
|
||||
model = Feed
|
||||
|
||||
class DuplicateFeedFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = DuplicateFeed
|
Loading…
Add table
Reference in a new issue