def test_get_module_name(): module_name ="mail" m = get_module_full_name(module_name) assert m == "superform.plugins.mail" module_name ="" m = get_module_full_name(module_name) assert m is None
def rss_feed(channel_id): # SQLAlchemy wants datetime objects (not date) when comparing db.DateTime objects, # so we convert today's date to a datetime object. now = datetime(*date.today().timetuple()[:3]) if channel_id: publishings = db.session.query(Publishing).filter( Publishing.channel_id == channel_id, Publishing.channel.has(module=get_module_full_name('rss')), Publishing.state == 1, # validated/shared Publishing.date_from <= now, now <= Publishing.date_until, ).all() else: publishings = db.session.query(Publishing).filter( Publishing.channel.has(module=get_module_full_name('rss')), Publishing.state == 1, # validated/shared Publishing.date_from <= now, now <= Publishing.date_until, ).all() feed = FeedGenerator() feed.title('Superform') feed.link(href='http://localhost:5000') feed.description('Superform') for publishing in publishings: entry = feed.add_entry() entry.title(publishing.title) entry.description(publishing.description) entry.link(href=publishing.link_url) return feed.rss_str(pretty=True)
def channel_list(): if request.method == "POST": action = request.form.get('@action', '') if action == "new": name = request.form.get('name') module = request.form.get('module') if module in get_modules_names( current_app.config["PLUGINS"].keys()): channel = Channel(name = name, module = get_module_full_name(module), config = "{}") db.session.add(channel) db.session.commit() elif action == "delete": channel_id = request.form.get("id") channel = Channel.query.get(channel_id) if channel: db.session.delete(channel) db.session.commit() elif action == "edit": channel_id = request.form.get("id") channel = Channel.query.get(channel_id) name = request.form.get('name') channel.name = name db.session.commit() channels = Channel.query.all() return render_template("channels.html", channels = channels, modules = get_modules_names( current_app.config["PLUGINS"].keys()))
def add_channel(channel_name, module, config): channel = Channel() channel.name = channel_name channel.module = get_module_full_name(module) channel.config = config db.session.add(channel) db.session.commit()
def test_get_module_rss(): """ Tests if the module rss is active :return: """ module_name = "rss" m = get_module_full_name(module_name) assert m == "superform.plugins.rss"
def test_get_module_ictv(): """ Tests if the module ictv is active :return: """ with app.app_context(): module_name = "ictv" m = get_module_full_name(module_name) assert m == "superform.plugins.ictv"
def get_post_form_validations(): mods = get_modules_names(current_app.config["PLUGINS"].keys()) post_form_validations = dict() for m in mods: full_name = get_module_full_name(m) clas = get_instance_from_module_path(full_name) fields = clas.POST_FORM_VALIDATIONS post_form_validations[m] = fields return post_form_validations
def test_get_moderate_channels_for_user(): u = User.query.get(1) channel = Channel(name="test", module=get_module_full_name("mail"), config="{}") db.session.add(channel) assert get_moderate_channels_for_user(u) is not None user = User(id=2, name="test", first_name="utilisateur2", email="*****@*****.**") db.session.add(user) assert len(get_moderate_channels_for_user(user)) == 0 a = Authorization(channel_id=1, user_id=2, permission=2) db.session.add(a) assert len(get_moderate_channels_for_user(user)) == 1
def test_search_post_valid_login(client) : login(client, "myself") channel = Channel(name="testTwitter", module=get_module_full_name("TestTwitter"), config="{}") db.session.add(channel) r = requests.post("http://127.0.0.1:5000/search_post", { "subject": "", "body": "", "sorted": "" }) assert int(r.status_code) == 200
def test_search_unlogged_client_publishing_search(client): user = User(id=6, name="test", first_name="utilisateur", email="*****@*****.**") db.session.add(user) channel = Channel(name="test", module=get_module_full_name("TestTwitter"), config="{}") db.session.add(channel) a = Authorization(channel_id=1, user_id=6, permission=2) db.session.add(a) r = requests.post("http://127.0.0.1:5000/search_publishings", { "subject": "", "body": "", "author": "", "channels": "test" }) assert int(r.status_code) == 403
def test_not_moderator(client) : user = User(id=1, name="test", first_name="utilisateur", email="*****@*****.**") db.session.add(user) channel = Channel(name="test", module=get_module_full_name("TestTwitter"), config="{}") db.session.add(channel) login(client, 1) r = requests.post("http://127.0.0.1:5000/search_publishings", { "subject": "", "body": "", "author": "", "channels": "test" }) assert r.status_code == 403
def test_logged_but_not_moderator(client) : login(client, "myself") rv2 = client.get('/', follow_redirects=True) assert rv2.status_code == 200 assert "Your are not logged in." not in rv2.data.decode() channel = Channel(name="test", module=get_module_full_name("TestTwitter"), config="{}") db.session.add(channel) filter = {} filter["subject"] = " " filter["sorted"] = "id" filter["body"] = " " headers ={} headers["Content-Type"] = "application/json" headers["Data-Type"] = "json" headers["Accept"] = "application/json" r = requests.post("http://127.0.0.1:5000/search_post",headers=headers, data=json.dumps(filter)) assert r.status_code==200
def channel_list(): if request.method == "POST": action = request.form.get('@action', '') if action == "new": name = request.form.get('name') module = request.form.get('module') if module in get_modules_names( current_app.config["PLUGINS"].keys()): channel = Channel(name=name, module=get_module_full_name(module), config="{}", archival_frequency=DEFAULT_FREQUENCY, archival_date=DEFAULT_DATE) db.session.add(channel) db.session.commit() # Archival Module : configure_job(channel.id, DEFAULT_FREQUENCY, DEFAULT_DATE) # End of Archival Module elif action == "delete": channel_id = request.form.get("id") channel = Channel.query.get(channel_id) if channel: db.session.delete(channel) db.session.commit() # Archival Module : delete_job(channel_id) # End of Archival Module elif action == "edit": channel_id = request.form.get("id") channel = Channel.query.get(channel_id) name = request.form.get('name') channel.name = name db.session.commit() channels = Channel.query.all() return render_template("channels.html", channels=channels, modules=get_modules_names( current_app.config["PLUGINS"].keys()))
def channel_list(): if request.method == "POST": action = request.form.get('@action', '') if action == "new": name = request.form.get('name') username = request.form.get('username') password = request.form.get('password') module = request.form.get('module') if module in get_modules_names(current_app.config["PLUGINS"].keys()): channel = Channel(name=name, module=get_module_full_name(module), config="{}") db.session.add(channel) db.session.flush() db.session.commit() elif action == "delete": channel_id = request.form.get("id") channel = Channel.query.get(channel_id) if channel: db.session.delete(channel) db.session.commit() elif action == "edit": channel_id = request.form.get("id") channel = Channel.query.get(channel_id) name = request.form.get('name') username = request.form.get('username') password = request.form.get('password') if name is not '': channel.name = name conf = json.loads(channel.config) conf["channel_name"] = name channel.config = json.dumps(conf) db.session.commit() channels = Channel.query.all() mods = get_modules_names(current_app.config["PLUGINS"].keys()) auth_fields = dict() return render_template("channels.html", channels=channels, modules=get_modules_names(current_app.config["PLUGINS"].keys()), auth_fields=auth_fields)
def test_edit_new_publishing(client): login(client, "myself") channel = Channel(id=0, name="test", module=get_module_full_name("mail"), config="{}") db.session.add(channel) a = Authorization(channel_id=channel.id, user_id="myself", permission=1) db.session.add(a) db.session.commit() datadict = dict(titlepost='A new test post', descriptionpost="A description", linkurlpost="http://www.test.com", imagepost="image.jpg", datefrompost="2018-07-01", dateuntilpost="2018-07-01") datadict[str(channel.name) + '_titlepost'] = "mail title" datadict[str(channel.name) + '_descriptionpost'] = 'mail description' datadict[str(channel.name) + '_linkurlpost'] = "http://www.test.com" datadict[str(channel.name) + '_imagepost'] = "image.jpg" datadict[str(channel.name) + '_datefrompost'] = "2018-07-01" datadict[str(channel.name) + '_dateuntilpost'] = "2018-07-01" rv = client.post('/new', data=datadict) assert rv.status_code == 302 posts = db.session.query(Post).all() last_add = posts[-1] url = '/edit/publish_edit_post/' + str(last_add.id) datadict2 = dict(title='An edited test post', description="A description", link_url="http://www.test.com", image="image.jpg", date_from="2018-07-01", date_until="2018-07-01") datadict3 = dict(title='mail title', description='edited mail description', date_from="2018-07-01", date_until="2018-07-01") rv = client.post(url, data=json.dumps([{ "name": "General", "fields": datadict2 }, { "name": "test", "fields": datadict3 }])) assert rv.status_code == 200 edited_posts = db.session.query(Post).all() assert len(posts) == len(edited_posts) edited_post = edited_posts[-1] assert edited_post.title == 'An edited test post' assert last_add.id == edited_post.id assert edited_post.description == "A description" edited_publishing = db.session.query(Publishing).filter( Publishing.post_id == last_add.id) assert edited_publishing[0].title == "mail title" assert edited_publishing[0].description == "edited mail description" # cleaning up db.session.query(Post).filter(Post.id == last_add.id).delete() db.session.query(Publishing).filter( Publishing.post_id == last_add.id).delete() db.session.delete(a) db.session.delete(channel) db.session.commit()
def channel_list(): if request.method == "POST": action = request.form.get('@action', '') if action == "new": name = request.form.get('name') username = request.form.get('username') password = request.form.get('password') module = request.form.get('module') if module in get_modules_names( current_app.config["PLUGINS"].keys()): channel = Channel(name=name, module=get_module_full_name(module), config="{}") db.session.add(channel) db.session.flush() keepass.set_entry_from_data(str(channel.id), username, password) keepass.add_entry_in_group(module) db.session.commit() elif action == "delete": channel_id = request.form.get("id") channel = Channel.query.get(channel_id) if channel: db.session.delete(channel) db.session.commit() keepass.delete_entry(channel_id) elif action == "edit": channel_id = request.form.get("id") channel = Channel.query.get(channel_id) name = request.form.get('name') username = request.form.get('username') password = request.form.get('password') if name is not '': channel.name = name conf = json.loads(channel.config) conf["channel_name"] = name channel.config = json.dumps(conf) db.session.commit() if username is not '' or password is not '': keepass.set_entry_from_data(str(channel.id), username, password) keepass.modify_entry_in_group( get_modules_names([channel.module])[0], channel.id) channels = Channel.query.all() mods = get_modules_names(current_app.config["PLUGINS"].keys()) auth_fields = dict() for m in mods: full_name = get_module_full_name(m) clas = get_instance_from_module_path(full_name) fields = clas.AUTH_FIELDS auth_fields[m] = fields return render_template("channels.html", channels=channels, modules=get_modules_names( current_app.config["PLUGINS"].keys()), auth_fields=auth_fields)
def create_channel(name, module, config): channel = Channel(name=name, module=get_module_full_name(module), config=json.dumps(config)) write_to_db(channel) return channel