def test_store_itemtag(self, monkeypatch):
        monkeypatch.setenv("DBNAME", "Test")
        os.environ["STAGE"] = "dev"

        session = get_db_session(True, None)

        # creating items
        item = Item()
        item.content = "RKI bestätigt Covid-19 Sterblichkeitsrate von 0,01 Prozent in (...) - Corona Transition "
        item.language = "de"
        item = item_handler.create_item(item, True, session)
        list_tags = ['RKI', 'Covid', 'Corona Transition']

        # store tags
        event = {"item": item.to_dict(), "Tags": list_tags}
        context = ""
        EnrichItem.store_itemtags(event, context, True, session)

        tag = tag_handler.get_tag_by_content(list_tags[0], True, session)
        assert tag.tag == list_tags[0]

        itemtag = tag_handler.get_itemtag_by_tag_and_item_id(
            tag.id, item.id, True, session)
        assert itemtag.id is not None

        event = {"pathParameters": {"item_id": item.id}}
        ret = GetTags.get_tags_for_item(event, context, True, session)
        body = ret['body']
        # Deserialize if body is string
        if isinstance(body, str):
            tags = json.loads(body)['Tags']
        else:
            tags = body['Tags']
        assert tags == list_tags
    def test_create_tagreport_1(self):
        os.environ["STAGE"] = "dev"

        with Session() as session:

            # creating items
            item = Item()
            item.content = "RKI bestätigt Covid-19 Sterblichkeitsrate von 0,01 Prozent in (...) - Corona Transition "
            item.language = "de"
            item = item_handler.create_item(item, session)
            list_tags = [
                'Corona-Maßnahmen', 'Senkung der Treibhausgasemissionen',
                'China', 'Film', 'Menschen', 'Kanzlerkandidatur', 'sars-cov-2',
                '#verunglimpft', 'g.co/privacytools', 'Gregor Gysi',
                'Bundestagswahl2021', '19', '-',
                'Statistik falsch interpretiert', 'Bild.de', 'JF',
                'MdB Hansjörg Müller (AFD)', '100 Tage', 'Gruene',
                '#notwendige Polizeimaßnahmen', 'Sonne'
            ]
            for _ in range(200):
                list_tags.append(
                    random.choice(list_tags) + "-" + random.choice(list_tags))
            # store tags
            event = {"item": item.to_dict(), "Tags": list_tags}
            context = ""
            EnrichItem.store_itemtags(event, context)

            event = ""
            context = ""
            s = time.perf_counter()
            GetTags.create_tagreport(event, context)
            elapsed = time.perf_counter() - s
            assert elapsed < 30
    def test_store_itemurl(self, monkeypatch):
        monkeypatch.setenv("DBNAME", "Test")
        from urllib.parse import urlparse

        session = get_db_session(True, None)

        str_url = "https://smopo.ch/zehntausende-als-falsche-coronatote-deklariert/"
        # creating items
        item = Item()
        item.content = str_url
        item = item_handler.create_item(item, True, session)

        # store a url
        event = {"item": item.to_dict(), "Claim": {"urls": [str_url]}}
        context = ""
        EnrichItem.store_itemurl(event, context, True, session)

        url = url_handler.get_url_by_content(str_url, True, session)
        itemurl = url_handler.get_itemurl_by_url_and_item_id(
            url.id, item.id, True, session)
        domain = urlparse(str_url).hostname
        claimant = claimant_handler.get_claimant_by_name(domain, True, session)

        assert url.url == str_url
        assert itemurl.id is not None
        assert claimant.claimant == domain
        assert url.claimant_id is not None
def test_create_item():
    session = get_db_session(True, None)
    item = Item()
    item.content = "Testitem"
    item = item_handler.create_item(item, True, session)
    assert item.id is not None
    assert item.open_reviews == 4
    assert item.open_reviews_level_1 == 4
    assert item.open_reviews_level_2 == 4
    assert item.in_progress_reviews_level_1 == 0
    assert item.in_progress_reviews_level_2 == 0
    assert item.open_timestamp is not None
def test_create_item():
    with Session() as session:
        item = Item()
        item.content = "Testitem"
        item = item_handler.create_item(item, session)
        assert item.id is not None
        assert item.open_reviews == 4
        assert item.open_reviews_level_1 == 4
        assert item.open_reviews_level_2 == 4
        assert item.in_progress_reviews_level_1 == 0
        assert item.in_progress_reviews_level_2 == 0
        assert item.open_timestamp is not None
def session(item_id, review_id, review_question_id, user_id):
    session = get_db_session(True, None)

    item = Item()
    item.id = item_id

    user = User()
    user.id = user_id

    level = Level(id=1)

    review = Review()
    review.id = review_id
    review.item_id = item.id
    review.user_id = user.id

    review_question = ReviewQuestion()
    review_question.id = review_question_id
    review_question.content = "Question content"
    review_question.info = "Question info"
    review_question.hint = "Question hint"

    o1 = AnswerOption(id="1", text="Option 1", value=0)
    o2 = AnswerOption(id="2", text="Option 2", value=1, tooltip="Tooltip 2")
    o3 = AnswerOption(id="3", text="Option 3", value=2)
    o4 = AnswerOption(id="4", text="Option 4", value=3)

    o1.questions = [review_question]
    o2.questions = [review_question]
    o4.questions = [review_question]
    o3.questions = [review_question]

    # all answers use the same review questions in order to keep the test data small
    reviewanswer1 = generate_review_answer(1, review_id, review_question_id)
    reviewanswer2 = generate_review_answer(0, review_id, review_question_id)
    reviewanswer3 = generate_review_answer(1, review_id, review_question_id)
    reviewanswer4 = generate_review_answer(3, review_id, review_question_id)
    reviewanswer5 = generate_review_answer(2, review_id, review_question_id)
    reviewanswer6 = generate_review_answer(1, review_id, review_question_id)
    reviewanswer7 = generate_review_answer(2, review_id, review_question_id)
    review.review_answers = [reviewanswer1, reviewanswer2, reviewanswer3,
                             reviewanswer4, reviewanswer5, reviewanswer6, reviewanswer7]

    session.add(item)
    session.add(user)
    session.add(level)
    session.add(review_question)
    # refernenced ReviewAnswers are stored as well
    session.add(review)

    session.commit()

    return session
    def test_post_tags_for_item_2(self, monkeypatch):
        monkeypatch.setenv("DBNAME", "Test")
        os.environ["STAGE"] = "dev"

        session = get_db_session(True, None)

        # creating items
        item = Item()
        item.content = "https://corona-transition.org/rki-bestatigt-covid-19-sterblichkeitsrate-von-0-01-prozent-in" \
                       "-deutschland?fbclid=IwAR2vLIkW_3EejFaeC5_wC_410uKhN_WMpWDMAcI-dF9TTsZ43MwaHeSl4n8%22 "
        item.language = "de"
        item = item_handler.create_item(item, True, session)

        event = {"pathParameters": {"item_id": item.id}}
        context = ""
        response = GetTags.get_tags_for_item(event, context, True, session)
        body = response['body']
        # Deserialize if body is string
        if isinstance(body, str):
            tags = json.loads(body)['Tags']
        else:
            tags = body['Tags']
        assert tags == []

        json.dumps({"tags": ["RKI", "Covid-19"]})
        event = {
            "pathParameters": {
                "item_id": item.id
            },
            "body": json.dumps({"tags": ["RKI", "Covid-19"]})
        }
        response = GetTags.post_tags_for_item(event, context, True, session)
        body = response['body']
        # Deserialize if body is string
        if isinstance(body, str):
            tags_added = json.loads(body)['added tags']
            tags_removed = json.loads(body)['removed tags']
        else:
            tags_added = body['added tags']
            tags_removed = body['removed tags']
        assert 'RKI' in tags_added
        assert 'Covid-19' in tags_added
        assert len(tags_removed) == 0
        assert tags_removed == []
        response = GetTags.get_tags_for_item(event, context, True, session)
        body = response['body']
        # Deserialize if body is string
        if isinstance(body, str):
            tags = json.loads(body)['Tags']
        else:
            tags = body['Tags']
        assert tags == ['RKI', 'Covid-19']
    def test_get_online_factcheck_by_itemid_2(self, monkeypatch):
        monkeypatch.setenv("DBNAME", "Test")
        os.environ["STAGE"] = "dev"

        session = get_db_session(True, None)

        # creating items
        item = Item()
        item.content = "https://corona-transition.org/rki-bestatigt-covid-19-sterblichkeitsrate-von-0-01-prozent-in" \
                       "-deutschland?fbclid=IwAR2vLIkW_3EejFaeC5_wC_410uKhN_WMpWDMAcI-dF9TTsZ43MwaHeSl4n8%22 "
        item.language = "de"
        item = item_handler.create_item(item, True, session)

        # store a fact check
        event = {
            "item": {
                "id": item.id,
                "content": item.content,
                "language": item.language,
            },
            "KeyPhrases": [
                "das Zahlenmaterial", "es", "den letzten 7 Tagen", "das RKI",
                "sich"
            ],
            "Entities": [
                "RKI", "0,01 Prozent", "19 Sterblichkeitsrate",
                "Corona Transition", "Covid"
            ],
            "Sentiment":
            "NEUTRAL"
        }
        context = ""
        EnrichItem.store_itementities(event, context, True, session)
        EnrichItem.store_itemphrases(event, context, True, session)

        event = {"pathParameters": {"item_id": item.id}}
        context = {}
        s = time.perf_counter()
        response = get_online_factcheck.get_online_factcheck(
            event, context, True, session)
        elapsed = time.perf_counter() - s
        body = response['body']
        # Deserialize if body is string
        if isinstance(body, str):
            factcheck = json.loads(body)
        else:
            factcheck = body
        assert factcheck[
            'url'] == 'https://correctiv.org/faktencheck/2020/07/09/nein-rki-bestaetigt-nicht-eine-covid-19-sterblichkeitsrate-von-001-prozent-in-deutschland/'
        assert factcheck[
            'title'] == 'Falsch. Das Robert-Koch-Institut bestätigte nicht eine Covid-19- Sterblichkeitsrate von 0,01 Prozent in Deutschland.'
        assert elapsed < 3
    def test_tags_and_urls(self):
        with Session() as session:

            session = setup_scenarios.create_levels_junior_and_senior_detectives(
                session)
            session = setup_scenarios.create_questions(session)

            junior_detective1 = user_handler.get_user_by_id("1", session)

            item1 = Item()
            item1.content = "Item 1"
            item1.status = "open"
            item1.item_type_id = "Type1"
            item1 = item_handler.create_item(item1, session)

            url = URL()
            url.id = str(uuid4())
            url.url = 'www.test.com'

            item_url = ItemURL()
            item_url.id = str(uuid4())
            item_url.item_id = item1.id
            item_url.url_id = url.id

            tag = Tag()
            tag.id = str(uuid4())
            tag.tag = "Test Tag"

            item_tag = ItemTag()
            item_tag.id = str(uuid4())
            item_tag.item_id = item1.id
            item_tag.tag_id = tag.id

            session.add_all([url, item_url, tag, item_tag])

            event = event_creator.get_create_review_event(
                junior_detective1.id, item1.id)

            response = get_open_items(event, None)
            assert response['statusCode'] == 200

            body = json.loads(response['body'])
            items = body['items']
            assert len(items) == 1
            urls = items[0]['urls']
            assert len(urls) == 1
            assert urls[0]['url'] == 'www.test.com'

            tags = items[0]['tags']
            assert len(tags) == 1
            assert tags[0] == "Test Tag"
def create_item_with_urls(session, urls) -> Item:
    item = Item()
    item.language = "de"
    item = item_handler.create_item(item, session)
    for url_str in urls:
        url = URL()
        url.id = str(uuid4())
        url.url = url_str
        itemUrl = ItemURL()
        itemUrl.item_id = item.id
        itemUrl.url_id = url.id
        itemUrl.id = str(uuid4())
        session.add(url)
        session.add(itemUrl)
        session.commit()
    return item
Exemple #11
0
def update_item(event, context):
    """stores data related to item

    Parameters
    ----------
    event: dict, required
        item

        Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format

    context: object, required
        Lambda Context runtime methods and attributes

        Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html

    Returns
    ------
    API Gateway Lambda Proxy Output Format: application/json

        Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
    """

    with Session() as session:

        # Parse event dict to Item object
        item = Item()
        json_event = event['item']
        for key in json_event:
            setattr(item, key, json_event[key])

        update_object(item, session)
def update_item_warning_tags(item: Item, session) -> Item:
    questions_with_warning_tags = []
    answer_dict = {}
    for review in item.reviews:
        for answer in review.review_answers:
            if answer.answer is None:
                continue
            if answer.review_question_id not in answer_dict:
                answer_dict[answer.review_question_id] = {
                    'question': answer.review_question,
                    'answers': [answer.answer]
                }
            else:
                answer_dict[answer.review_question_id]['answers'].append(
                    answer.answer)
    for key in answer_dict:
        answers = answer_dict[key]['answers']
        question = answer_dict[key]['question']
        if len(answers) <= 2:
            continue
        if sum(answers) / len(answers) > 2:
            continue
        questions_with_warning_tags.append(question)
    for question in questions_with_warning_tags:
        icq = ItemCriticalQuestion(
            id=str(uuid4()), item_id=item.id, review_question_id=question.id)
        session.add(icq)

    item.warning_tags_calculated = True
    session.merge(item)
    session.commit()
    return item
Exemple #13
0
def test_get_closed_items():

    # pre-stuff
    os.environ["STAGE"] = "dev"

    with Session() as session:

        context = None

        # create item
        item = Item()
        item.content = "Test content"
        item.language = "de"
        item.status = "closed"
        item = item_handler.create_item(item, session)

        # create events with tags
        event1 = {
            "pathParameters": {
                "item_id": item.id
            },
            "body": json.dumps({"tags": ['C', 'B', 'D']})
        }
        event2 = {
            "pathParameters": {
                "item_id": item.id
            },
            "body": json.dumps({"tags": ['B', 'C']})
        }
        event3 = {
            "pathParameters": {
                "item_id": item.id
            },
            "body": json.dumps({"tags": ['A', 'B']})
        }

        # post tags
        GetTags.post_tags_for_item(event1, context)
        GetTags.post_tags_for_item(event2, context)
        GetTags.post_tags_for_item(event3, context)

        # Check if tags are sorted by number of mentions
        response = get_closed_items(event1, context)
        body = response['body']
        tags = json.loads(body)[0]['tags']
        assert tags in [['B', 'C', 'A', 'D'], ['B', 'C', 'D', 'A']]
def test_tags_to_dict():
    with Session() as session:
        user = User(id=str(uuid4()), name='user1')
        level = Level(id=1, description='beginner')

        item = Item(id=str(uuid4()), content='item')

        tag1 = Tag(id=str(uuid4()), tag='tag1')
        tag2 = Tag(id=str(uuid4()), tag='tag2')
        tag3 = Tag(id=str(uuid4()), tag='tag3')

        review = Review()
        review.id = str(uuid4())
        review.is_peer_review = False
        review.user_id = user.id
        review.item_id = item.id

        session.add_all([user, item, tag1, tag2, tag3, review, level])
        session.commit()

        review_dict = review.to_dict(with_tags=True, with_user=True)
        assert 'tags' in review_dict
        assert len(review_dict['tags']) == 0

        item_tag1 = ItemTag(id=str(uuid4()),
                            item_id=item.id,
                            tag_id=tag1.id,
                            review_id=review.id)
        session.add(item_tag1)
        session.commit()
        session.refresh(review)

        review_dict = review.to_dict(with_tags=True, with_user=True)
        assert 'tags' in review_dict
        assert len(review_dict['tags']) == 1
        assert review_dict['tags'][0] == 'tag1'

        item_tag2 = ItemTag(id=str(uuid4()),
                            item_id=item.id,
                            tag_id=tag2.id,
                            review_id=review.id)
        session.add(item_tag2)
        session.commit()
        session.refresh(review)

        review_dict = review.to_dict(with_tags=True, with_user=True)
        assert 'tags' in review_dict
        assert len(review_dict['tags']) == 2
        assert 'tag2' in review_dict['tags']

        session.delete(item_tag1)
        session.commit()
        session.refresh(review)
        review_dict = review.to_dict(with_tags=True, with_user=True)
        assert 'tags' in review_dict
        assert len(review_dict['tags']) == 1
        assert review_dict['tags'][0] == 'tag2'
    def test_get_online_factcheck_by_itemid_5(self, monkeypatch):
        monkeypatch.setenv("DBNAME", "Test")
        os.environ["STAGE"] = "dev"

        session = get_db_session(True, None)

        # creating items
        item = Item()
        item.content = "Ein in sozialen Medien kursierendes Video soll angeblich große Schwächen der zum Corona-Test genutzten PCR-Methode offenbaren. 'Sensation! Naomi Seibt widerlegt den PCR Test von Prof Drosten! KEIN Virus EXISTENT!!!', heißt es etwa (hier archiviert, hier Video archiviert)"
        item.language = "de"
        item = item_handler.create_item(item, True, session)

        # store a fact check
        event = {
            "item": {
                "id": item.id,
                "content": item.content,
                "language": item.language,
            },
            "KeyPhrases": ["Drosten", "Test", "Corona", "PCR"],
            "Entities": []
        }
        context = ""
        EnrichItem.store_itementities(event, context, True, session)
        EnrichItem.store_itemphrases(event, context, True, session)

        event = {"pathParameters": {"item_id": item.id}}
        context = {}
        s = time.perf_counter()
        response = get_online_factcheck.get_online_factcheck(
            event, context, True, session)
        elapsed = time.perf_counter() - s
        body = response['body']
        # Deserialize if body is string
        if isinstance(body, str):
            factcheck = json.loads(body)
        else:
            factcheck = body
        assert factcheck[
            'url'] == 'https://correctiv.org/faktencheck/2020/11/23/nein-christian-drosten-hat-2014-nicht-gesagt-dass-er-pcr-tests-fuer-untauglich-halte/'
        assert factcheck[
            'title'] == 'Fehlender Kontext. Drosten sagte nicht, PCR-Tests seien „untauglich“ – er kritisierte die Teststrategie 2014 in der MERS-Epidemie. Seine Aussagen lassen sich nicht auf die heutige Coronavirus-Pandemie übertragen.'
        assert elapsed < 3
def session(item_id):
    session = get_db_session(True, None)
    session = setup_scenarios.create_questions(session)
    session = setup_scenarios.create_levels_junior_and_senior_detectives(
        session)

    item = Item(id=item_id, item_type_id="Type1")

    session.add(item)
    session.commit()
    return session
def test_get_user():

    with Session() as session:

        session = setup_scenarios.create_levels_junior_and_senior_detectives(
            session)
        junior_detective1 = user_handler.get_user_by_id("1", session)

        event = event_creator.get_create_review_event(junior_detective1.id,
                                                      "abc")
        resp = get_user(event, None)
        body = json.loads(resp["body"])

        assert body["id"] == junior_detective1.id
        assert body["level"] == 1
        assert body["level_description"] == "Junior"
        assert body["progress"] == 0
        assert body["total_rank"] == session.query(User).count()
        assert body["level_rank"] == session.query(User).filter(
            User.level_id == junior_detective1.level_id).count()
        assert body["solved_cases_total"] == 0
        assert body["solved_cases_today"] == 0
        assert body["exp_needed"] == 5
        sign_up_date = datetime.strptime(body["sign_up_timestamp"],
                                         '%Y-%m-%d %H:%M:%S').date()
        assert sign_up_date != datetime.today()

        item1 = Item(id='item1', status='closed')
        review1 = Review(id='review1',
                         user_id=junior_detective1.id,
                         item_id=item1.id)
        item2 = Item(id='item2', status='open')
        review2 = Review(id='review2',
                         user_id=junior_detective1.id,
                         item_id=item2.id)
        session.add_all([item1, item2, review1, review2])
        session.commit()
        resp = get_user(event, None)
        body = json.loads(resp["body"])
        assert len(body['closed_items']) == 1
        assert body['closed_items'][0]['id'] == 'item1'
    def test_store_factcheck_empty(self, monkeypatch):
        monkeypatch.setenv("DBNAME", "Test")

        session = get_db_session(True, None)

        # creating items
        item = Item()
        item.content = "item is referencing some fact checks"
        item = item_handler.create_item(item, True, session)

        # store a fact check
        event = {
            "item": {
                "id": item.id,
                "content": item.content,
                "language": "en",
            },
            "FactChecks": [""]
        }
        context = ""
        EnrichItem.store_factchecks(event, context, True, session)
        assert 1 == 1
Exemple #19
0
def test_prepare_and_store_urls_for_localhost_url():
    with Session() as session:
        str_urls = [
            "http://LOCALHOST/utes-moma-127-8-altmaier-will-haertere-strafen-bei-verstoessen-gegen-die-corona-regeln/",
            "http://127.0.0.1/utes-moma-127-8-altmaier-will-haertere-strafen-bei-verstoessen-gegen-die-corona-regeln/"
        ]

        item = Item()
        item = item_handler.create_item(item, session)

        url_handler.prepare_and_store_urls(item, str_urls, session)
        assert item.urls == []
        assert item.status != 'Unsafe'
Exemple #20
0
def test_prepare_and_store_urls_with_unsafe_items():
    with Session() as session:
        str_urls = ["http://testsafebrowsing.appspot.com/s/malware.html"]

        item = Item()
        item = item_handler.create_item(item, session)

        url_handler.prepare_and_store_urls(item, str_urls, session)
        for str_url in str_urls:
            url = verify_and_get_url(item, str_url, session)
            assert url.unsafe is not None

        assert item.status == 'Unsafe'
def test_create_review(item_id, junior_user_id, senior_user_id):

    with Session() as session:

        session = setup_scenarios.create_questions(session)
        session = setup_scenarios.create_levels_junior_and_senior_detectives(session)
        item = Item(id=item_id, item_type_id="Type1")
        session.add(item)
        session.commit()        

        # Create junior review
        event = event_creator.get_create_review_event(junior_user_id, item_id)
        response = create_review.create_review(event, None)
        assert response['statusCode'] == 201
        reviews = session.query(Review).all()
        assert len(reviews) == 1
        review = Review()
        review = reviews[0]
        assert review.user_id == junior_user_id
        assert review.item_id == item_id
        question_ids = []
        for answer in review.review_answers:
            question_ids.append(answer.review_question_id)

        assert "other_type" not in question_ids
        parent_question_counter = 0
        for answer in review.review_answers:
            if answer.review_question.max_children > 0:
                child_questions = session.query(ReviewQuestion).filter(
                    ReviewQuestion.parent_question_id == answer.review_question_id).all()
                for child_question in child_questions:
                    assert child_question.id in question_ids
            if answer.review_question.parent_question_id is None:
                parent_question_counter += 1

        assert parent_question_counter == 6

        event = event_creator.get_create_review_event(senior_user_id, item_id)
        response = create_review.create_review(event, None)
        assert response['statusCode'] == 201
        reviews = session.query(Review).all()
        assert len(reviews) == 2
        reviews = session.query(Review).filter(
            Review.user_id == senior_user_id).all()
        assert len(reviews) == 1
        review = reviews[0]
        assert review.user_id == senior_user_id
        assert review.item_id == item_id
        for answer in review.review_answers:
            assert answer.review_question_id in question_ids
    def test_get_online_factcheck_by_itemid_4(self, monkeypatch):
        monkeypatch.setenv("DBNAME", "Test")
        os.environ["STAGE"] = "dev"

        session = get_db_session(True, None)

        # creating items
        item = Item()
        item.content = "https://kopp-report.de/helios-kliniken-veroeffentlichen-corona-fakten-keine-pandemie-von-nationaler-tragweite/?fbclid=IwAR1fMRjkKXXYQUiNxYrgYczcffvNZbW-F3z8Q4f4Ar00caSNO1KjFtyJrG4"
        item.language = None
        item = item_handler.create_item(item, True, session)

        # store a fact check
        event = {
            "item": {
                "id": item.id,
                "content": item.content,
                "language": item.language,
            },
            "KeyPhrases": [],
            "Entities": [],
            "Sentiment": "NEUTRAL"
        }
        context = ""
        EnrichItem.store_itementities(event, context, True, session)
        EnrichItem.store_itemphrases(event, context, True, session)

        event = {"pathParameters": {"item_id": item.id}}
        context = {}
        s = time.perf_counter()
        response = get_online_factcheck.get_online_factcheck(
            event, context, True, session)
        elapsed = time.perf_counter() - s
        body = response['body']
        # Deserialize if body is string
        assert body == 'No factcheck found. Exception: Language of Claim not recognized.'
        assert elapsed < 3
Exemple #23
0
def test_prepare_and_store_urls():
    with Session() as session:
        str_urls = [
            "https://smopo.ch/zehntausende-als-falsche-coronatote-deklariert/"
        ]

        item = Item()
        item = item_handler.create_item(item, session)

        url_handler.prepare_and_store_urls(item, str_urls, session)
        for str_url in str_urls:
            url = verify_and_get_url(item, str_url, session)
            assert url.unsafe is None

        assert item.status != 'Unsafe'
Exemple #24
0
def test_prepare_and_store_urls_localhost_url_skipped():
    with Session() as session:
        str_urls = [
            "http://localhost:8080/index.html", "https://www.google.de/"
        ]

        item = Item()
        item = item_handler.create_item(item, session)

        url_handler.prepare_and_store_urls(item, str_urls, session)
        assert len(item.urls) == 1
        for str_url in ["https://www.google.de/"]:
            verify_and_get_url(item, str_url, session)

        assert item.status != 'Unsafe'
Exemple #25
0
def test_prepare_and_store_urls_multiply_urls_with_unsafe_items():
    with Session() as session:
        str_urls = [
            "http://testsafebrowsing.appspot.com/s/phishing.html",
            "https://www.google.de/"
        ]

        item = Item()
        item = item_handler.create_item(item, session)

        url_handler.prepare_and_store_urls(item, str_urls, session)
        for str_url in str_urls:
            verify_and_get_url(item, str_url, session)

        assert item.status == 'Unsafe'
Exemple #26
0
def test_post_comment_on_item(event, item_id, user_id):

    with Session() as session:

        item_obj = Item(id=item_id)
        user_obj = User(id=user_id, name='Testuser')
        level_1_obj = Level(id=1)
        session.add_all([item_obj, level_1_obj, user_obj])
        session.commit()

        response = post_comment_on_item(event)

        body = json.loads(response['body'])
        assert body['user'] == 'Testuser'

        comment = session.query(Item).all()[
            0].comments[0]

        assert comment.comment == "Comment from event"
        assert comment.is_review_comment == False
        assert comment.status == "published"
Exemple #27
0
def test_update_review(item_id, junior_user_id, senior_user_id, monkeypatch):

    monkeypatch.setenv("CORS_ALLOW_ORIGIN", "http://localhost:4200")
    with Session() as session:

        session = setup_scenarios.create_questions(session)
        session = setup_scenarios.create_levels_junior_and_senior_detectives(
            session)
        item = Item(id=item_id, item_type_id="Type1")
        session.add(item)
        session.commit()

        # Create junior review
        event = event_creator.get_create_review_event(junior_user_id, item_id)
        response = create_review.create_review(event, None)
        assert response['statusCode'] == 201
        reviews = session.query(Review).all()
        assert len(reviews) == 1
        review = Review()
        review = reviews[0]

        # Test 403
        event = event_creator.get_review_event(
            review, item_id, "in progress", senior_user_id, 1)

        response = update_review.update_review(event, None)
        assert response['statusCode'] == 403

        event = event_creator.get_review_event(
            review, item_id, "in progress", junior_user_id, 1, tags=['test', 'tag'])

        response = update_review.update_review(event, None)
        assert response['statusCode'] == 200

        # Test comments
        comments = session.query(Comment).all()[0]
        assert comments.comment == "Test comment"
        assert comments.review_id == review.id
        assert comments.user_id == junior_user_id
        assert comments.status == "published"
        assert comments.is_review_comment == True

        # Test tags
        item_tags = session.query(ItemTag).all()
        assert len(item_tags) == 2
        for item_tag in item_tags:
            assert item_tag.item_id == item.id
            assert item_tag.review_id == review.id
            assert item_tag.tag.tag in ['test', 'tag']

        event = event_creator.get_review_event(
            review, item_id, "in progress", junior_user_id, 1, tags=['test'])
        response = update_review.update_review(event, None)
        assert response['statusCode'] == 200
        item_tags = session.query(ItemTag).all()
        assert len(item_tags) == 1
        assert item_tags[0].item_id == item.id
        assert item_tags[0].review_id == review.id
        assert item_tags[0].tag.tag == 'test'
        response_body = json.loads(response['body'])
        assert 'tags' in response_body
        assert len(response_body['tags']) == 1
        assert response_body['tags'][0] == 'test'

        event = event_creator.get_review_event(
            review, item_id, "in progress", junior_user_id, 1, tags=[])
        response = update_review.update_review(event, None)
        assert response['statusCode'] == 200
        response_body = json.loads(response['body'])
        assert 'tags' in response_body
        assert len(response_body['tags']) == 0

        event = event_creator.get_review_event(
            review, item_id, "in progress", junior_user_id, 1, tags=None)
        response = update_review.update_review(event, None)
        assert response['statusCode'] == 200
        response_body = json.loads(response['body'])
        assert 'tags' in response_body
        assert len(response_body['tags']) == 0

        event = event_creator.get_review_event(
            review, item_id, "closed", junior_user_id, 1, tags=None)
        response = update_review.update_review(event, None)
        assert response['statusCode'] == 200

        # Test not existing review
        fake_review = review
        fake_review.id = "fake"
        event = event_creator.get_review_event(
            fake_review, item_id, "in progress", junior_user_id, 1)

        response = update_review.update_review(event, None)
        assert response['statusCode'] == 404
    def test_DocSim_vs_RegExp(self, monkeypatch):
        monkeypatch.setenv("DBNAME", "Test")
        os.environ["STAGE"] = "dev"

        session = get_db_session(True, None)

        claim_factcheck_dicts = [
            {
                "claim": "https://www.facebook.com/DieSteffi82/posts/5064896943550398",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/23/nein-abstrichstaebchen-von-corona-schnelltests-sind-nicht-verseucht/",
                "stepfunction": {}
            },
            {
                # nicht extrahierbar
                "claim": "In Ägypten war das eine Strafe für Slaves... Breche die Drüse der Blutenzephalitis: https://www.facebook.com/photo.php?fbid=3591706030868619&set=a.368339826538605&type=3",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/23/nein-nasenabstriche-fuer-einen-corona-test-gleichen-nicht-einer-strafe-fuer-sklaven-im-alten-aegypten/",
                "stepfunction": {}
            },
            {
                # twitter benötigt eine andere extraktionsmethode
                "claim": "An der Universität Cambridge wurden alle 9000 Studenten mit PCR getestet. Alle Tests stellten sich im nach hinein als falsch positiv heraus - 100% falsche Ergebnisse und auf diesem Test beruhen, Foderungen  und Massnahmen. Es reicht jetzt wirklich.: https://twitter.com/LuanaNussbaum/status/1336956296017350657?s=20",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/23/nein-an-der-universitaet-cambridge-wurden-nicht-9-000-studierende-falsch-positiv-auf-corona-getestet/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.facebook.com/Silberjungede-Wir-wollen-Augen-öffnen-Thorsten-Schulte-155330287422/videos/381310726307004/",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/22/dauer-lockdown-angela-merkels-aussage-wird-irrefuehrend-interpretiert/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.facebook.com/svensworld000/videos/2792271450987454/",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/21/video-keine-belege-dass-ein-corona-schnelltest-positiv-auf-fruchtsaft-reagierte/",
                "stepfunction": {}
            },
            {
                "claim": "https://corona-transition.org/rki-bestatigt-covid-19-sterblichkeitsrate-von-0-01-prozent-in" \
                    "-deutschland?fbclid=IwAR2vLIkW_3EejFaeC5_wC_410uKhN_WMpWDMAcI-dF9TTsZ43MwaHeSl4n8%22 ",
                "factcheck": "https://correctiv.org/faktencheck/2020/07/09/nein-rki-bestaetigt-nicht-eine-covid-19-sterblichkeitsrate-von-001-prozent-in-deutschland/",
                "stepfunction": {}
            },
            {
                "claim": "https://kopp-report.de/helios-kliniken-veroeffentlichen-corona-fakten-keine-pandemie-von-nationaler-tragweite/?fbclid=IwAR1fMRjkKXXYQUiNxYrgYczcffvNZbW-F3z8Q4f4Ar00caSNO1KjFtyJrG4",
                "factcheck": "https://correctiv.org/faktencheck/medizin-und-gesundheit/2020/11/06/corona-zahlen-ueber-patienten-auf-intensivstationen-in-helios-kliniken-werden-irrefuehrend-verbreitet/",
                "stepfunction": {}
            },
            {
                "claim": "Manche Corona-Tests brauchen keine externe Qualitätskontrolle",
                "factcheck": "https://www.br.de/nachrichten/wissen/warum-viele-corona-tests-noch-keine-qualitaetskontrolle-brauchen,SI1KrNC",
                "stepfunction": {}
            },
#            {
#                "claim": "https://viralvirus.de/politik/obama-finanzierte-labor-in-wuhan/?fbclid=IwAR3qOdSnC-A7h6wvPQcOFmuFPgLGNOImn_Ee6_vjAGeAmVJ9MVZnoNeFMBk",
#                "factcheck": "https://correctiv.org/faktencheck/2020/07/21/nein-die-us-regierung-unter-obama-hat-das-institut-fuer-virologie-in-wuhan-nicht-mit-37-millionen-dollar-unterstuetzt/",
#                "stepfunction": {}
#            },
            {
                "claim": "Spanien korrigiert Anzahl der  Corona-Toten von über 26.000 auf 2.000. Bin mal gespannt, wie lange D-A-CH noch an den FAKE-Zahlen festhalten wollen.",
                "factcheck": "https://correctiv.org/faktencheck/2020/06/16/nein-spanien-hat-die-zahl-der-corona-toten-nicht-auf-2-000-korrigiert/",
                "stepfunction": {}
            },
            {
                "claim": "GERADE VON NTV AUFGENOMMEN!!!! MERKEL EMPFÄNGT MINSITERPRÄSIDENTEN IM KANZLERAMT.WO IST DER SICHERHEITSABSTAND, WO SIND DIE MASKEN??? SELBST SÖDER TRÄGT KEINE, ABER WEHE DER STEHT IN BAYERN VOR EINER PK, DA KOMMT DER DANN MIT MASKE REIN.WAS EIN VERLOGENES VOLK",
                "factcheck": "https://correctiv.org/faktencheck/2020/06/24/nein-merkel-hat-die-ministerpraesidenten-nicht-ohne-sicherheitsabstand-empfangen/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.bitchute.com/video/WGkyGAUdwqlh/",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/17/sprachnachricht-verbreitet-unbelegte-behauptung-ueber-corona-tests-mit-voreingestelltem-ergebnis/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.facebook.com/corinnas.angelika.winkler/videos/4668198303252715",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/16/video-nein-corona-schnelltest-reagiert-nicht-positiv-auf-rotwein/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.facebook.com/steffen.mono/videos/1531749847023893/",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/16/positiver-corona-test-bei-apfelmus-hat-keine-aussagekraft/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.ots.at/presseaussendung/OTS_20201210_OTS0242/fpoe-schnedlitz-macht-live-coronatest-im-parlament",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/15/antigen-schnelltest-falsch-durchgefuehrt-fpoe-politiker-testet-cola-auf-corona/",
                "stepfunction": {}
            },
            {
                # twitter benötigt eine andere extraktionsmethode
                "claim": "Ich übersetzte das mal für die #Gerichte: Jeder Patient mit #Lungenentzündung, der Kontakt mit einer positiv getesteten Person hatte, wird als Covid19 Fall gemeldet, auch wenn er selbst negativ getestet wurde. https://twitter.com/QuakDr/status/1332601338514038784",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/15/es-stimmt-nicht-dass-jeder-patient-mit-lungenentzuendung-als-corona-fall-gezaehlt-wird/",
                "stepfunction": {}
            },
            {
                # nicht extrahierbar
                "claim": "Lothar Wieler vom RKI: Wir haben viel gelernt.. unabhängig davon ob es das Virus gibt, oder nicht Diese Aussage muss man sich mal auf der Zunge zergehen lassen! https://www.facebook.com/photo.php?fbid=3466879523407507&set=a.897173730378112&type=3",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/15/ob-es-das-virus-gibt-oder-nicht-zitat-von-rki-chef-lothar-wieler-aus-dem-kontext-gerissen/",
                "stepfunction": {}
            },
            {
                # nicht extrahierbar
                "claim": "Die Schweizer Zulassungsbehörde hat soeben den deutschen mRNA-Corona-Impfstoff als zu gefährlich und unkalkulierbar ABGELEHNT. ***** TELEBASEL.CH Swissmedic: Stand heute können wir keine Zulassung für einen Impfstoff erteilen https://www.facebook.com/photo.php?fbid=1187531251644128&set=a.135783410152256&type=3",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/14/schweiz-nein-einem-corona-impfstoff-wurde-nicht-die-zulassung-verweigert-weil-er-zu-gefaehrlich-und-unkalkulierbar-sei/",
                "stepfunction": {}
            },
            {
                # Forbidden to extract
                "claim": "Italien: Studie belegt stark erhöhten CO2-Wert unter der Maske https://2020news.de/italien-studie-belegt-stark-erhoehten-co2-wert-unter-der-maske/",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/14/nein-eine-angebliche-studie-belegt-keinen-zu-hohen-co2-wert-unter-masken/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.facebook.com/yhardt/videos/10222050726953076",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/10/impfstudie-alles-deutet-darauf-hin-dass-dieser-arzt-in-brasilien-nicht-durch-eine-corona-impfung-starb/",
                "stepfunction": {}
            },
            {
                # nicht extrahierbar
                "claim": "Warum ist es notwendig, tief in der Nase nach dem Virus zu suchen?... Wäre es nicht ausreichend, auf das Stäbchen zu spucken, wenn doch angeblich das Virus au einem Meter schon ansteckend sein soll? https://www.facebook.com/photo.php?fbid=1773053819513552&set=a.794989853986625&type=3",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/10/deshalb-wird-der-abstrich-fuer-pcr-tests-meist-am-nasenrachen-gemacht/",
                "stepfunction": {}
            },
            {
                "claim": "https://fingersblog.com/2020/11/19/niederlande-nur-wer-geimpft-ist-darf-sich-wieder-frei-bewegen/",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/10/vorteile-fuer-menschen-die-sich-gegen-covid-19-impfen-lassen-niederlaendischer-gesundheitsminister-spricht-von-missverstaendnis/",
                "stepfunction": {}
            },
            {
                "claim": "https://corona-transition.org/amtliche-anweisung-an-arzte-und-apotheker-bitte-sprechen-sie-die-risiken-nicht",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/09/nein-jens-spahn-hat-nicht-gesagt-dass-apotheker-keine-bedenken-zu-corona-impfstoffen-aeussern-sollen/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.youtube.com/watch?v=io5ShKM4MV8&feature=youtu.be",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/09/unwissenheit-ueber-covid-19-impfstoffe-aelteres-interview-mit-rki-chef-wieler-wird-irrefuehrend-verbreitet/",
                "stepfunction": {}
            },
            {
                # nicht extrahierbar
                "claim": "Weisheit des Tages: Wenn man an COVID stirbt, wird man sehr leicht... https://www.facebook.com/groups/648478082346782/permalink/978930515968202/",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/07/nein-diese-bilder-von-leichensaecken-und-einem-sarg-zeigen-nicht-dass-corona-todesfaelle-inszeniert-werden/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.facebook.com/permalink.php?story_fbid=2992046007562267&id=353649981401896",
                "factcheck": "https://correctiv.org/faktencheck/2020/12/07/nein-das-tragen-einer-maske-fuehrt-nicht-zu-sauerstoffmangel-bei-kindern/",
                "stepfunction": {}
            },
            {
                "claim": "https://www.spiegel.de/wissenschaft/medizin/corona-krise-bringt-rekord-rueckgang-der-co2-emissionen-a-81f70390-624d-4717-ba35-f3bc130ad8df",
                "factcheck": "",
                "stepfunction": {}
            },
            {
                "claim": "Kinderarzt besorgt: Corona-Geimpfte sind Teil eines medizinischen Experiments: https://www.compact-online.de/kinderarzt-besorgt-corona-geimpfte-sind-teil-eines-medizinischen-experiments/",
                "factcheck": "",
                "stepfunction": {}
            },
            {
                "claim": "Baden-Württemberg: Zwangseinweisung für hartnäckige Quarantäneverweigerer beschlossen: https://de.rt.com/inland/110251-baden-wurttemberg-zwangseinweisung-fur-hartnackige/",
                "factcheck": "",
                "stepfunction": {}
            },
            {
                "claim": "Gesundheitsexperten warnen vor kurzfristigen, aber heftigen Nebenwirkungen einer Corona-Impfung https://de.rt.com/inland/110211-gesundheitsexperten-warnen-vor-kurzfristigen-aber-heftigen-nebenwirkungen-corona-impfung/",
                "factcheck": "",
                "stepfunction": {}
            },
        ]

        # search fact checks for all items
        count_fcExists = 0
        count_kp_tp = 0
        count_kp_fn = 0
        count_noFc = 0
        count_kp_tn = 0
        count_kp_fp = 0

        for i in range(len(claim_factcheck_dicts)):
            # creating item
            item = Item()
            item.content = claim_factcheck_dicts[i]["claim"]
            item = item_handler.create_item(item, True, session)
            claim_factcheck_dicts[i]["stepfunction"]["item"] =  {
                    "id": item.id,
                    "content": item.content,
                    "language": item.language,
                }

            #extract claim
            event = {
                "item": claim_factcheck_dicts[i]["stepfunction"]["item"]
            }
            context = ""
            claim = ExtractClaim.extract_claim(event, context)
            claim_factcheck_dicts[i]["stepfunction"]["Claim"] = claim

            # detect language
            event = {
                "Text": claim["concatenation"]["Text"]
            }
            try:
                claim_factcheck_dicts[i]["stepfunction"]["item"]["language"] = GetLanguage.get_language(event, context)
            except:
                continue

            # increment count of factchecks
            if claim_factcheck_dicts[i]["factcheck"] == "":
                count_noFc = count_noFc+1
            else:
                count_fcExists = count_fcExists+1

            # detect key phrases
            event["LanguageCode"] = claim_factcheck_dicts[i]["stepfunction"]["item"]["language"]
            claim_factcheck_dicts[i]["stepfunction"]["KeyPhrases"] = GetKeyPhrases.get_phrases(event, context)

            # detect entities
            claim_factcheck_dicts[i]["stepfunction"]["Entities"] = GetEntities.get_entities(event, context)

            # search factchecks with KeyPhrases
            event = {
                "item": claim_factcheck_dicts[i]["stepfunction"]["item"],
                "KeyPhrases": claim_factcheck_dicts[i]["stepfunction"]["KeyPhrases"],
                "Entities": claim_factcheck_dicts[i]["stepfunction"]["Entities"]
            }
            ret = SearchFactChecks.get_FactChecks(event, context)
            url = ""
            if 'claimReview' in ret[0]:
                url = ret[0]['claimReview'][0]['url']
            if url == claim_factcheck_dicts[i]["factcheck"]:
                if url == "":
                    count_kp_tn = count_kp_tn+1
                else:
                    count_kp_tp = count_kp_tp+1
            else:
                if url == "":
                    count_kp_fn = count_kp_fn+1
                else:
                    count_kp_fp = count_kp_fp+1

        # calculate rate of false factchecks
        kp_fp = count_kp_fp/(count_fcExists+count_noFc)
        # calculate precision
        kp_pr = count_kp_tp/(count_kp_tp+count_kp_fp)
        # calculate Specitivity
        if count_noFc>0:
            kp_tn = count_kp_tn/count_noFc
        else:
            kp_tn = 1.
        if count_fcExists>0:
            # calculate Recall or Sensitivity, respectively
            kp_tp = count_kp_tp/count_fcExists
            # calculate false negatives
            kp_fn = count_kp_fn/count_fcExists
        else:
            kp_tp = 1.
            kp_fn = 1.

        logger = logging.getLogger()
        logger.setLevel(logging.INFO)
        logger.info('Precision (How much of the found factchecks are correct) for FactCheck Search: {}'.format(kp_pr))
        logger.info('Recall (Sensitivity, how much of the factchecks were found) for FactCheck Search: {}'.format(kp_tp))
        logger.info('Specifity (if no factcheck was found, how much of them are really without existing factcheck): {}'.format(kp_tn))
        logger.info('False factchecks found: {}'.format(kp_fp))
        logger.info('Existing Factcheck not found: {}'.format(kp_fn))
def test_post_tags_for_item():
    # pre-stuff
    os.environ["STAGE"] = "dev"

    with Session() as session:

        # create item
        item = Item()
        item.content = "https://corona-transition.org/rki-bestatigt-covid-19-sterblichkeitsrate-von-0-01-prozent-in" \
            "-deutschland?fbclid=IwAR2vLIkW_3EejFaeC5_wC_410uKhN_WMpWDMAcI-dF9TTsZ43MwaHeSl4n8%22 "
        item.language = "de"
        item = item_handler.create_item(item, session)

        # store a fact check
        event = {
            "item": {
                "id": item.id,
                "content": item.content,
                "language": item.language,
            },
            "Tags": ["RKI", "Covid", "Corona Transition"]
        }
        context = ""
        EnrichItem.store_itemtags(event, context)

        # create event
        event = {"pathParameters": {"item_id": item.id}}

        response = GetTags.get_tags_for_item(event, context)
        body = response['body']
        tags = json.loads(body)['Tags']
        assert tags == ['RKI', 'Covid', 'Corona Transition']

        # create event with 1 already existing tag and 1 new tag
        event = {
            "pathParameters": {
                "item_id": item.id
            },
            "body": json.dumps({"tags": ['RKI', 'Covid-19']})
        }

        response = GetTags.post_tags_for_item(event, context)
        body = response['body']
        tags_added = json.loads(body)['added new tags']
        tags_counter_increased = json.loads(body)['increased tag counter']
        assert tags_added == ['Covid-19']
        assert len(tags_counter_increased) == 1
        assert 'RKI' in tags_counter_increased
        assert 'Covid-19' not in tags_counter_increased

        response = GetTags.get_tags_for_item(event, context)
        body = response['body']
        tags = json.loads(body)['Tags']
        assert tags == ['RKI', 'Covid', 'Corona Transition', 'Covid-19']
        assert tags != ['Covid', 'Corona Transition', 'Covid-19', 'RKI']

        # Check counts: RKI posted twice, all other once
        assert session.query(ItemTag).join(Tag).filter(
            Tag.tag == 'RKI').count() == 2
        assert session.query(ItemTag).join(Tag).filter(
            Tag.tag == 'Covid').count() == 1
        assert session.query(ItemTag).join(Tag).filter(
            Tag.tag == 'Corona Transition').count() == 1
        assert session.query(ItemTag).join(Tag).filter(
            Tag.tag == 'Covid-19').count() == 1
def submit_item(event, context):
    client = boto3.client('stepfunctions', region_name="eu-central-1")

    helper.log_method_initiated("Item submission", event, logger)

    with Session() as session:

        try:
            body = event['body']

            if isinstance(body, str):
                body_dict = json.loads(body)
            else:
                body_dict = body
            content = body_dict["content"]
            del body_dict["content"]

            if "type" in body_dict:
                type = body_dict["type"]
                del body_dict["type"]
            else:
                type = None

            if "item_type_id" in body_dict:
                item_type_id = body_dict["item_type_id"]
                del body_dict["item_type_id"]
            else:
                item_type_id = None

            if "item" in body_dict:
                del body_dict["item"]

            submission = Submission()
            helper.body_to_object(body_dict, submission)
            # add ip address
            ip_address = event['requestContext']['identity']['sourceIp']
            setattr(submission, 'ip_address', ip_address)

            try:
                # Item already exists, item_id in submission is the id of the found item
                item = item_handler.get_item_by_content(content, session)
                submission.item_id = item.id
                new_item_created = False

            except Exception:
                # Item does not exist yet, item_id in submission is the id of the newly created item
                item = Item()
                item.content = content
                item.item_type_id = item_type_id
                item.type = type
                item = item_handler.create_item(item, session)
                new_item_created = True

                if content:
                    str_urls = re.findall(
                        'http[s]?://(?:[a-zA-ZäöüÄÖÜ]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
                        content)
                    url_handler.prepare_and_store_urls(item, str_urls, session)

                submission.item_id = item.id
                submission.status = item.status

            # Create submission
            submission_handler.create_submission_db(submission, session)
            if submission.mail:
                if item.status != 'Unsafe':
                    send_confirmation_mail(submission)

            # Create response
            if item.status == 'Unsafe':
                response = {
                    "statusCode": 403,
                    "headers": {
                        "content-type": "application/json; charset=utf-8",
                        "new-item-created": str(new_item_created)
                    },
                    "body": "Item not valid"
                }
            else:
                response = {
                    "statusCode": 201,
                    "headers": {
                        "content-type": "application/json; charset=utf-8",
                        "new-item-created": str(new_item_created)
                    },
                    "body": json.dumps(item.to_dict())
                }

        except Exception as e:
            logger.error("Couldn't submit item. Exception: %s", e)
            response = {
                "statusCode":
                400,
                "body":
                "Could not create item and/or submission. Check HTTP POST payload. Stacktrace: {}"
                .format(traceback.format_exc())
            }

    ## start SearchFactChecks only for safe items
    if (item.status != 'Unsafe') and (new_item_created == True):
        stage = os.environ['STAGE']
        client.start_execution(
            stateMachineArn=
            'arn:aws:states:eu-central-1:891514678401:stateMachine:SearchFactChecks_new-'
            + stage,
            name='SFC_' + item.id,
            input="{\"item\":{"
            "\"id\":\"" + item.id + "\","
            "\"content\":\"" + remove_control_characters(item.content) +
            "\" } }")

    response_cors = helper.set_cors(response, event)
    return response_cors