import bpy
import molecularnodes as mn
import pytest

from .constants import data_dir


def test_session_present():
    assert isinstance(mn.session.get_session(), mn.session.MNSession)


def test_persistent_handlers_added():
    load_handlers = [handler.__name__ for handler in bpy.app.handlers.load_post]
    save_handlers = [handler.__name__ for handler in bpy.app.handlers.save_post]
    assert "_pickle" in save_handlers
    assert "_load" in load_handlers


def test_entity_registered():
    session = mn.session.get_session()
    assert len(session.entities) == 0

    mol = mn.entities.fetch("1BNA", cache_dir=data_dir)

    assert mol.uuid in session.entities
    assert isinstance(session.get(mol.uuid), mn.entities.BCIF)
    assert len(session.entities) == 1
