Beispiel #1
0
def test_update():
    mock_model = Model(schema=MockSchema, loader=mock_loader, saver=mock_saver)
    mock_model.load()

    mock_model.update('2', file='sunder2.wad')
    assert(mock_model.find('2').file == 'sunder2.wad')
    # other attributes should be the same
    assert(mock_model.find_by(id='2', name='sunder', file='sunder2.wad') != None)

    # throw error when trying to update item that doesnt exist
    with case.assertRaises(KeyError):
        mock_model.update('4', name='key error should be thrown')
Beispiel #2
0
def test_create():
    mock_model = Model(schema=MockSchema, loader=mock_loader, saver=mock_saver)
    mock_model.load()

    wad = {'name':'foo', 'file':'foo.wad'}
    id = mock_model.create(**wad)
    assert(asdict(mock_model.find(id)).items() >= wad.items())

    wad2 = {'name':'bar', 'file':'bar.wad'}
    wad2metadata = { 'id': '1234', 'title': 'Bar', 'description': 'This is bar.wad!' }
    id2 = mock_model.create(**wad2, **wad2metadata)
    assert all([key in asdict(mock_model.find(id2)) for key in {**wad2, **wad2metadata}])
Beispiel #3
0
def test_delete():
    mock_model = Model(schema=MockSchema, loader=mock_loader, saver=mock_saver)
    mock_model.load()

    deleted = mock_model.delete('2')
    assert all([key in asdict(deleted) for key in mock_data.get('2')])

    with case.assertRaises(KeyError):
        mock_model.find('2')
Beispiel #4
0
def test_subscribe():
    mock_model = Model(schema=MockSchema, loader=mock_loader)
    mock_func1 = mock.MagicMock()
    mock_func2 = mock.MagicMock()

    unsubscribe = mock_model.subscribe(mock_func1)
    mock_model.subscribe(mock_func2)

    mock_model.broadcast('data')
    mock_func1.assert_called_with('data')
    mock_func2.assert_called_with('data')

    # if unsubscribed, mock_func1 should not be called again
    unsubscribe()
    # mock_func2 should still function as usual
    mock_func2.reset_mock()
    mock_model.broadcast('data')
    mock_func1.assert_called_once_with('data')
    mock_func2.assert_called_with('data')
Beispiel #5
0
def test_saver():
    mock_model = Model(schema=MockSchema, loader=mock_loader, saver=mock_saver)
    mock_model.load()

    wad = {'name':'foo', 'file':'foo.wad' }
    id = mock_model.create(**wad)
    json_string = mock_model.save(id)

    assert all([key in json.loads(json_string) for key in {'id':id, **wad}])
Beispiel #6
0
def test_find_by():
    mock_model = Model(schema=MockSchema, loader=mock_loader)
    mock_model.load()

    # Finding by one attribute
    item = mock_model.find_by(name='going down')
    assert all([key in asdict(item) for key in mock_data.get('0')])

    # Finding by multiple attributes
    item = mock_model.find_by(name='miasma', file='miasma.wad')
    assert all([key in asdict(item) for key in mock_data.get('1')])

    # Returns None if not found
    assert(mock_model.find_by(name='should not be found', file='miasma.wad', random='none') == None)
Beispiel #7
0
def test_find():
    mock_model = Model(schema=MockSchema, loader=mock_loader)
    mock_model.load()

    assert all([key in asdict(mock_model.find('0')) for key in mock_data.get('0')])
Beispiel #8
0
def test_loader():
    mock_model = Model(schema=MockSchema, loader=mock_loader)
    mock_model.load()

    for item in mock_model.all():
        assert all([key in asdict(item) for key in mock_data[item.id]])
Beispiel #9
0
def test_instance_creation():
    mock_model = Model(schema=MockSchema)
Beispiel #10
0
 def __init__(self):
     Model.__init__(self, schema=Iwad)
     iwad_loader_worker_wrapper([self.loaded], [self.loaded_all])
Beispiel #11
0
 def __init__(self):
     Model.__init__(self, schema=Wad, saver=wad_saver_worker_wrapper)
     self.wad_dir_files = []
     self.current_idgames_wad_id = None
     self.load_ordered_files = []
     wad_loader_worker_wrapper([self.loaded], [self.loaded_all])
Beispiel #12
0
 def __init__(self):
     Model.__init__(self, schema=Category)
     category_loader_worker_wrapper([self.loaded], [self.loaded_all])
Beispiel #13
0
 def __init__(self):
     Model.__init__(self, schema=SourcePort)
     source_port_loader_worker_wrapper([self.loaded], [self.loaded_all])