Beispiel #1
0
def setup_repositories(app):
    """Setup repositories."""
    from pybossa.repositories import UserRepository
    from pybossa.repositories import ProjectRepository
    from pybossa.repositories import ProjectStatsRepository
    from pybossa.repositories import AnnouncementRepository
    from pybossa.repositories import BlogRepository
    from pybossa.repositories import TaskRepository
    from pybossa.repositories import AuditlogRepository
    from pybossa.repositories import WebhookRepository
    from pybossa.repositories import ResultRepository
    from pybossa.repositories import HelpingMaterialRepository
    global user_repo
    global project_repo
    global project_stats_repo
    global announcement_repo
    global blog_repo
    global task_repo
    global auditlog_repo
    global webhook_repo
    global result_repo
    global helping_repo
    language = app.config.get('FULLTEXTSEARCH_LANGUAGE')
    user_repo = UserRepository(db)
    project_repo = ProjectRepository(db)
    project_stats_repo = ProjectStatsRepository(db)
    announcement_repo = AnnouncementRepository(db)
    blog_repo = BlogRepository(db)
    task_repo = TaskRepository(db, language)
    auditlog_repo = AuditlogRepository(db)
    webhook_repo = WebhookRepository(db)
    result_repo = ResultRepository(db)
    helping_repo = HelpingMaterialRepository(db)
Beispiel #2
0
def setup_repositories(app):
    """Setup repositories."""
    from pybossa.repositories import UserRepository
    from pybossa.repositories import ProjectRepository
    from pybossa.repositories import ProjectStatsRepository
    from pybossa.repositories import AnnouncementRepository
    from pybossa.repositories import BlogRepository
    from pybossa.repositories import TaskRepository
    from pybossa.repositories import AuditlogRepository
    from pybossa.repositories import WebhookRepository
    from pybossa.repositories import ResultRepository
    from pybossa.repositories import HelpingMaterialRepository
    from pybossa.repositories import PerformanceStatsRepository
    global user_repo
    global project_repo
    global project_stats_repo
    global announcement_repo
    global blog_repo
    global task_repo
    global auditlog_repo
    global webhook_repo
    global result_repo
    global helping_repo
    global performance_stats_repo
    language = app.config.get('FULLTEXTSEARCH_LANGUAGE')
    rdancy_upd_exp = app.config.get('REDUNDANCY_UPDATE_EXPIRATION', 30)
    user_repo = UserRepository(db)
    project_repo = ProjectRepository(db)
    project_stats_repo = ProjectStatsRepository(db)
    announcement_repo = AnnouncementRepository(db)
    blog_repo = BlogRepository(db)
    task_repo = TaskRepository(db, language, rdancy_upd_exp)
    auditlog_repo = AuditlogRepository(db)
    webhook_repo = WebhookRepository(db)
    result_repo = ResultRepository(db)
    helping_repo = HelpingMaterialRepository(db)
    performance_stats_repo = PerformanceStatsRepository(db)
Beispiel #3
0
 def setUp(self):
     super(TestHelpingMaterialRepository, self).setUp()
     self.helping_repo = HelpingMaterialRepository(db)
Beispiel #4
0
class TestHelpingMaterialRepository(Test):
    def setUp(self):
        super(TestHelpingMaterialRepository, self).setUp()
        self.helping_repo = HelpingMaterialRepository(db)

    @with_context
    def test_get_return_none_if_no_helpingmaterial(self):
        """Test get method returns None if there is no helpingmaterial with the
        specified id"""

        helpingmaterial = self.helping_repo.get(2)

        assert helpingmaterial is None, helpingmaterial

    @with_context
    def test_get_returns_helpingmaterial(self):
        """Test get method returns a helpingmaterial if exists"""

        helpingmaterial = HelpingMaterialFactory.create()

        retrieved_helpingmaterial = self.helping_repo.get(helpingmaterial.id)

        assert helpingmaterial == retrieved_helpingmaterial, retrieved_helpingmaterial

    @with_context
    def test_get_by(self):
        """Test get_by returns a helpingmaterial with the specified attribute"""

        helpingmaterial = HelpingMaterialFactory.create(media_url="algo")

        retrieved_helpingmaterial = self.helping_repo.get_by(media_url="algo")

        assert helpingmaterial == retrieved_helpingmaterial, retrieved_helpingmaterial

    @with_context
    def test_get_by_returns_none_if_no_helpingmaterial(self):
        """Test get_by returns None if no helpingmaterial matches the query"""

        HelpingMaterialFactory.create()

        helpingmaterial = self.helping_repo.get_by(project_id=10000)

        assert helpingmaterial is None, helpingmaterial

    @with_context
    def test_filter_by_no_matches(self):
        """Test filter_by returns an empty list if no helpingmaterials match the query"""

        HelpingMaterialFactory.create()

        retrieved_helpingmaterials = self.helping_repo.filter_by(
            project_id=100)

        assert isinstance(retrieved_helpingmaterials, list)
        assert len(retrieved_helpingmaterials) == 0, retrieved_helpingmaterials

    @with_context
    def test_filter_by_one_condition(self):
        """Test filter_by returns a list of helpingmaterials that meet the filtering
        condition"""

        HelpingMaterialFactory.create_batch(3, media_url="algo")
        should_be_missing = HelpingMaterialFactory.create(media_url="new")

        retrieved_helpingmaterials = self.helping_repo.filter_by(
            media_url="algo")

        assert len(retrieved_helpingmaterials) == 3, retrieved_helpingmaterials
        assert should_be_missing not in retrieved_helpingmaterials, retrieved_helpingmaterials

    @with_context
    def test_filter_by_limit_offset(self):
        """Test that filter_by supports limit and offset options"""

        HelpingMaterialFactory.create_batch(4)
        all_helpingmaterials = self.helping_repo.filter_by()

        first_two = self.helping_repo.filter_by(limit=2)
        last_two = self.helping_repo.filter_by(limit=2, offset=2)

        assert len(first_two) == 2, first_two
        assert len(last_two) == 2, last_two
        assert first_two == all_helpingmaterials[:2]
        assert last_two == all_helpingmaterials[2:]

    @with_context
    def test_filter_by_multiple_conditions(self):
        """Test filter_by supports multiple-condition queries"""

        h1 = HelpingMaterialFactory.create(media_url='url')
        h2 = HelpingMaterialFactory.create(media_url='url')

        retrieved_helpingmaterials = self.helping_repo.filter_by(
            project_id=h2.project_id, media_url='url')

        assert len(retrieved_helpingmaterials) == 1, retrieved_helpingmaterials
        assert h2 in retrieved_helpingmaterials, retrieved_helpingmaterials

    @with_context
    def test_save(self):
        """Test save persist the helpingmaterial"""

        helpingmaterial = HelpingMaterialFactory.build()
        project = ProjectFactory.create()
        helpingmaterial.project_id = project.id
        assert self.helping_repo.get(helpingmaterial.id) is None

        self.helping_repo.save(helpingmaterial)

        assert self.helping_repo.get(
            helpingmaterial.id
        ) == helpingmaterial, "Helping material not saved"

    @with_context
    def test_save_fails_if_integrity_error(self):
        """Test save raises a DBIntegrityError if the instance to be saved lacks
        a required value"""

        helpingmaterial = HelpingMaterialFactory.build(project_id=None)

        assert_raises(DBIntegrityError, self.helping_repo.save,
                      helpingmaterial)

    @with_context
    def test_save_only_saves_helpingmaterials(self):
        """Test save raises a WrongObjectError when an object which is not
        a Blogpost instance is saved"""

        bad_object = dict()

        assert_raises(WrongObjectError, self.helping_repo.save, bad_object)

    @with_context
    def test_update(self):
        """Test update persists the changes made to the helpingmaterial"""

        info = {'key': 'val'}
        helpingmaterial = HelpingMaterialFactory.create(info=info)
        info_new = {'f': 'v'}
        helpingmaterial.info = info_new

        self.helping_repo.update(helpingmaterial)
        updated_helpingmaterial = self.helping_repo.get(helpingmaterial.id)

        assert updated_helpingmaterial.info == info_new, updated_helpingmaterial

    @with_context
    def test_update_fails_if_integrity_error(self):
        """Test update raises a DBIntegrityError if the instance to be updated
        lacks a required value"""

        helpingmaterial = HelpingMaterialFactory.create()
        helpingmaterial.project_id = None

        assert_raises(DBIntegrityError, self.helping_repo.update,
                      helpingmaterial)

    @with_context
    def test_update_only_updates_helpingmaterials(self):
        """Test update raises a WrongObjectError when an object which is not
        a HelpingMaterial instance is updated"""

        bad_object = dict()

        assert_raises(WrongObjectError, self.helping_repo.update, bad_object)

    @with_context
    def test_delete(self):
        """Test delete removes the helpingmaterial instance"""

        helpingmaterial = HelpingMaterialFactory.create()

        self.helping_repo.delete(helpingmaterial)
        deleted = self.helping_repo.get(helpingmaterial.id)

        assert deleted is None, deleted

    @with_context
    def test_delete_only_deletes_helpingmaterials(self):
        """Test delete raises a WrongObjectError if is requested to delete other
        than a helpingmaterial"""

        bad_object = dict()

        assert_raises(WrongObjectError, self.helping_repo.delete, bad_object)
 def setUp(self):
     super(TestHelpingMaterialRepository, self).setUp()
     self.helping_repo = HelpingMaterialRepository(db)
class TestHelpingMaterialRepository(Test):

    def setUp(self):
        super(TestHelpingMaterialRepository, self).setUp()
        self.helping_repo = HelpingMaterialRepository(db)

    @with_context
    def test_get_return_none_if_no_helpingmaterial(self):
        """Test get method returns None if there is no helpingmaterial with the
        specified id"""

        helpingmaterial = self.helping_repo.get(2)

        assert helpingmaterial is None, helpingmaterial


    @with_context
    def test_get_returns_helpingmaterial(self):
        """Test get method returns a helpingmaterial if exists"""

        helpingmaterial = HelpingMaterialFactory.create()

        retrieved_helpingmaterial = self.helping_repo.get(helpingmaterial.id)

        assert helpingmaterial == retrieved_helpingmaterial, retrieved_helpingmaterial


    @with_context
    def test_get_by(self):
        """Test get_by returns a helpingmaterial with the specified attribute"""

        helpingmaterial = HelpingMaterialFactory.create(media_url="algo")

        retrieved_helpingmaterial = self.helping_repo.get_by(media_url="algo")

        assert helpingmaterial == retrieved_helpingmaterial, retrieved_helpingmaterial


    @with_context
    def test_get_by_returns_none_if_no_helpingmaterial(self):
        """Test get_by returns None if no helpingmaterial matches the query"""

        HelpingMaterialFactory.create()

        helpingmaterial = self.helping_repo.get_by(project_id=10000)

        assert helpingmaterial is None, helpingmaterial


    @with_context
    def test_filter_by_no_matches(self):
        """Test filter_by returns an empty list if no helpingmaterials match the query"""

        HelpingMaterialFactory.create()

        retrieved_helpingmaterials = self.helping_repo.filter_by(project_id=100)

        assert isinstance(retrieved_helpingmaterials, list)
        assert len(retrieved_helpingmaterials) == 0, retrieved_helpingmaterials


    @with_context
    def test_filter_by_one_condition(self):
        """Test filter_by returns a list of helpingmaterials that meet the filtering
        condition"""

        HelpingMaterialFactory.create_batch(3, media_url="algo")
        should_be_missing = HelpingMaterialFactory.create(media_url="new")

        retrieved_helpingmaterials = self.helping_repo.filter_by(media_url="algo")

        assert len(retrieved_helpingmaterials) == 3, retrieved_helpingmaterials
        assert should_be_missing not in retrieved_helpingmaterials, retrieved_helpingmaterials


    @with_context
    def test_filter_by_limit_offset(self):
        """Test that filter_by supports limit and offset options"""

        HelpingMaterialFactory.create_batch(4)
        all_helpingmaterials = self.helping_repo.filter_by()

        first_two = self.helping_repo.filter_by(limit=2)
        last_two = self.helping_repo.filter_by(limit=2, offset=2)

        assert len(first_two) == 2, first_two
        assert len(last_two) == 2, last_two
        assert first_two == all_helpingmaterials[:2]
        assert last_two == all_helpingmaterials[2:]


    @with_context
    def test_filter_by_multiple_conditions(self):
        """Test filter_by supports multiple-condition queries"""

        h1 = HelpingMaterialFactory.create(media_url='url')
        h2 = HelpingMaterialFactory.create(media_url='url')

        retrieved_helpingmaterials = self.helping_repo.filter_by(project_id=h2.project_id,
                                                                 media_url='url')

        assert len(retrieved_helpingmaterials) == 1, retrieved_helpingmaterials
        assert h2 in retrieved_helpingmaterials, retrieved_helpingmaterials


    @with_context
    def test_save(self):
        """Test save persist the helpingmaterial"""

        helpingmaterial = HelpingMaterialFactory.build()
        project = ProjectFactory.create()
        helpingmaterial.project_id = project.id
        assert self.helping_repo.get(helpingmaterial.id) is None

        self.helping_repo.save(helpingmaterial)

        assert self.helping_repo.get(helpingmaterial.id) == helpingmaterial, "Helping material not saved"


    @with_context
    def test_save_fails_if_integrity_error(self):
        """Test save raises a DBIntegrityError if the instance to be saved lacks
        a required value"""

        helpingmaterial = HelpingMaterialFactory.build(project_id=None)

        assert_raises(DBIntegrityError, self.helping_repo.save, helpingmaterial)


    @with_context
    def test_save_only_saves_helpingmaterials(self):
        """Test save raises a WrongObjectError when an object which is not
        a Blogpost instance is saved"""

        bad_object = dict()

        assert_raises(WrongObjectError, self.helping_repo.save, bad_object)


    @with_context
    def test_update(self):
        """Test update persists the changes made to the helpingmaterial"""

        info = {'key': 'val'}
        helpingmaterial = HelpingMaterialFactory.create(info=info)
        info_new = {'f': 'v'}
        helpingmaterial.info = info_new

        self.helping_repo.update(helpingmaterial)
        updated_helpingmaterial = self.helping_repo.get(helpingmaterial.id)

        assert updated_helpingmaterial.info == info_new, updated_helpingmaterial


    @with_context
    def test_update_fails_if_integrity_error(self):
        """Test update raises a DBIntegrityError if the instance to be updated
        lacks a required value"""

        helpingmaterial = HelpingMaterialFactory.create()
        helpingmaterial.project_id = None

        assert_raises(DBIntegrityError, self.helping_repo.update, helpingmaterial)


    @with_context
    def test_update_only_updates_helpingmaterials(self):
        """Test update raises a WrongObjectError when an object which is not
        a HelpingMaterial instance is updated"""

        bad_object = dict()

        assert_raises(WrongObjectError, self.helping_repo.update, bad_object)


    @with_context
    def test_delete(self):
        """Test delete removes the helpingmaterial instance"""

        helpingmaterial = HelpingMaterialFactory.create()

        self.helping_repo.delete(helpingmaterial)
        deleted = self.helping_repo.get(helpingmaterial.id)

        assert deleted is None, deleted


    @with_context
    def test_delete_only_deletes_helpingmaterials(self):
        """Test delete raises a WrongObjectError if is requested to delete other
        than a helpingmaterial"""

        bad_object = dict()

        assert_raises(WrongObjectError, self.helping_repo.delete, bad_object)
Beispiel #7
0
from pybossa.repositories import AnnouncementRepository
from pybossa.repositories import BlogRepository
from pybossa.repositories import TaskRepository
from pybossa.repositories import AuditlogRepository
from pybossa.repositories import WebhookRepository
from pybossa.repositories import HelpingMaterialRepository
from pybossa.repositories import PageRepository

user_repo = UserRepository(db)
project_repo = ProjectRepository(db)
announcement_repo = AnnouncementRepository(db)
blog_repo = BlogRepository(db)
task_repo = TaskRepository(db)
auditlog_repo = AuditlogRepository(db)
webhook_repo = WebhookRepository(db)
helping_repo = HelpingMaterialRepository(db)
page_repo = PageRepository(db)


def reset_all_pk_sequences():
    ProjectFactory.reset_sequence()
    AnnouncementFactory.reset_sequence()
    BlogpostFactory.reset_sequence()
    CategoryFactory.reset_sequence()
    TaskFactory.reset_sequence()
    TaskRunFactory.reset_sequence()
    UserFactory.reset_sequence()
    AuditlogFactory.reset_sequence()
    WebhookFactory.reset_sequence()
    HelpingMaterialFactory.reset_sequence()
    PageFactory.reset_sequence()