forked from openlp/openlp
Fix projector tests
This commit is contained in:
parent
b1febaa452
commit
f2cccb90ae
@ -22,26 +22,3 @@
|
||||
"""
|
||||
Module-level functions for the functional test suite
|
||||
"""
|
||||
|
||||
import os
|
||||
from tests.functional import patch
|
||||
|
||||
from openlp.core.common import is_win
|
||||
|
||||
from .test_projectordb import tmpfile
|
||||
|
||||
|
||||
def setUp():
|
||||
if not is_win():
|
||||
# Wine creates a sharing violation during tests. Ignore.
|
||||
try:
|
||||
os.remove(tmpfile)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def tearDown():
|
||||
"""
|
||||
Ensure test suite has been cleaned up after tests
|
||||
"""
|
||||
patch.stopall()
|
||||
|
@ -31,9 +31,7 @@ from unittest import TestCase
|
||||
from openlp.core.lib.projector.db import Projector, ProjectorDB, ProjectorSource
|
||||
|
||||
from tests.functional import MagicMock, patch
|
||||
from tests.resources.projector.data import TEST1_DATA, TEST2_DATA, TEST3_DATA
|
||||
|
||||
tmpfile = '/tmp/openlp-test-projectordb.sql'
|
||||
from tests.resources.projector.data import TEST_DB, TEST1_DATA, TEST2_DATA, TEST3_DATA
|
||||
|
||||
|
||||
def compare_data(one, two):
|
||||
@ -89,9 +87,9 @@ class TestProjectorDB(TestCase):
|
||||
Set up anything necessary for all tests
|
||||
"""
|
||||
with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url:
|
||||
if os.path.exists(tmpfile):
|
||||
os.unlink(tmpfile)
|
||||
mocked_init_url.return_value = 'sqlite:///%s' % tmpfile
|
||||
if os.path.exists(TEST_DB):
|
||||
os.unlink(TEST_DB)
|
||||
mocked_init_url.return_value = 'sqlite:///%s' % TEST_DB
|
||||
self.projector = ProjectorDB()
|
||||
|
||||
def tearDown(self):
|
||||
@ -105,13 +103,13 @@ class TestProjectorDB(TestCase):
|
||||
Test find record by IP
|
||||
"""
|
||||
# GIVEN: Record entries in database
|
||||
add_records(self.projector, [TEST1_DATA, TEST2_DATA])
|
||||
add_records(self.projector, [Projector(**TEST1_DATA), Projector(**TEST2_DATA)])
|
||||
|
||||
# WHEN: Search for record using IP
|
||||
record = self.projector.get_projector_by_ip(TEST2_DATA.ip)
|
||||
record = self.projector.get_projector_by_ip(TEST2_DATA['ip'])
|
||||
|
||||
# THEN: Verify proper record returned
|
||||
self.assertTrue(compare_data(TEST2_DATA, record),
|
||||
self.assertTrue(compare_data(Projector(**TEST2_DATA), record),
|
||||
'Record found should have been test_2 data')
|
||||
|
||||
def find_record_by_name_test(self):
|
||||
@ -119,13 +117,13 @@ class TestProjectorDB(TestCase):
|
||||
Test find record by name
|
||||
"""
|
||||
# GIVEN: Record entries in database
|
||||
add_records(self.projector, [TEST1_DATA, TEST2_DATA])
|
||||
add_records(self.projector, [Projector(**TEST1_DATA), Projector(**TEST2_DATA)])
|
||||
|
||||
# WHEN: Search for record using name
|
||||
record = self.projector.get_projector_by_name(TEST2_DATA.name)
|
||||
record = self.projector.get_projector_by_name(TEST2_DATA['name'])
|
||||
|
||||
# THEN: Verify proper record returned
|
||||
self.assertTrue(compare_data(TEST2_DATA, record),
|
||||
self.assertTrue(compare_data(Projector(**TEST2_DATA), record),
|
||||
'Record found should have been test_2 data')
|
||||
|
||||
def record_delete_test(self):
|
||||
@ -133,14 +131,14 @@ class TestProjectorDB(TestCase):
|
||||
Test record can be deleted
|
||||
"""
|
||||
# GIVEN: Record in database
|
||||
add_records(self.projector, [TEST3_DATA, ])
|
||||
record = self.projector.get_projector_by_ip(TEST3_DATA.ip)
|
||||
add_records(self.projector, [Projector(**TEST3_DATA), ])
|
||||
record = self.projector.get_projector_by_ip(TEST3_DATA['ip'])
|
||||
|
||||
# WHEN: Record deleted
|
||||
self.projector.delete_projector(record)
|
||||
|
||||
# THEN: Verify record not retrievable
|
||||
found = self.projector.get_projector_by_ip(TEST3_DATA.ip)
|
||||
found = self.projector.get_projector_by_ip(TEST3_DATA['ip'])
|
||||
self.assertFalse(found, 'test_3 record should have been deleted')
|
||||
|
||||
def record_edit_test(self):
|
||||
@ -148,34 +146,35 @@ class TestProjectorDB(TestCase):
|
||||
Test edited record returns the same record ID with different data
|
||||
"""
|
||||
# GIVEN: Record entries in database
|
||||
add_records(self.projector, [TEST1_DATA, TEST2_DATA])
|
||||
add_records(self.projector, [Projector(**TEST1_DATA), Projector(**TEST2_DATA)])
|
||||
|
||||
# WHEN: We retrieve a specific record
|
||||
record = self.projector.get_projector_by_ip(TEST1_DATA.ip)
|
||||
record = self.projector.get_projector_by_ip(TEST1_DATA['ip'])
|
||||
record_id = record.id
|
||||
|
||||
# WHEN: Data is changed
|
||||
record.ip = TEST3_DATA.ip
|
||||
record.port = TEST3_DATA.port
|
||||
record.pin = TEST3_DATA.pin
|
||||
record.name = TEST3_DATA.name
|
||||
record.location = TEST3_DATA.location
|
||||
record.notes = TEST3_DATA.notes
|
||||
record.ip = TEST3_DATA['ip']
|
||||
record.port = TEST3_DATA['port']
|
||||
record.pin = TEST3_DATA['pin']
|
||||
record.name = TEST3_DATA['name']
|
||||
record.location = TEST3_DATA['location']
|
||||
record.notes = TEST3_DATA['notes']
|
||||
updated = self.projector.update_projector(record)
|
||||
self.assertTrue(updated, 'Save updated record should have returned True')
|
||||
record = self.projector.get_projector_by_ip(TEST3_DATA.ip)
|
||||
record = self.projector.get_projector_by_ip(TEST3_DATA['ip'])
|
||||
|
||||
# THEN: Record ID should remain the same, but data should be changed
|
||||
self.assertEqual(record_id, record.id, 'Edited record should have the same ID')
|
||||
self.assertTrue(compare_data(TEST3_DATA, record), 'Edited record should have new data')
|
||||
self.assertTrue(compare_data(Projector(**TEST3_DATA), record), 'Edited record should have new data')
|
||||
|
||||
def source_add_test(self):
|
||||
"""
|
||||
Test source entry for projector item
|
||||
"""
|
||||
# GIVEN: Record entries in database
|
||||
self.projector.add_projector(TEST1_DATA)
|
||||
item = self.projector.get_projector_by_id(TEST1_DATA.id)
|
||||
projector1 = Projector(**TEST1_DATA)
|
||||
self.projector.add_projector(projector1)
|
||||
item = self.projector.get_projector_by_id(projector1.id)
|
||||
item_id = item.id
|
||||
|
||||
# WHEN: A source entry is saved for item
|
||||
@ -185,3 +184,4 @@ class TestProjectorDB(TestCase):
|
||||
# THEN: Projector should have the same source entry
|
||||
item = self.projector.get_projector_by_id(item_id)
|
||||
self.assertTrue(compare_source(item.source_list[0], source))
|
||||
|
||||
|
@ -24,26 +24,26 @@ The :mod:`tests.resources.projector.data file contains test data
|
||||
"""
|
||||
|
||||
import os
|
||||
from openlp.core.lib.projector.db import Projector
|
||||
from tempfile import gettempdir
|
||||
|
||||
# Test data
|
||||
TEST_DB = os.path.join('tmp', 'openlp-test-projectordb.sql')
|
||||
TEST_DB = os.path.join(gettempdir(), 'openlp-test-projectordb.sql')
|
||||
|
||||
TEST1_DATA = Projector(ip='111.111.111.111',
|
||||
TEST1_DATA = dict(ip='111.111.111.111',
|
||||
port='1111',
|
||||
pin='1111',
|
||||
name='___TEST_ONE___',
|
||||
location='location one',
|
||||
notes='notes one')
|
||||
|
||||
TEST2_DATA = Projector(ip='222.222.222.222',
|
||||
TEST2_DATA = dict(ip='222.222.222.222',
|
||||
port='2222',
|
||||
pin='2222',
|
||||
name='___TEST_TWO___',
|
||||
location='location two',
|
||||
notes='notes two')
|
||||
|
||||
TEST3_DATA = Projector(ip='333.333.333.333',
|
||||
TEST3_DATA = dict(ip='333.333.333.333',
|
||||
port='3333',
|
||||
pin='3333',
|
||||
name='___TEST_THREE___',
|
||||
|
Loading…
Reference in New Issue
Block a user