test_elx_schemas.py 638 Bytes
Newer Older
Pinar Alper's avatar
Pinar Alper committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from unittest import TestCase
from json import loads
from jsonschema import validate
import os


class TestParser(TestCase):



    def test_validation(self):

        schemaFile = open('../metadata-tools/resources/elx-study.json', encoding='utf-8')
        dataFile = open(os.path.join(os.path.dirname(__file__), 'study1.json'), encoding='utf-8')

        schema = loads(schemaFile.read())
        data = loads(dataFile.read())

        try:
            validate(data, schema['schema'])
            self.assert_(True)
        except:
            self.fail()
        finally:
            dataFile.close()
            schemaFile.close()