from django.contrib.auth import get_user_model
from django.test import Client
from django.urls import reverse
from scrobbles.models import EBirdCSVImport

User = get_user_model()


class TestBirdingLocationViews:
    def test_birding_location_list_anonymous(self, db):
        client = Client()
        response = client.get(reverse("birds:birding_location_list"))
        assert response.status_code == 200

    def test_bird_list_anonymous(self, db):
        client = Client()
        response = client.get(reverse("birds:bird_list"))
        assert response.status_code == 200


class TestBirdingCSVImportViews:
    def test_upload_view_requires_login(self, db):
        client = Client()
        response = client.get(reverse("birds:csv-upload"))
        assert response.status_code == 302

    def test_import_detail_view_requires_login(self, db):
        client = Client()
        response = client.get(
            reverse("birds:csv_import_detail", kwargs={"slug": "00000000-0000-0000-0000-000000000001"})
        )
        assert response.status_code == 302

    def test_import_detail_authenticated(self, db):
        user = User.objects.create(email="birder@example.com")
        client = Client()
        client.force_login(user)
        imp = EBirdCSVImport.objects.create(user=user)
        response = client.get(
            reverse("scrobbles:ebird-csv-import-detail", kwargs={"slug": imp.uuid})
        )
        assert response.status_code == 200
