<commit_before>"""Unit test module for Notification and UserNotification logic"""
from flask_webtest import SessionScope

from portal.extensions import db
from portal.models.notification import Notification, UserNotification
from tests import TestCase, TEST_USER_ID


class TestNotification(TestCase):
    """Notification and UserNotification tests"""

    def test_notification_from_json(self):
        data = {"name": "test", "content": "Test Alert!"}
        notif = Notification.from_json(data)
        with SessionScope(db):
            db.session.add(notif)
            db.session.commit()
        notif = db.session.merge(notif)

        self.assertTrue(notif.id)
        self.assertTrue(notif.created_at)

    def test_notification_as_json(self):
        notif = Notification(name="test", content="Test Alert!")
        with SessionScope(db):
            db.session.add(notif)
            db.session.commit()
        notif = db.session.merge(notif)

        data = notif.as_json()
        self.assertEquals(data['name'], 'test')
        self.assertTrue(data['created_at'])

    def test_usernotification_delete(self):
        notif = Notification(name="test", content="Test Alert!")
        with SessionScope(db):
            db.session.add(notif)
            db.session.commit()
        notif = db.session.merge(notif)
        notif_id = notif.id

        un = UserNotification(user_id=TEST_USER_ID, notification_id=notif_id)
        with SessionScope(db):
            db.session.add(un)
            db.session.commit()<commit_msg>adding addtl tests for GET<commit_after>"""Unit test module for Notification and UserNotification logic"""
from flask_webtest import SessionScope

from portal.extensions import db
from portal.models.notification import Notification, UserNotification
from tests import TestCase, TEST_USER_ID


class TestNotification(TestCase):
    """Notification and UserNotification tests"""

    def test_notification_from_json(self):
        data = {"name": "test", "content": "Test Alert!"}
        notif = Notification.from_json(data)
        with SessionScope(db):
            db.session.add(notif)
            db.session.commit()
        notif = db.session.merge(notif)

        self.assertTrue(notif.id)
        self.assertTrue(notif.created_at)

    def test_notification_get(self):
        notif = Notification(name="test", content="Test Alert!")
        with SessionScope(db):
            db.session.add(notif)
            db.session.commit()
        notif = db.session.merge(notif)

        un = UserNotification(user_id=TEST_USER_ID, notification_id=notif.id)
        with SessionScope(db):
            db.session.add(un)
            db.session.commit()

        self.login()
        resp = self.client.get(
            '/api/user/{}/notification'.format(TEST_USER_ID))
        self.assert200(resp)

        self.assertEquals(len(resp.json['notifications']), 1)
        self.assertEquals(resp.json['notifications'][0]['name'], 'test')
        self.assertTrue(resp.json['notifications'][0]['created_at'])

    def test_usernotification_delete(self):
        notif = Notification(name="test", content="Test Alert!")
        with SessionScope(db):
            db.session.add(notif)
            db.session.commit()
        notif = db.session.merge(notif)
        notif_id = notif.id

        un = UserNotification(user_id=TEST_USER_ID, notification_id=notif_id)
        with SessionScope(db):
            db.session.add(un)
            db.session.commit()
{'fraction_non_alphanumeric': 0.11439220183486239, 'fraction_numerical': 0.0017201834862385322, 'mean_word_length': 2.8552486187845303, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3278731', 'n_tokens_mistral': 1013, 'n_tokens_neox': 979, 'n_words': 191}