import pytest

from dashboard.models import DashboardLayout


@pytest.mark.django_db
class TestLayout(object):

    @pytest.mark.unit
    def test_add_user(self, add_user_with_permissions):
        """ Check that when new user is created, layout for him is created too """
        username = "username"
        password = "pro100ton"

        user = add_user_with_permissions(username=username, password=password)

        layout = DashboardLayout.objects.get(user=user)

    @pytest.mark.unit
    def test_update_user(self, add_user_with_permissions):
        """ Check that when user is updated, no new layout is created """
        username = "username"
        password = "pro100ton"

        user = add_user_with_permissions(username=username, password=password)

        assert DashboardLayout.objects.filter(user=user).count() == 1

        user.email = "name@name.com"
        user.save()

        assert DashboardLayout.objects.filter(user=user).count() == 1
