Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cahytinne committed Jul 31, 2015
1 parent abe28b6 commit 8d4edc2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
8 changes: 4 additions & 4 deletions atramhasis/scripts/import_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def file_to_csv_provider(input_file):
input_name, input_ext = os.path.splitext(os.path.basename(input_file))
with open(input_file, "rb") as ifile:
reader = csv.reader(ifile)
return SimpleCsvProvider(
{'id': input_name.upper()},
reader,
)
return SimpleCsvProvider(
{'id': input_name.upper()},
reader,
)


def file_to_json_provider(input_file):
Expand Down
11 changes: 11 additions & 0 deletions tests/data/menu.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1,"Egg and Bacon",
2,"Egg, sausage and Bacon",
3,"Egg and Spam",
4,"Spam Egg Sausage and Spam",
5,"Egg, Bacon and Spam",
6,"Egg, Bacon, sausage and Spam",
7,"Spam, Bacon, sausage and Spam",
8,"Spam, Egg, Spam, Spam, Bacon and Spam",
9,"Spam, Spam, Spam, Egg and Spam",
10,"Spam, Spam, Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam",
11,"Lobster Thermidor", "Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provencale manner with shallots and aubergines, garnished with truffle pâté, brandy and a fried egg on top and Spam"
36 changes: 36 additions & 0 deletions tests/test_import_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
from skosprovider_sqlalchemy.models import Base
from skosprovider_sqlalchemy.providers import SQLAlchemyProvider
from skosprovider.utils import dict_dumper
from skosprovider.skos import (
Concept,
Note
)

from atramhasis.scripts import import_file

here = os.path.dirname(__file__)
settings = get_appsettings(os.path.join(here, '../', 'tests/conf_test.ini'))
test_data_rdf = os.path.join(here, '../', 'tests/data/trees.xml')
test_data_json = os.path.join(here, '../', 'tests/data/trees.json')
test_data_csv = os.path.join(here, '../', 'tests/data/menu.csv')


class ImportTests(unittest.TestCase):
Expand Down Expand Up @@ -59,13 +64,44 @@ def _check_trees(self):
self.assertDictEqual(obj_1['notes'][0],
{'language': 'en', 'note': 'A different type of tree.', 'type': 'definition'})

def _check_menu(self):
sql_prov = SQLAlchemyProvider({'id': 'MENU', 'conceptscheme_id': 1}, self.session_maker)
self.assertEqual(11, len(sql_prov.get_all()))
eb = sql_prov.get_by_id(1)
self.assertIsInstance(eb, Concept)
self.assertEqual(1, eb.id)
self.assertEqual('urn:x-skosprovider:menu:1', eb.uri)
self.assertEqual('Egg and Bacon', eb.label().label)
self.assertEqual('prefLabel', eb.label().type)
self.assertEqual([], eb.notes)
eb = sql_prov.get_by_uri('urn:x-skosprovider:menu:3')
self.assertIsInstance(eb, Concept)
self.assertEqual(3, eb.id)
self.assertEqual('urn:x-skosprovider:menu:3', eb.uri)
spam = sql_prov.find({'label': 'Spam'})
self.assertEqual(8, len(spam))
eb = sql_prov.get_by_id(11)
self.assertIsInstance(eb, Concept)
self.assertEqual(11, eb.id)
self.assertEqual('Lobster Thermidor', eb.label().label)
self.assertIsInstance(eb.notes[0], Note)
self.assertIn('Mornay', eb.notes[0].note)
self.assertEqual('note', eb.notes[0].type)

def test_import_rdf(self):
sys.argv = ['import_file', '--from', test_data_rdf, '--to', settings['sqlalchemy.url']]
import_file.main(sys.argv)
self._check_trees()

def test_import_json(self):
sys.argv = ['import_file', '--from', test_data_json, '--to', settings['sqlalchemy.url']]
import_file.main(sys.argv)
self._check_trees()

def test_import_csv(self):
sys.argv = ['import_file', '--from', test_data_csv, '--to', settings['sqlalchemy.url']]
import_file.main(sys.argv)
self._check_menu()



Expand Down

0 comments on commit 8d4edc2

Please sign in to comment.