import pytest
from django.urls import reverse


@pytest.mark.django_db()
def test_authenticate(user, client, program):
    r = client.get(reverse("login"))
    assert r.status_code == 200
    assert b"id_username" in r.content
    r = client.post(reverse("login"), kwargs={"username": "foo", "password": "bar"})
    assert b"errorlist" in r.content
    assert client.login(username="user1", password="bar")


@pytest.mark.django_db()
def test_profile_programs(user, client, program):
    client.force_login(user)
    r = client.get(reverse("profile"))
    assert program.title not in r.content.decode("utf-8")
    user.groups.add(program.editors)
    r = client.get(reverse("profile"))
    assert program.title in r.content.decode("utf-8")
