
from pybossa.model import db
from pybossa.model.blogpost import Blogpost
from . import BaseFactory, factory


class BlogpostFactory(BaseFactory):
    FACTORY_FOR = Blogpost

    id = factory.Sequence(lambda n: n)
    title = u'Blogpost title'
    body = u'Blogpost body text'
    app = factory.SubFactory('factories.AppFactory')
    app_id = factory.LazyAttribute(lambda blogpost: blogpost.app.id)
    owner = factory.SelfAttribute('app.owner')
    user_id = factory.LazyAttribute(lambda blogpost: blogpost.owner.id)


from pybossa.model import db
from pybossa.model.blogpost import Blogpost
from . import BaseFactory, factory


class BlogpostFactory(BaseFactory):
    FACTORY_FOR = Blogpost

    id = factory.Sequence(lambda n: n)
    title = u'Blogpost title'
    body = u'Blogpost body text'
    app = factory.SubFactory('factories.AppFactory')
    app_id = factory.LazyAttribute(lambda blogpost: blogpost.app.id)
    owner = factory.SelfAttribute('app.owner')
    user_id = factory.LazyAttribute(
        lambda blogpost: blogpost.owner.id if blogpost.owner else None)

Fix for nullable author in blogpost factory
Fix for nullable author in blogpost factory

  
  from pybossa.model import db
  from pybossa.model.blogpost import Blogpost
  from . import BaseFactory, factory
  
  
  class BlogpostFactory(BaseFactory):
      FACTORY_FOR = Blogpost
  
      id = factory.Sequence(lambda n: n)
      title = u'Blogpost title'
      body = u'Blogpost body text'
      app = factory.SubFactory('factories.AppFactory')
      app_id = factory.LazyAttribute(lambda blogpost: blogpost.app.id)
      owner = factory.SelfAttribute('app.owner')
-     user_id = factory.LazyAttribute(lambda blogpost: blogpost.owner.id)
+     user_id = factory.LazyAttribute(
+         lambda blogpost: blogpost.owner.id if blogpost.owner else None)
  
Fix for nullable author in blogpost factory
## Code Before:

from pybossa.model import db
from pybossa.model.blogpost import Blogpost
from . import BaseFactory, factory


class BlogpostFactory(BaseFactory):
    FACTORY_FOR = Blogpost

    id = factory.Sequence(lambda n: n)
    title = u'Blogpost title'
    body = u'Blogpost body text'
    app = factory.SubFactory('factories.AppFactory')
    app_id = factory.LazyAttribute(lambda blogpost: blogpost.app.id)
    owner = factory.SelfAttribute('app.owner')
    user_id = factory.LazyAttribute(lambda blogpost: blogpost.owner.id)

## Instruction:
Fix for nullable author in blogpost factory
## Code After:

from pybossa.model import db
from pybossa.model.blogpost import Blogpost
from . import BaseFactory, factory


class BlogpostFactory(BaseFactory):
    FACTORY_FOR = Blogpost

    id = factory.Sequence(lambda n: n)
    title = u'Blogpost title'
    body = u'Blogpost body text'
    app = factory.SubFactory('factories.AppFactory')
    app_id = factory.LazyAttribute(lambda blogpost: blogpost.app.id)
    owner = factory.SelfAttribute('app.owner')
    user_id = factory.LazyAttribute(
        lambda blogpost: blogpost.owner.id if blogpost.owner else None)
