-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_main.py
More file actions
106 lines (89 loc) · 3.68 KB
/
test_main.py
File metadata and controls
106 lines (89 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import re
import pytest
from django.core.files.uploadedfile import SimpleUploadedFile
from exhibition.models import ExhibitorInfo
@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="test@example.com",
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 == "test@example.com"
assert re.fullmatch(
r"exhibitors/logos/Test Exhibitor/test_logo(?:_[A-Za-z0-9]{7})?\.jpg",
exhibitor.logo.name,
)
assert exhibitor.lead_scanning_enabled is True
assert exhibitor.status == "pending"
@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="test@example.com",
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 == "test@example.com"
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="test@example.com",
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="test@example.com",
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)