|
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +def test_conference_create(session): |
| 5 | + from dispatch.conference.service import create |
| 6 | + from dispatch.conference.models import ConferenceCreate |
| 7 | + |
| 8 | + resource_id = "000000" |
| 9 | + resource_type = "resourcetype" |
| 10 | + weblink = "https://www.example.com" |
| 11 | + conference_id = "12345" |
| 12 | + conference_challenge = "a0v0a0v9a" |
| 13 | + |
| 14 | + conference_in = ConferenceCreate( |
| 15 | + resource_id=resource_id, |
| 16 | + resource_type=resource_type, |
| 17 | + weblink=weblink, |
| 18 | + conference_id=conference_id, |
| 19 | + conference_challenge=conference_challenge, |
| 20 | + ) |
| 21 | + conference = create(db_session=session, conference_in=conference_in) |
| 22 | + assert conference |
| 23 | + assert conference.resource_id == "000000" |
| 24 | + assert conference.resource_type == "resourcetype" |
| 25 | + assert conference.weblink == "https://www.example.com" |
| 26 | + assert conference.conference_id == "12345" |
| 27 | + assert conference.conference_challenge == "a0v0a0v9a" |
| 28 | + |
| 29 | + |
| 30 | +def test_conference_get(session, conference): |
| 31 | + from dispatch.conference.service import get |
| 32 | + |
| 33 | + test_conference = get(db_session=session, conference_id=conference.id) |
| 34 | + assert test_conference.id == conference.id |
| 35 | + assert test_conference.conference_challenge == conference.conference_challenge |
| 36 | + |
| 37 | + |
| 38 | +def test_conference_get_by_resource_id(session, conference): |
| 39 | + from dispatch.conference.service import get_by_resource_id |
| 40 | + |
| 41 | + test_conference = get_by_resource_id(db_session=session, resource_id=conference.resource_id) |
| 42 | + |
| 43 | + assert test_conference.resource_id == conference.resource_id |
| 44 | + assert test_conference.conference_challenge == conference.conference_challenge |
| 45 | + |
| 46 | + |
| 47 | +def test_conference_get_by_resource_type(session, conference): |
| 48 | + """The service method returns a list of conferences that match a given resource type. We'll test |
| 49 | + to ensure that the first and last items returned match the desired resource type.""" |
| 50 | + from dispatch.conference.service import get_by_resource_type |
| 51 | + |
| 52 | + conferences = get_by_resource_type(db_session=session, resource_type=conference.resource_type) |
| 53 | + |
| 54 | + assert conferences[0].resource_type == conference.resource_type |
| 55 | + assert conferences[-1].resource_type == conference.resource_type |
| 56 | + |
| 57 | + |
| 58 | +def test_conference_get_by_conference_id(session, conference): |
| 59 | + from dispatch.conference.service import get_by_conference_id |
| 60 | + |
| 61 | + test_conference = get_by_conference_id(session, conference.conference_id) |
| 62 | + |
| 63 | + assert test_conference.conference_id == conference.conference_id |
| 64 | + assert test_conference.conference_challenge == conference.conference_challenge |
| 65 | + |
| 66 | + |
| 67 | +def test_conference_get_by_incident_id(session, conference): |
| 68 | + from dispatch.conference.service import get_by_incident_id |
| 69 | + |
| 70 | + test_conference = get_by_incident_id(db_session=session, incident_id=conference.incident.id) |
| 71 | + |
| 72 | + assert test_conference.incident.id == conference.incident.id |
| 73 | + assert test_conference.conference_challenge == conference.conference_challenge |
| 74 | + |
| 75 | + |
| 76 | +def test_conference_get_all(session, conferences): |
| 77 | + """The test should not rely on the conferences created earlier, to pass. |
| 78 | + Therefore, we pass "conferences" as an argument, to manually create several in the DB. |
| 79 | + """ |
| 80 | + |
| 81 | + from dispatch.conference.service import get_all |
| 82 | + |
| 83 | + test_conferences = get_all(db_session=session).all() |
| 84 | + |
| 85 | + assert len(test_conferences) > 1 |
0 commit comments