import json
from indra.sources import sparser
from indra.sources.sparser.processor import _fix_agent
from indra.statements import Agent, Phosphorylation, Complex
from nose.plugins.attrib import attr

# ############################
# XML processing tests
# ############################

def test_invalid_xml():
    sp = sparser.process_xml('xyz')
    assert sp is None


def test_phosphorylation():
    sp = sparser.process_xml(xml_str1)
    assert len(sp.statements) == 1
    assert sp.statements[0].enz.name == 'MAP2K1'
    assert sp.statements[0].sub.name == 'MAPK3'
    assert len(sp.statements[0].evidence) == 1
    ev = sp.statements[0].evidence[0]
    assert ev.pmid == '54321'
    assert ev.text
    assert ev.source_api == 'sparser'


# This test uses some slow UniPtot web queries to standardize agent names
@attr('webservice', 'slow')
def test_phosphorylation2():
    sp = sparser.process_xml(xml_str2)
    assert len(sp.statements) == 1
    assert sp.statements[0].enz.name == 'MAPK1'
    assert sp.statements[0].sub.name == 'TP53BP2'