"""
This file is part of LiberaForms.

# SPDX-FileCopyrightText: 2021 LiberaForms.org
# SPDX-License-Identifier: AGPL-3.0-or-later
"""

import os
import ast
import pytest
from flask import g
from liberaforms.utils import utils
from .utils import login, logout


class TestAdmin():
    """ Tests admin's admin preferences
    """
    def test_toggle_new_user_notification(self, users, admin_client, anon_client):
        """ Tests admin permission
            Tests POST only
            Tests toggle bool
        """
        url = "/admin/toggle-newuser-notification"
        response = anon_client.post(
                        url,
                        follow_redirects=True,
                    )
        assert response.status_code == 200
        html = response.data.decode()
        assert '<!-- site_index_page -->' in html
        #login(admin_client, users['admin'])
        response = admin_client.get(
                        url,
                        follow_redirects=True,
                    )
        assert response.status_code == 405
        notification = g.current_user.admin["notifyNewUser"]
        response = admin_client.post(url)
        assert response.status_code == 200
        assert g.current_user.admin["notifyNewUser"] != notification
        assert type(g.current_user.admin["notifyNewUser"]) == type(bool())

    def test_toggle_new_form_notification(self, users, admin_client, anon_client):
        """ Tests admin permission
            Tests POST only
            Tests toggle bool
        """
        url = "/admin/toggle-newform-notification"
        response = anon_client.post(
                        url,
                        follow_redirects=True,
                    )
        assert response.status_code == 200
        html = response.data.decode()
        assert '<!-- site_index_page -->' in html

        response = admin_client.get(
                        url,
                        follow_redirects=True,
                    )
        #print(utils.print_obj_values(g.current_user))
        #assert g.current_user.username == users['admin']['username']
        assert response.status_code == 405
        notification = g.current_user.admin["notifyNewForm"]
        response = admin_client.post(url)
        assert response.status_code == 200
        assert g.current_user.admin["notifyNewForm"] != notification
        assert type(g.current_user.admin["notifyNewForm"]) == type(bool())

    def test_toggle_newuser_uploadsenabled(self, users, admin_client, anon_client):
        pass

"""
This file is part of LiberaForms.

# SPDX-FileCopyrightText: 2021 LiberaForms.org
# SPDX-License-Identifier: AGPL-3.0-or-later
"""

import os
import ast
import pytest
from flask import g
from liberaforms.utils import utils
from .utils import login, logout


class TestAdmin():
    """ Tests admin's admin preferences
    """
    def test_toggle_new_user_notification(self, users, admin_client, anon_client):
        """ Tests admin permission
            Tests POST only
            Tests toggle bool
        """
        url = "/admin/toggle-newuser-notification"
        response = anon_client.post(
                        url,
                        follow_redirects=True,
                    )
        assert response.status_code == 200
        html = response.data.decode()
        assert '<!-- site_index_page -->' in html
        #login(admin_client, users['admin'])
        response = admin_client.get(
                        url,
                        follow_redirects=True,
                    )
        assert response.status_code == 405
        notification = g.current_user.admin["notifyNewUser"]
        response = admin_client.post(url)
        assert response.status_code == 200
        assert g.current_user.admin["notifyNewUser"] != notification
        assert type(g.current_user.admin["notifyNewUser"]) == type(bool())

    def test_toggle_new_form_notification(self, users, admin_client, anon_client):
        """ Tests admin permission
            Tests POST only
            Tests toggle bool
        """
        url = "/admin/toggle-newform-notification"
        response = anon_client.post(
                        url,
                        follow_redirects=True,
                    )
        assert response.status_code == 200
        html = response.data.decode()
        assert '<!-- site_index_page -->' in html

        response = admin_client.get(
                        url,
                        follow_redirects=True,
                    )
        #print(utils.print_obj_values(g.current_user))
        #assert g.current_user.username == users['admin']['username']
        assert response.status_code == 405
        notification = g.current_user.admin["notifyNewForm"]
        response = admin_client.post(url)
        assert response.status_code == 200
        assert g.current_user.admin["notifyNewForm"] != notification
        assert type(g.current_user.admin["notifyNewForm"]) == type(bool())

    def test_toggle_newuser_uploadsenabled(self, users, admin_client, anon_client):
        pass

This file is part of LiberaForms.  # SPDX-FileCopyrightText: 2021 LiberaForms.org # SPDX-License-Identifier: AGPL-3.0-or-later Tests admin's admin preferences Tests admin permission             Tests POST only             Tests toggle bool #login(admin_client, users['admin']) Tests admin permission             Tests POST only             Tests toggle bool #print(utils.print_obj_values(g.current_user)) #assert g.current_user.username == users['admin']['username']