def test_filters_for_user_are_saved():
    config = Config(string=IdMaintainerTest.CONFIG_WITH_FILTERS)
    id_watch = IdMaintainer(":memory:")
    filter = {'fish': 'cat'}
    hunter = WebHunter(config, id_watch)
    hunter.set_filters_for_user(123, filter)
    assert hunter.get_filters_for_user(123) == filter
def test_all_filters_can_be_loaded(id_watch):
    filter = { 'fish': 'cat' }
    config = Config(string=CONFIG_WITH_FILTERS)
    hunter = WebHunter(config, id_watch)
    hunter.set_filters_for_user(123, filter)
    hunter.set_filters_for_user(124, filter)
    assert id_watch.get_user_settings() == [ (123, { 'filters': filter }), (124, { 'filters': filter }) ]
def test_all_filters_can_be_loaded():
    config = Config(string=IdMaintainerTest.CONFIG_WITH_FILTERS)
    id_watch = IdMaintainer(":memory:")
    filter = {'fish': 'cat'}
    hunter = WebHunter(config, id_watch)
    hunter.set_filters_for_user(123, filter)
    hunter.set_filters_for_user(124, filter)
    assert id_watch.get_user_settings() == [(123, {
        'filters': filter
    }), (124, {
        'filters': filter
    })]
예제 #4
0
def hunt_client():
    app.config['TESTING'] = True
    with tempfile.NamedTemporaryFile(mode='w+') as temp_db:
        config = Config(string=DUMMY_CONFIG)
        config.set_searchers([DummyCrawler()])
        app.config['HUNTER'] = WebHunter(config, IdMaintainer(temp_db.name))
        app.config['BOT_TOKEN'] = "1234xxx.12345"
        app.secret_key = b'test_session_key'

        with app.test_client() as hunt_client:
            yield hunt_client
예제 #5
0
from flathunter.idmaintainer import IdMaintainer
from flathunter.googlecloud_idmaintainer import GoogleCloudIdMaintainer
from flathunter.web_hunter import WebHunter
from flathunter.config import Config

from flathunter.web import app

config = Config()

if __name__ == '__main__':
    # Use the SQLite DB file if we are running locally
    id_watch = IdMaintainer('%s/processed_ids.db' % config.database_location())
else:
    # Use Google Cloud DB if we run on the cloud
    id_watch = GoogleCloudIdMaintainer()

hunter = WebHunter(config, id_watch)

app.config["HUNTER"] = hunter
if 'website' in config:
    app.secret_key = config['website']['session_key']
    app.config["DOMAIN"] = config['website']['domain']
    app.config["BOT_NAME"] = config['website']['bot_name']
else:
    app.secret_key = b'Not a secret'
app.config["BOT_TOKEN"] = config['telegram']['bot_token']

if __name__ == '__main__':
    listen = config['website']['listen']
    app.run(host=listen['host'], port=listen['port'], debug=True)
def test_filters_for_user_are_saved(id_watch):
    filter = { 'fish': 'cat' }
    config = Config(string=CONFIG_WITH_FILTERS)
    hunter = WebHunter(config, id_watch)
    hunter.set_filters_for_user(123, filter)
    assert hunter.get_filters_for_user(123) == filter
def test_filters_for_user_returns_none_if_none_present(id_watch):
    config = Config(string=CONFIG_WITH_FILTERS)
    hunter = WebHunter(config, id_watch)
    assert hunter.get_filters_for_user(123) == None
    assert hunter.get_filters_for_user(None) == None