class TestWebhookRepository(Test): payload = dict(foo='bar') def setUp(self): super(TestWebhookRepository, self).setUp() self.webhook_repo = WebhookRepository(db) TaskRunFactory.create() webhook = Webhook(project_id=1, payload=self.payload) self.webhook_repo.save(webhook) def test_get_return_none_if_no_webhook(self): """Test get method returns None if there is no log with the specified id.""" assert self.webhook_repo.get(2) is None def test_get_return_obj(self): """Test get method returns obj.""" tmp = self.webhook_repo.get(1) assert tmp.id == 1 assert tmp.project_id == 1 def test_get_by_return_obj(self): """Test get_by method returns obj.""" tmp = self.webhook_repo.get_by(project_id=1) assert tmp.id == 1 assert tmp.project_id == 1 def test_filter_by_return_obj(self): """Test filter_by method returns obj.""" tmp = self.webhook_repo.filter_by(project_id=1) assert len(tmp) == 1 tmp = tmp[0] assert tmp.id == 1 assert tmp.project_id == 1 tmp = self.webhook_repo.filter_by(limit=1, offset=1, project_id=1) assert len(tmp) == 0 def test_save(self): """Test save.""" webhook = self.webhook_repo.get(1) assert webhook.id == 1 def test_save_fails_if_integrity_error(self): """Test save raises a DBIntegrityError if the instance to be saved lacks a required value""" wh = Webhook(project_id=None) assert_raises(DBIntegrityError, self.webhook_repo.save, wh) def test_save_only_saves_webhooks(self): """Test save raises a WrongObjectError when an object which is not a Webhok instance is saved""" bad_object = dict() assert_raises(WrongObjectError, self.webhook_repo.save, bad_object)
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)
def setup_repositories(): """Setup repositories.""" from pybossa.repositories import UserRepository from pybossa.repositories import ProjectRepository 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 UserScoreRepository global user_repo global project_repo global blog_repo global task_repo global auditlog_repo global webhook_repo global result_repo global user_score_repo user_repo = UserRepository(db) project_repo = ProjectRepository(db) blog_repo = BlogRepository(db) task_repo = TaskRepository(db) auditlog_repo = AuditlogRepository(db) webhook_repo = WebhookRepository(db) result_repo = ResultRepository(db) user_score_repo = UserScoreRepository(db)
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)
from pybossa.core import db import factory from pybossa.repositories import UserRepository from pybossa.repositories import ProjectRepository from pybossa.repositories import BlogRepository from pybossa.repositories import TaskRepository from pybossa.repositories import AuditlogRepository from pybossa.repositories import WebhookRepository user_repo = UserRepository(db) project_repo = ProjectRepository(db) blog_repo = BlogRepository(db) task_repo = TaskRepository(db) auditlog_repo = AuditlogRepository(db) webhook_repo = WebhookRepository(db) def reset_all_pk_sequences(): ProjectFactory.reset_sequence() BlogpostFactory.reset_sequence() CategoryFactory.reset_sequence() TaskFactory.reset_sequence() TaskRunFactory.reset_sequence() UserFactory.reset_sequence() AuditlogFactory.reset_sequence() WebhookFactory.reset_sequence() class BaseFactory(factory.Factory): @classmethod
def setUp(self): super(TestWebhookRepository, self).setUp() self.webhook_repo = WebhookRepository(db) TaskRunFactory.create() webhook = Webhook(project_id=1, payload=self.payload) self.webhook_repo.save(webhook)
class TestWebhookRepository(Test): payload = dict(foo='bar') @with_context def setUp(self): super(TestWebhookRepository, self).setUp() self.webhook_repo = WebhookRepository(db) TaskRunFactory.create() webhook = Webhook(project_id=1, payload=self.payload) self.webhook_repo.save(webhook) @with_context def test_get_return_none_if_no_webhook(self): """Test get method returns None if there is no log with the specified id.""" assert self.webhook_repo.get(2) is None @with_context def test_get_return_obj(self): """Test get method returns obj.""" tmp = self.webhook_repo.get(1) assert tmp.id == 1 assert tmp.project_id == 1 @with_context def test_get_by_return_obj(self): """Test get_by method returns obj.""" tmp = self.webhook_repo.get_by(project_id=1) assert tmp.id == 1 assert tmp.project_id == 1 @with_context def test_filter_by_return_obj(self): """Test filter_by method returns obj.""" tmp = self.webhook_repo.filter_by(project_id=1) assert len(tmp) == 1 tmp = tmp[0] assert tmp.id == 1 assert tmp.project_id == 1 tmp = self.webhook_repo.filter_by(limit=1, offset=1, project_id=1) assert len(tmp) == 0 @with_context def test_save(self): """Test save.""" webhook = self.webhook_repo.get(1) assert webhook.id == 1 @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""" wh = Webhook(project_id=None) assert_raises(DBIntegrityError, self.webhook_repo.save, wh) @with_context def test_save_only_saves_webhooks(self): """Test save raises a WrongObjectError when an object which is not a Webhok instance is saved""" bad_object = dict() assert_raises(WrongObjectError, self.webhook_repo.save, bad_object) @with_context @patch('pybossa.repositories.webhook_repository.clean_project') def test_delete_entries_from_project(self, clean_project_mock): """Test delete entries from project works.""" project = ProjectFactory.create() wh = Webhook(project_id=project.id) self.webhook_repo.save(wh) self.webhook_repo.delete_entries_from_project(project) res = self.webhook_repo.get_by(project_id=project.id) assert res is None clean_project_mock.assert_called_with(project.id)