def test_delete_media(): test_media1 = Game('test_name', 'test_path', 'test_genres', 'test_platform', 'test_mult', 'test-id') test_media2 = Game('test_name', 'test_path', 'test_genres', 'test_platform', 'test_mult', 'test-id2') test_user = user.User({'media': [test_media1.as_json(), test_media2.as_json()], '_id': ''}) with patch.object(user, 'DB', {config.MONGODB_USER_COLLECTION_NAME: MagicMock()}): test_user.delete_media(test_media2.id_code) assert test_user.media == [test_media1.as_json()]
def test_read_media_error(): test_media = Game('test_name', 'test_path', 'test_genres', 'test_platform', 'test_mult', 'test-id') test_user = user.User({'media': [test_media.as_json()], '_id': ''}) with pytest.raises(ValueError): result = test_user.read_media('not an id code')
def test_read_media(): test_media1 = Game('test_name', 'test_path', 'test_genres', 'test_platform', 'test_mult', 'test-id') test_media2 = Game('test_name', 'test_path', 'test_genres', 'test_platform', 'test_mult', 'test-id2') test_user = user.User({'media': [test_media1.as_json(), test_media2.as_json()], '_id': ''}) result = test_user.read_media(test_media2.id_code) assert result == test_media2.as_json()
def test_create_media(): test_media = Game('test_name', 'test_path', 'test_genres', 'test_platform', 'test_mult', 'test-id') test_user = user.User({'media': [], '_id': ''}) with patch.object(user, 'DB', {config.MONGODB_USER_COLLECTION_NAME: MagicMock()}): test_user.create_media(test_media) assert test_user.media == [test_media.as_json()]
def test_media_prop(): test_user = user.User({'media': ['media-item']}) assert test_user.media == ['media-item']
def test_update_media_error(): test_media = Game('test_name', 'test_path', 'test_genres', 'test_platform', 'test_mult', 'test-id') test_media2 = Game('test_name', 'test_path', 'test_genres', 'test_platform', 'test_mult', 'test-id2') test_user = user.User({'media': [test_media.as_json()], '_id': ''}) with pytest.raises(ValueError): test_user.update_media(test_media2)