-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
# put your pytest fixtures here | ||
import pytest | ||
from pretix.base.models import Organizer, Event | ||
from django.utils.timezone import now | ||
|
||
@pytest.fixture | ||
def event(db): | ||
organizer = Organizer.objects.create(name="Test Organizer", slug="test-organizer") | ||
event = Event.objects.create( | ||
organizer=organizer, | ||
name="Test Event", | ||
slug="test-event", | ||
live=True, | ||
date_from=now(), | ||
) | ||
return event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,95 @@ | ||
def test_empty(): | ||
from exhibitor.apps import ExhibitorConfig | ||
assert ExhibitorConfig.name == 'exhibitor' | ||
assert isinstance(ExhibitorConfig.verbose_name, str) | ||
assert isinstance(ExhibitorConfig.description, str) | ||
assert isinstance(ExhibitorConfig.version, str) | ||
assert ExhibitorConfig.author == 'OpenCraft' | ||
import pytest | ||
from exhibitors.models import ExhibitorInfo | ||
from django.core.files.uploadedfile import SimpleUploadedFile | ||
|
||
@pytest.mark.django_db | ||
def test_create_exhibitor_info(event): | ||
# CREATE: Simulate an image upload and create an exhibitor | ||
logo = SimpleUploadedFile("test_logo.jpg", b"file_content", content_type="image/jpeg") | ||
|
||
exhibitor = ExhibitorInfo.objects.create( | ||
event=event, | ||
name="Test Exhibitor", | ||
description="This is a test exhibitor", | ||
url="http://testexhibitor.com", | ||
email="[email protected]", | ||
logo=logo, | ||
lead_scanning_enabled=True | ||
) | ||
|
||
# Verify the exhibitor was created and the fields are correct | ||
assert exhibitor.name == "Test Exhibitor" | ||
assert exhibitor.description == "This is a test exhibitor" | ||
assert exhibitor.url == "http://testexhibitor.com" | ||
assert exhibitor.email == "[email protected]" | ||
assert exhibitor.logo.name == "exhibitors/logos/Test Exhibitor/test_logo.jpg" | ||
assert exhibitor.lead_scanning_enabled is True | ||
|
||
@pytest.mark.django_db | ||
def test_read_exhibitor_info(event): | ||
# CREATE an exhibitor first to test reading | ||
logo = SimpleUploadedFile("test_logo.jpg", b"file_content", content_type="image/jpeg") | ||
exhibitor = ExhibitorInfo.objects.create( | ||
event=event, | ||
name="Test Exhibitor", | ||
description="This is a test exhibitor", | ||
url="http://testexhibitor.com", | ||
email="[email protected]", | ||
logo=logo, | ||
lead_scanning_enabled=True | ||
) | ||
|
||
# READ: Fetch the exhibitor from the database and verify fields | ||
exhibitor_from_db = ExhibitorInfo.objects.get(id=exhibitor.id) | ||
assert exhibitor_from_db.name == "Test Exhibitor" | ||
assert exhibitor_from_db.description == "This is a test exhibitor" | ||
assert exhibitor_from_db.url == "http://testexhibitor.com" | ||
assert exhibitor_from_db.email == "[email protected]" | ||
assert exhibitor_from_db.lead_scanning_enabled is True | ||
|
||
@pytest.mark.django_db | ||
def test_update_exhibitor_info(event): | ||
# CREATE an exhibitor first to test updating | ||
logo = SimpleUploadedFile("test_logo.jpg", b"file_content", content_type="image/jpeg") | ||
exhibitor = ExhibitorInfo.objects.create( | ||
event=event, | ||
name="Test Exhibitor", | ||
description="This is a test exhibitor", | ||
url="http://testexhibitor.com", | ||
email="[email protected]", | ||
logo=logo, | ||
lead_scanning_enabled=True | ||
) | ||
|
||
# UPDATE: Modify some fields and save the changes | ||
exhibitor.name = "Updated Exhibitor" | ||
exhibitor.description = "This is an updated description" | ||
exhibitor.lead_scanning_enabled = False | ||
exhibitor.save() | ||
|
||
# Verify the updated fields | ||
updated_exhibitor = ExhibitorInfo.objects.get(id=exhibitor.id) | ||
assert updated_exhibitor.name == "Updated Exhibitor" | ||
assert updated_exhibitor.description == "This is an updated description" | ||
assert updated_exhibitor.lead_scanning_enabled is False | ||
|
||
@pytest.mark.django_db | ||
def test_delete_exhibitor_info(event): | ||
# CREATE an exhibitor first to test deleting | ||
logo = SimpleUploadedFile("test_logo.jpg", b"file_content", content_type="image/jpeg") | ||
exhibitor = ExhibitorInfo.objects.create( | ||
event=event, | ||
name="Test Exhibitor", | ||
description="This is a test exhibitor", | ||
url="http://testexhibitor.com", | ||
email="[email protected]", | ||
logo=logo, | ||
lead_scanning_enabled=True | ||
) | ||
|
||
# DELETE: Delete the exhibitor and verify it no longer exists | ||
exhibitor_id = exhibitor.id | ||
exhibitor.delete() | ||
|
||
with pytest.raises(ExhibitorInfo.DoesNotExist): | ||
ExhibitorInfo.objects.get(id=exhibitor_id) |