Ejemplo n.º 1
0
def test_different_channels():
    """
    Test if when publishing on different channels the posts are added to the right feed
    """

    pub1 = Publishing(title="first title", description="first description feed", link_url="www.google.com", channel_id=-2)
    pub2 = Publishing(title="second title", description="second description feed", link_url="www.google.com", channel_id=-3)

    conf1 = "{\"feed_title\": \"-\", \"feed_description\": \"-\"}"
    conf2 = "{\"feed_title\": \"-\", \"feed_description\": \"-\"}"

    path1 = root + '-2.xml'
    path2 = root + '-3.xml'

    del_file([path1, path2])

    rss.run(pub1, conf1)
    rss.run(pub2, conf2)

    assert Path(path1).exists()
    assert Path(path2).exists()

    assert count(path1) == 1
    assert count(path2) == 1

    assert check_post(pub1, path1)
    assert check_post(pub2, path2)

    del_file([path1, path2])
Ejemplo n.º 2
0
def test_publish_post():
    """
    Test that when adding a new post to a feed it is actually added and added at the top of the feed
    """

    pub = Publishing(title="Voici un super beau titre", description="Avec une super description", link_url="www.facebook.com", date_from="2018-10-25", channel_id=-4)
    conf = "{\"feed_title\": \"-\", \"feed_description\": \"-\"}"

    path = root + "-4.xml"
    rss.run(pub, conf)

    count1 = count(path)

    rss.run(pub, conf)

    assert (count1 < count(path))
    assert check_post(pub, path)

    del_file([path])
Ejemplo n.º 3
0
def test_non_valid_publishing():
    pub = Publishing(link_url="www.facebook.com", date_from="2018-10-25", channel_id=-7)
    conf = "{\"feed_title\": \"-\", \"feed_description\": \"-\"}"

    path = root + "-7.xml"

    response = rss.run(pub, conf)
    assert type(response) is tuple
    assert response[0] == StatusCode.ERROR
    assert response[2] is None

    file = Path(path)
    assert not file.exists()
Ejemplo n.º 4
0
def test_server_reboot():
    """
    Test that when de server reboots it restore the rss feeds with the xml files already existing and add the new item
    to the corresponding feed. Make sure it don't erase the already existing xml file.
    """

    pub = Publishing(title="Voici un super beau titre", description="Avec une super description", link_url="www.facebook.com", date_from="2018-10-25", channel_id=-6)
    conf = "{\"feed_title\": \"-\", \"feed_description\": \"-\"}"

    path = root + "-6.xml"
    rss.run(pub, conf)

    assert count(path) == 1  # Check that the post has been added
    assert check_post(pub, path)

    rss.rss_feeds = {}  # simulate a server reboot by setting the list of rss feeds to none
    rss.run(pub, conf)

    assert count(path) == 2
    assert check_post(pub, path)

    del_file([path])
Ejemplo n.º 5
0
def test_create_feed_if_none_exist():
    """
    Test if our module create a new RSS feed (new xml file) if it is the first time a post is send towards this channel.
    It also tests if it added the right post.
    """

    pub = Publishing(title="This is a test feed", description="This is a test description feed", link_url="www.facebook.com", channel_id=-1)

    path = root + "-1.xml"

    del_file([path])

    conf = "{\"feed_title\": \"-\", \"feed_description\": \"-\"}"

    rss.run(pub, conf)

    file = Path(path)

    assert file.exists()

    assert check_post(pub, path)

    del_file([path])
def test_publish_base():
    """
        Trying publishing to an existing RSS Feed
    :return:
    """
    json_data = {}
    rname = "Test Publishing"
    json_data['Feed title'] = rname
    rdescription = "Used for trying to publish a new post"
    json_data['Feed description'] = rdescription
    link = None
    origin = None

    title = "Test title"
    body = "I don't know what to write"

    pub = Publishing()
    pub.date_from = '13.02.02'
    pub.title = 'test-Title'
    pub.link_url = 'a link'
    determinants = ["une", "un", "le", "la", "les", "vos", "nos", "mes", "tes"]
    nomCommuns = [
        "chien", "chat", "vache", "cheval", "poney", "cochon", "poule", "coq"
    ]
    verbes = [
        "aller", "venir", "courir", "voler", "manger", "mourir", "partir",
        "skier"
    ]
    lieux = [
        "campagne", "montagne", "aeroport", "ecole", "mer", "jardin",
        "toilette"
    ]
    testDeterminant = determinants[random.randint(0, 8)]
    testNomCmmun = nomCommuns[random.randint(0, 7)]
    testVerbe = verbes[random.randint(0, 7)]
    testLieu = lieux[random.randint(0, 6)]
    pub.description = " " + testDeterminant + " " + testNomCmmun + " " + testVerbe + " " + testLieu + " " + str(
        random.randint(0, 10000))
    pub.image_url = 'image url'
    pub.date_until = '14.02.19'
    pub.state = 1
    c = db.session.query(Channel).filter(Channel.module == "rss").first()

    if c is None:
        print("No Rss Channel found")
        return
    pub.channel_id = c.channel_id
    plugin_name = c.module
    c_conf = c.config
    channel_config = None

    rss.run(pub, channel_config)

    localPath = os.path.dirname(__file__) + "/rss/feed_" + str(
        pub.channel_id) + ".xml"
    items = rss.import_items(localPath)
    found_wanted_feed = False

    for item in items:
        if item.description == rdescription and item.title == rname.replace(
                " ", "_"):
            found_wanted_feed = True
            print("The new field was well created")
            return
    assert found_wanted_feed, "The new rss publishign failled"