from django.urls import reverse
from userservice.user import UserService
from myuw.models import MigrationPreference, User
from myuw.test import get_request_with_user
from myuw.test.api import MyuwApiTest, VALIDATE, OVERRIDE


class TestBannerMessage(MyuwApiTest):

    def test_close_banner_msg(self):
        self.set_user('bill')
        resp = self.get_response_by_reverse('myuw_close_banner_message')
        self.assertEqual(resp.content, b'{"done": true}')

        # remove the entry in DB (delete CASCADE)
        obj = User.objects.get(uwnetid='bill')
        obj.delete()

        resp = self.get_response_by_reverse('myuw_close_banner_message')
        self.assertEqual(resp.content, b'{"done": true}')

        user = User.objects.get(uwnetid='bill')
        self.assertIsNotNone(str(user))
        pref = MigrationPreference.objects.get(user=user)
        self.assertIsNotNone(str(pref))

    def test_close_banner_msg_error_case(self):
        self.set_user('0000')
        resp = self.get_response_by_reverse('myuw_close_banner_message')
        self.assertEqual(resp.content, b'Unrecognized user')

    def test_turn_off_pop_up(self):
        self.set_user('bill')
        resp = self.get_response_by_reverse('myuw_turn_off_tour_popup')
        self.assertEqual(resp.content, b'{"done": true}')

    def test_turn_off_pop_up_error_case(self):
        self.set_user('0000')
        resp = self.get_response_by_reverse('myuw_turn_off_tour_popup')
        self.assertEqual(resp.content, b'Unrecognized user')

    def test_close_banner_msg_when_override(self):
        with self.settings(DEBUG=False,
                           MYUW_DISABLE_ACTIONS_WHEN_OVERRIDE=True):
            self.set_user('javerage')
            self.set_userservice_override("bill")
            self.assertEquals(UserService().get_override_user(), "bill")
            resp = self.get_response_by_reverse('myuw_close_banner_message')
            self.assertEqual(resp.status_code, 401)

    def test_turn_off_pop_up_when_override(self):
        with self.settings(DEBUG=False,
                           MYUW_DISABLE_ACTIONS_WHEN_OVERRIDE=True):
            self.set_user('javerage')
            self.set_userservice_override("bill")
            self.assertEquals(UserService().get_override_user(), "bill")
            resp = self.get_response_by_reverse('myuw_turn_off_tour_popup')
            self.assertEqual(resp.status_code, 401)

@@ -905,34 +905,34 @@
    def test_
-close_bann
+invalid_us
 er_msg_error
@@ -966,32 +966,210 @@
 et_user('0000')%0A
+        err_msg = (b'Your data is not in Person Web Service. '%0A                   b'If you have just created your UW NetID, '%0A                   b'please come back in an hour.')%0A
         resp = s
@@ -1268,95 +1268,15 @@
 nt, 
-b'Unrecognized user')%0A%0A    def test_turn_off_pop_up(self):%0A        self.set_user('bill'
+err_msg
 )%0A  
@@ -1384,33 +1384,23 @@
 ontent, 
-b'%7B%22done%22: true%7D'
+err_msg
 )%0A%0A    d
@@ -1422,27 +1422,16 @@
 f_pop_up
-_error_case
 (self):%0A
@@ -1445,36 +1445,36 @@
  self.set_user('
-0000
+bill
 ')%0A        resp 
@@ -1577,25 +1577,22 @@
 , b'
-Unrecognized user
+%7B%22done%22: true%7D
 ')%0A%0A

fix test