403Webshell
Server IP : 66.29.132.122  /  Your IP : 3.144.40.189
Web Server : LiteSpeed
System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User : admazpex ( 531)
PHP Version : 7.2.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/self/root/opt/cloudlinux/venv/lib64/python3.11/site-packages/pylint_django/tests/input/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/self/root/opt/cloudlinux/venv/lib64/python3.11/site-packages/pylint_django/tests/input//external_factory_boy_noerror.py
"""
Test to validate that pylint_django doesn't produce
Instance of 'SubFactory' has no 'pk' member (no-member) warnings
"""
# pylint: disable=attribute-defined-outside-init, missing-docstring, too-few-public-methods
import factory
from django import test
from django.db import models


class Author(models.Model):
    name = models.CharField()


class Book(models.Model):
    title = models.CharField()
    author = models.ForeignKey(Author, related_name="books", on_delete=models.CASCADE)


class AuthorFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = "Author"

    name = factory.Sequence(lambda n: f"Author {n}")


class BookFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = "Book"

    title = factory.Sequence(lambda n: f"Book {n}")
    author = factory.SubFactory(AuthorFactory)
    reviewer = factory.LazyFunction(Author.objects.first())


class BookTestCase(test.LiveServerTestCase):
    serialized_rollback = True

    def _fixture_setup(self):
        super()._fixture_setup()
        self.book = BookFactory()
        _author = AuthorFactory()
        _first_book = _author.books.first()
        self.assertIsNotNone(_first_book)

    def test_author_is_not_none(self):
        self.assertGreater(self.book.pk, 0)
        self.assertGreater(self.book.author.pk, 0)

        self.assertIsNotNone(self.book.title)
        self.assertIsNotNone(self.book.author.name)

    def test_reviewer_is_not_none(self):
        self.assertGreater(self.book.reviewer.pk, 0)

Youez - 2016 - github.com/yon3zu
LinuXploit