# Path: jarr/lib/utils.py
# def utc_now():
#     return datetime.utcnow().replace(tzinfo=timezone.utc)
# 
# Path: jarr/lib/enums.py
# class FeedType(Enum):
#     classic = 'classic'
#     json = 'json'
#     tumblr = 'tumblr'
#     instagram = 'instagram'
#     soundcloud = 'soundcloud'
#     reddit = 'reddit'
#     koreus = 'koreus'
#     twitter = 'twitter'
# 
# Path: jarr/crawler/main.py
# @celery_app.task(name='feed_cleaner')
# @lock('feed-cleaner')
# def feed_cleaner(feed_id):
#     logger.warning("Feed cleaner - start => %s", feed_id)
#     WORKER_BATCH.labels(worker_type='delete').observe(1)
#     fctrl = FeedController()
#     result = fctrl.update({'id': feed_id, 'status': FeedStatus.to_delete},
#                           {'status': FeedStatus.deleting})
#     if not result:
#         logger.error('feed %r seems locked, not doing anything', feed_id)
#         return
#     try:
#         logger.warning("Deleting feed %r", feed_id)
#         fctrl.delete(feed_id)
#     except Exception:
#         logger.exception('something went wrong when deleting feeds %r',
#                          feed_id)
#         fctrl.update({'id': feed_id}, {'status': FeedStatus.to_delete})
#         raise
#     finally:
#         REDIS_CONN.delete(JARR_FEED_DEL_KEY)


from tests.base import JarrFlaskCommon
from datetime import timezone, timedelta
from jarr.lib.utils import utc_now
from jarr.lib.enums import FeedType
from jarr.controllers import FeedController
from jarr.crawler.main import feed_cleaner
        self.assertTrue(feed['cluster_wake_up'])
        self.assertEqual('changed2', feed['title'])
        self.assertEqual(self.valid_filters, feed['filters'])
        # put with no change
        self.jarr_client('put', 'feed', feed_id, data={}, user='user1')
        feed = self.jarr_client('get', 'feed', feed_id, user='user1').json
        self.assertTrue(feed['cluster_wake_up'])
        self.assertEqual('changed2', feed['title'])
        self.assertEqual(self.valid_filters, feed['filters'])
        # put with limited change
        resp = self.jarr_client('put', 'feed', feed_id,
                                data={'title': 'changed again',
                                      'cluster_enabled': False}, user='user1')
        feed = self.jarr_client('get', 'feed', feed_id, user='user1').json
        self.assertTrue(feed['cluster_wake_up'])
        self.assertFalse(feed['cluster_enabled'])
        self.assertEqual('changed again', feed['title'])
        self.assertEqual(self.valid_filters, feed['filters'])
        # changing to other user category
        categories_resp = self.jarr_client('get', 'categories', user='user2')
        self.assertStatusCode(200, categories_resp)
        feed = self.jarr_client('get', 'feed', feed_id, user='user1').json
        category = categories_resp.json[0]
        resp = self.jarr_client('put', 'feed', feed_id, user='user1',
                                data={'category_id': category['id']})
        self.assertStatusCode(403, resp)

    def test_FeedResource_delete(self):
        feed_id = self.jarr_client('get', 'feeds', user='user1').json[0]['id']
        resp = self.jarr_client('delete', 'feed', feed_id)

# Path: jarr/lib/utils.py
# def utc_now():
#     return datetime.utcnow().replace(tzinfo=timezone.utc)
# 
# Path: jarr/lib/enums.py
# class FeedType(Enum):
#     classic = 'classic'
#     json = 'json'
#     tumblr = 'tumblr'
#     instagram = 'instagram'
#     soundcloud = 'soundcloud'
#     reddit = 'reddit'
#     koreus = 'koreus'
#     twitter = 'twitter'
# 
# Path: jarr/crawler/main.py
# @celery_app.task(name='feed_cleaner')
# @lock('feed-cleaner')
# def feed_cleaner(feed_id):
#     logger.warning("Feed cleaner - start => %s", feed_id)
#     WORKER_BATCH.labels(worker_type='delete').observe(1)
#     fctrl = FeedController()
#     result = fctrl.update({'id': feed_id, 'status': FeedStatus.to_delete},
#                           {'status': FeedStatus.deleting})
#     if not result:
#         logger.error('feed %r seems locked, not doing anything', feed_id)
#         return
#     try:
#         logger.warning("Deleting feed %r", feed_id)
#         fctrl.delete(feed_id)
#     except Exception:
#         logger.exception('something went wrong when deleting feeds %r',
#                          feed_id)
#         fctrl.update({'id': feed_id}, {'status': FeedStatus.to_delete})
#         raise
#     finally:
#         REDIS_CONN.delete(JARR_FEED_DEL_KEY)


# Path: tests/api/feed_test.py
from tests.base import JarrFlaskCommon
from datetime import timezone, timedelta
from jarr.lib.utils import utc_now
from jarr.lib.enums import FeedType
from jarr.controllers import FeedController
from jarr.crawler.main import feed_cleaner

        self.assertTrue(feed['cluster_wake_up'])
        self.assertEqual('changed2', feed['title'])
        self.assertEqual(self.valid_filters, feed['filters'])
        # put with no change
        self.jarr_client('put', 'feed', feed_id, data={}, user='user1')
        feed = self.jarr_client('get', 'feed', feed_id, user='user1').json
        self.assertTrue(feed['cluster_wake_up'])
        self.assertEqual('changed2', feed['title'])
        self.assertEqual(self.valid_filters, feed['filters'])
        # put with limited change
        resp = self.jarr_client('put', 'feed', feed_id,
                                data={'title': 'changed again',
                                      'cluster_enabled': False}, user='user1')
        feed = self.jarr_client('get', 'feed', feed_id, user='user1').json
        self.assertTrue(feed['cluster_wake_up'])
        self.assertFalse(feed['cluster_enabled'])
        self.assertEqual('changed again', feed['title'])
        self.assertEqual(self.valid_filters, feed['filters'])
        # changing to other user category
        categories_resp = self.jarr_client('get', 'categories', user='user2')
        self.assertStatusCode(200, categories_resp)
        feed = self.jarr_client('get', 'feed', feed_id, user='user1').json
        category = categories_resp.json[0]
        resp = self.jarr_client('put', 'feed', feed_id, user='user1',
                                data={'category_id': category['id']})
        self.assertStatusCode(403, resp)

    def test_FeedResource_delete(self):
        feed_id = self.jarr_client('get', 'feeds', user='user1').json[0]['id']
        resp = self.jarr_client('delete', 'feed', feed_id)

        self.assertStatusCode(401, resp)