2011-04-26 21:05:02 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
test_refine.py
|
|
|
|
|
|
|
|
These tests require a connection to a Refine server either at
|
2011-04-26 23:02:40 +02:00
|
|
|
http://127.0.0.1:3333/ or by specifying environment variables
|
2013-10-10 13:41:10 +02:00
|
|
|
OPENREFINE_HOST and OPENREFINE_PORT.
|
2011-04-26 21:05:02 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
# Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
|
|
|
|
|
2011-07-20 17:31:47 +02:00
|
|
|
import csv
|
2011-04-26 21:05:02 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from google.refine import refine
|
2011-04-28 17:47:10 +02:00
|
|
|
from tests import refinetest
|
2011-04-26 21:05:02 +02:00
|
|
|
|
|
|
|
|
2011-04-26 21:13:25 +02:00
|
|
|
class RefineServerTest(refinetest.RefineTestCase):
|
2011-04-26 21:05:02 +02:00
|
|
|
def test_init(self):
|
2011-07-20 17:30:57 +02:00
|
|
|
server_url = 'http://' + refine.REFINE_HOST
|
|
|
|
if refine.REFINE_PORT != '80':
|
|
|
|
server_url += ':' + refine.REFINE_PORT
|
2011-06-10 14:53:46 +02:00
|
|
|
self.assertEqual(self.server.server, server_url)
|
|
|
|
self.assertEqual(refine.RefineServer.url(), server_url)
|
2011-04-26 22:55:07 +02:00
|
|
|
# strip trailing /
|
2011-04-26 21:05:02 +02:00
|
|
|
server = refine.RefineServer('http://refine.example/')
|
|
|
|
self.assertEqual(server.server, 'http://refine.example')
|
|
|
|
|
|
|
|
def test_list_projects(self):
|
|
|
|
projects = self.refine.list_projects()
|
|
|
|
self.assertTrue(isinstance(projects, dict))
|
|
|
|
|
|
|
|
def test_get_version(self):
|
2011-06-10 19:49:06 +02:00
|
|
|
version_info = self.server.get_version()
|
2011-04-26 21:05:02 +02:00
|
|
|
for item in ('revision', 'version', 'full_version', 'full_name'):
|
|
|
|
self.assertTrue(item in version_info)
|
|
|
|
|
2011-06-10 19:49:06 +02:00
|
|
|
def test_version(self):
|
2013-10-10 13:41:10 +02:00
|
|
|
self.assertTrue(self.server.version in ('2.0', '2.1', '2.5'))
|
2011-06-10 19:49:06 +02:00
|
|
|
|
2011-04-26 21:05:02 +02:00
|
|
|
|
2011-04-26 21:13:25 +02:00
|
|
|
class RefineTest(refinetest.RefineTestCase):
|
2011-04-26 21:05:02 +02:00
|
|
|
project_file = 'duplicates.csv'
|
|
|
|
|
|
|
|
def test_new_project(self):
|
|
|
|
self.assertTrue(isinstance(self.project, refine.RefineProject))
|
|
|
|
|
2011-06-10 14:58:03 +02:00
|
|
|
def test_wait_until_idle(self):
|
|
|
|
self.project.wait_until_idle() # should just return
|
|
|
|
|
|
|
|
def test_get_models(self):
|
2011-04-26 21:05:02 +02:00
|
|
|
self.assertEqual(self.project.key_column, 'email')
|
2011-06-10 14:58:03 +02:00
|
|
|
self.assertTrue('email' in self.project.columns)
|
2011-04-26 21:05:02 +02:00
|
|
|
self.assertTrue('email' in self.project.column_order)
|
|
|
|
self.assertEqual(self.project.column_order['name'], 1)
|
|
|
|
|
|
|
|
def test_delete_project(self):
|
|
|
|
self.assertTrue(self.project.delete())
|
|
|
|
|
2011-04-28 20:00:04 +02:00
|
|
|
def test_open_export(self):
|
|
|
|
fp = refine.RefineProject(self.project.project_url()).export()
|
|
|
|
line = fp.next()
|
|
|
|
self.assertTrue('email' in line)
|
2011-07-20 17:31:47 +02:00
|
|
|
for line in fp:
|
|
|
|
self.assertTrue('M' in line or 'F' in line)
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
def test_open_export_csv(self):
|
|
|
|
fp = refine.RefineProject(self.project.project_url()).export()
|
|
|
|
csv_fp = csv.reader(fp, dialect='excel-tab')
|
|
|
|
row = csv_fp.next()
|
|
|
|
self.assertTrue(row[0] == 'email')
|
|
|
|
for row in csv_fp:
|
|
|
|
self.assertTrue(row[3] == 'F' or row[3] == 'M')
|
2011-04-28 20:00:04 +02:00
|
|
|
fp.close()
|
2011-04-26 21:05:02 +02:00
|
|
|
|
2011-06-10 14:43:48 +02:00
|
|
|
|
2011-04-26 21:05:02 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|