class TestProjectStatsRepository(Test):

    def setUp(self):
        super(TestProjectStatsRepository, self).setUp()
        self.projectstats_repo = ProjectStatsRepository(db)

    def prepare_stats(self, n=1):
      project = ProjectFactory.create()
      TaskFactory.create_batch(n, project=project)
      stats.update_stats(project.id)
      return stats.get_stats(project.id, full=True)

    @with_context
    def test_get_return_none_if_no_stats(self):
        """Test get method returns None if no stats with the specified id"""
        ps = self.projectstats_repo.get(2)
        assert ps is None, ps

    @with_context
    def test_get_returns_stats(self):
        """Test get method returns project stats if they exist"""
        ps = self.prepare_stats()
        retrieved_ps = self.projectstats_repo.get(ps.id)
        assert ps == retrieved_ps, retrieved_ps

    @with_context
    def test_filter_by_no_matches(self):
        """Test filter_by returns an empty list if no stats match the query"""
        ps = self.prepare_stats()
        retrieved_ps = self.projectstats_repo.filter_by(n_tasks=100)
        assert isinstance(retrieved_ps, list)
        assert len(retrieved_ps) == 0, retrieved_ps


    @with_context
    def test_filter_by_one_condition(self):
        """Test filter_by returns a list of logs that meet the filtering
        condition"""
        ps1 = self.prepare_stats(3)
        ps2 = self.prepare_stats(3)
        should_be_missing = self.prepare_stats(5)
        retrieved_ps = self.projectstats_repo.filter_by(n_tasks=3)

        assert len(retrieved_ps) == 2, retrieved_ps
        assert should_be_missing not in retrieved_ps, retrieved_ps


    @with_context
    def test_filter_by_multiple_conditions(self):
        """Test filter_by supports multiple-condition queries"""
        ps1 = self.prepare_stats(3)
        ps2 = self.prepare_stats(5)
        retrieved_ps = self.projectstats_repo.filter_by(project_id=ps1.project_id,
                                                        n_tasks=3)
        assert len(retrieved_ps) == 1, retrieved_ps
        assert ps1 in retrieved_ps, retrieved_ps
Example #2
0
class TestProjectStatsRepository(Test):
    def setUp(self):
        super(TestProjectStatsRepository, self).setUp()
        self.projectstats_repo = ProjectStatsRepository(db)

    def prepare_stats(self, n=1):
        project = ProjectFactory.create()
        TaskFactory.create_batch(n, project=project)
        stats.update_stats(project.id)
        return stats.get_stats(project.id, full=True)

    @with_context
    def test_get_return_none_if_no_stats(self):
        """Test get method returns None if no stats with the specified id"""
        ps = self.projectstats_repo.get(2)
        assert ps is None, ps

    @with_context
    def test_get_returns_stats(self):
        """Test get method returns project stats if they exist"""
        ps = self.prepare_stats()
        retrieved_ps = self.projectstats_repo.get(ps.id)
        assert ps == retrieved_ps, retrieved_ps

    @with_context
    def test_filter_by_no_matches(self):
        """Test filter_by returns an empty list if no stats match the query"""
        ps = self.prepare_stats()
        retrieved_ps = self.projectstats_repo.filter_by(n_tasks=100)
        assert isinstance(retrieved_ps, list)
        assert len(retrieved_ps) == 0, retrieved_ps

    @with_context
    def test_filter_by_one_condition(self):
        """Test filter_by returns a list of logs that meet the filtering
        condition"""
        ps1 = self.prepare_stats(3)
        ps2 = self.prepare_stats(3)
        should_be_missing = self.prepare_stats(5)
        retrieved_ps = self.projectstats_repo.filter_by(n_tasks=3)

        assert len(retrieved_ps) == 2, retrieved_ps
        assert should_be_missing not in retrieved_ps, retrieved_ps

    @with_context
    def test_filter_by_multiple_conditions(self):
        """Test filter_by supports multiple-condition queries"""
        ps1 = self.prepare_stats(3)
        ps2 = self.prepare_stats(5)
        retrieved_ps = self.projectstats_repo.filter_by(
            project_id=ps1.project_id, n_tasks=3)
        assert len(retrieved_ps) == 1, retrieved_ps
        assert ps1 in retrieved_ps, retrieved_ps
Example #3
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)
Example #4
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)
Example #5
0
 def setUp(self):
     super(TestProjectStatsRepository, self).setUp()
     self.projectstats_repo = ProjectStatsRepository(db)
 def setUp(self):
     super(TestProjectStatsRepository, self).setUp()
     self.projectstats_repo = ProjectStatsRepository(db)