Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sak1012 committed Oct 9, 2024
1 parent 9c3575c commit 0109178
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 8 deletions.
16 changes: 15 additions & 1 deletion tests/conftest.py
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
102 changes: 95 additions & 7 deletions tests/test_main.py
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)

0 comments on commit 0109178

Please sign in to comment.