-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c058735
commit 87d141d
Showing
19 changed files
with
496 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import unittest | ||
from datetime import datetime | ||
|
||
from fake import FILE_REGISTRY | ||
|
||
from article.factories import ArticleFactory | ||
from article.models import Article, User | ||
|
||
__all__ = ("FactoriesTestCase",) | ||
|
||
|
||
class FactoriesTestCase(unittest.TestCase): | ||
def tearDown(self): | ||
FILE_REGISTRY.clean_up() | ||
|
||
def test_sub_factory(self) -> None: | ||
article = ArticleFactory() | ||
|
||
# Testing SubFactory | ||
self.assertIsInstance(article.author, User) | ||
self.assertIsInstance(article.author.id, int) | ||
self.assertIsInstance(article.author.is_staff, bool) | ||
self.assertIsInstance(article.author.date_joined, datetime) | ||
|
||
# Testing Factory | ||
self.assertIsInstance(article.id, int) | ||
self.assertIsInstance(article.slug, str) | ||
|
||
# Testing hooks | ||
self.assertTrue( | ||
hasattr(article, "pre_save_called") and article.pre_save_called | ||
) | ||
self.assertTrue( | ||
hasattr(article, "post_save_called") and article.post_save_called | ||
) | ||
self.assertTrue( | ||
hasattr(article.author, "pre_save_called") | ||
and article.author.pre_save_called | ||
) | ||
self.assertTrue( | ||
hasattr(article.author, "post_save_called") | ||
and article.author.post_save_called | ||
) | ||
|
||
# Testing batch creation | ||
articles = ArticleFactory.create_batch(5) | ||
self.assertEqual(len(articles), 5) | ||
self.assertIsInstance(articles[0], Article) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
import argparse | ||
import os | ||
import sys | ||
import unittest | ||
|
||
import IPython | ||
|
||
|
||
def run_tests(): | ||
"""Function to run tests in the article directory.""" | ||
loader = unittest.TestLoader() | ||
suite = loader.discover(start_dir="./article", pattern="tests.py") | ||
runner = unittest.TextTestRunner() | ||
runner.run(suite) | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks based on command line arguments.""" | ||
sys.path.insert(0, os.path.abspath(".")) | ||
parser = argparse.ArgumentParser( | ||
description="Management script for the project." | ||
) | ||
parser.add_argument("command", help="The command to run (test or shell)") | ||
|
||
args = parser.parse_args() | ||
|
||
if args.command == "test": | ||
run_tests() | ||
elif args.command == "shell": | ||
IPython.embed() | ||
else: | ||
print("Unknown command. Use 'test' or 'shell'.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from datetime import datetime | ||
|
||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
from fake import FILE_REGISTRY | ||
|
||
from article.factories import ArticleFactory | ||
from article.models import Article | ||
|
||
__all__ = ("FactoriesTestCase",) | ||
|
||
|
||
class FactoriesTestCase(TestCase): | ||
def tearDown(self): | ||
super().tearDown() | ||
FILE_REGISTRY.clean_up() | ||
|
||
def test_sub_factory(self) -> None: | ||
article = ArticleFactory() | ||
|
||
# Testing SubFactory | ||
self.assertIsInstance(article.author, User) | ||
self.assertIsInstance(article.author.id, int) | ||
self.assertIsInstance(article.author.is_staff, bool) | ||
self.assertIsInstance(article.author.date_joined, datetime) | ||
|
||
# Testing Factory | ||
self.assertIsInstance(article.id, int) | ||
self.assertIsInstance(article.slug, str) | ||
|
||
# Testing hooks | ||
self.assertTrue( | ||
hasattr(article, "pre_save_called") and article.pre_save_called | ||
) | ||
self.assertTrue( | ||
hasattr(article, "post_save_called") and article.post_save_called | ||
) | ||
self.assertTrue( | ||
hasattr(article.author, "pre_save_called") | ||
and article.author.pre_save_called | ||
) | ||
self.assertTrue( | ||
hasattr(article.author, "post_save_called") | ||
and article.author.post_save_called | ||
) | ||
|
||
# Testing batch creation | ||
articles = ArticleFactory.create_batch(5) | ||
self.assertEqual(len(articles), 5) | ||
self.assertIsInstance(articles[0], Article) |
Oops, something went wrong.