Exemple #1
0
class TestRWSCSVReader(unittest.TestCase):
    def setUp(self):
        fake_db = FakeConn()
        self.tested = SQLLiteDBAdapter(fake_db)
        self.tested._setDatasets(metadata)

    def test_dataset(self):
        self.assertEqual("V_SIMPLESTUDY_ENROL" in self.tested.datasets, True)

    def test_cols(self):
        self.assertEqual(
            self.tested.datasets["V_SIMPLESTUDY_ENROL"][0]["ordinal"], "1")
        self.assertEqual(
            self.tested.datasets["V_SIMPLESTUDY_ENROL"][1]["varname"],
            "projectid")
        self.assertEqual(
            self.tested.datasets["V_SIMPLESTUDY_ENROL"][2]["vartype"], "char")
        self.assertEqual(
            self.tested.datasets["V_SIMPLESTUDY_ENROL"][3]["varformat"], "10.")
        self.assertEqual(
            self.tested.datasets["V_SIMPLESTUDY_ENROL"][4]["varlabel"],
            "Environment")

    def test_table_gen(self):
        "test generating tables"
        sql = self.tested._generateDDL()
        self.assertEqual(sql[0], 'drop table if exists V_SIMPLESTUDY_ENROL;')
        self.assertEqual(sql[1][:34], u'CREATE TABLE V_SIMPLESTUDY_ENROL (')
        self.assertEqual(True, 'userid NUMERIC' in sql[1])
        self.assertEqual(True, 'projectid NUMERIC' in sql[1])
        self.assertEqual(True, 'project TEXT' in sql[1])

    def test_insert_gen(self):
        """Test generation of insert statements"""
        self.tested.processFormData(enrol_data, 'V_SIMPLESTUDY_ENROL')

        first_line = self.tested.conn.cursor.sql[0][0]
        first_statement = first_line[0]
        first_values = first_line[1]

        #Check sql construction
        self.assertEqual(
            first_statement.startswith(
                'INSERT INTO V_SIMPLESTUDY_ENROL (userid,projectid,project'),
            True)
        self.assertEqual(
            'SUBID,BIRTHDT,BIRTHDT_RAW,BIRTHDT_INT,BIRTHDT_YYYY,BIRTHDT_MM,BIRTHDT_DD)'
            in first_statement, True)

        #Check values
        self.assertEqual('457', first_values[0])  #First value
        self.assertEqual('26', first_values[-1])  #Last value
Exemple #2
0
class TestRWSCSVReader(unittest.TestCase):
    def setUp(self):
        fake_db = FakeConn()
        self.tested = SQLLiteDBAdapter(fake_db)
        self.tested._setDatasets(metadata)

    def test_dataset(self):
        self.assertEqual("V_SIMPLESTUDY_ENROL" in self.tested.datasets, True)

    def test_cols(self):
        self.assertEqual(self.tested.datasets["V_SIMPLESTUDY_ENROL"][0]["ordinal"], "1")
        self.assertEqual(self.tested.datasets["V_SIMPLESTUDY_ENROL"][1]["varname"], "projectid")
        self.assertEqual(self.tested.datasets["V_SIMPLESTUDY_ENROL"][2]["vartype"], "char")
        self.assertEqual(self.tested.datasets["V_SIMPLESTUDY_ENROL"][3]["varformat"], "10.")
        self.assertEqual(self.tested.datasets["V_SIMPLESTUDY_ENROL"][4]["varlabel"], "Environment")

    def test_table_gen(self):
        "test generating tables"
        sql = self.tested._generateDDL()

        self.assertEqual(sql[0],'drop table if exists V_SIMPLESTUDY_ENROL;')
        self.assertEqual(sql[1][:34],u'CREATE TABLE V_SIMPLESTUDY_ENROL (')
        self.assertEqual(True, 'userid NUMERIC' in sql[1])
        self.assertEqual(True, 'projectid NUMERIC' in sql[1])
        self.assertEqual(True, 'project TEXT' in sql[1])


    def test_insert_gen(self):
        """Test generation of insert statements"""
        self.tested.processFormData(enrol_data, 'V_SIMPLESTUDY_ENROL')

        first_line = self.tested.conn.cursor.sql[0][0]
        first_statement = first_line[0]
        first_values = first_line[1]

        #Check sql construction
        self.assertEqual(first_statement.startswith('INSERT INTO V_SIMPLESTUDY_ENROL (userid,projectid,project'), True)
        self.assertEqual('SUBID,BIRTHDT,BIRTHDT_RAW,BIRTHDT_INT,BIRTHDT_YYYY,BIRTHDT_MM,BIRTHDT_DD)' in first_statement, True)

        #Check values
        self.assertEqual('457',first_values[0]) #First value
        self.assertEqual('26',first_values[-1]) #Last value
Exemple #3
0
    def test_sql_typefor(self):

        sqlite_db = None
        tested = SQLLiteDBAdapter(sqlite_db)
        self.assertEqual(tested.getSQLDataType("num"), "NUMERIC")
        self.assertEqual(tested.getSQLDataType("char"), "TEXT")
Exemple #4
0
 def setUp(self):
     fake_db = FakeConn()
     self.tested = SQLLiteDBAdapter(fake_db)
     self.tested._setDatasets(metadata)
Exemple #5
0
    def test_sql_typefor(self):

        sqlite_db = None
        tested = SQLLiteDBAdapter(sqlite_db)
        self.assertEqual(tested.getSQLDataType("num"), "NUMERIC")
        self.assertEqual(tested.getSQLDataType("char"), "TEXT")
Exemple #6
0
 def setUp(self):
     fake_db = FakeConn()
     self.tested = SQLLiteDBAdapter(fake_db)
     self.tested._setDatasets(metadata)