Skip to content

Commit

Permalink
Fixed Workflow and Added Tests (#3)
Browse files Browse the repository at this point in the history
* Fix Workflow

* Added tests
  • Loading branch information
Sak1012 authored Oct 10, 2024
1 parent ef023a7 commit 211514b
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]" psycopg2-binary
pip install isort
- name: Run isort
run: isort --check-only .
working-directory: ./src

flake:
name: flake8
Expand All @@ -64,7 +64,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]" psycopg2-binary
pip install flake8
- name: Run flake8
run: flake8 .
working-directory: ./src
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]" psycopg2-binary
pip install -e ".[dev]" psycopg2-binary pytest
- name: Run tests for exhibitors plugin
run: py.test tests --reruns 3
run: pytest tests --reruns 3
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 211514b

Please sign in to comment.