"""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()
        notif, un, self.test_user = map(
            db.session.merge, (notif, un, self.test_user))

        self.assertTrue(notif in self.test_user.notifications)

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

        self.assertFalse(notif in self.test_user.notifications)
        deleted = UserNotification.query.filter_by(
            user_id=TEST_USER_ID, notification_id=notif_id).first()
        self.assertFalse(deleted)

@@ -1833,16 +1833,67 @@
 (resp)%0A%0A
+        # confirm the UserNotification was deleted%0A
         
@@ -1960,18 +1960,25 @@
     
-deleted = 
+self.assertFalse(
 User
@@ -2078,39 +2078,133 @@
 st()
-%0A        self.assertFalse(deleted
+)%0A%0A        # confirm the Notification was NOT deleted%0A        self.assertTrue(Notification.query.filter_by(name=%22test%22).first()
 )%0A

extend deletion unit tests