Esempio n. 1
0
    def test_import_data_from_api(self, requests_mock):
        db_handle = csv_handle.DatabaseCSVHandle(self.db_name)
        db_handle.csv_file_path = self.csv_dir
        db_handle.create_db()
        db_handle.create_table()

        url = self.mock_api_request(requests_mock)
        db_handle.api_url = url
        db_handle.encoding = 'utf-8'
        db_handle.import_csv_to_sql()

        tables = []
        try:
            con = sqlite3.connect(db_handle.db_name)
            cursor = con.cursor()
            cursor.execute("SELECT * FROM matura")
            tables = cursor.fetchall()
            con.close()
        except Exception:
            pass
        finally:
            os.remove(db_handle.db_name)

        expected = []
        x = self.test_csv_content.split('\n')[1:]
        for row in x:
            expected.append(tuple(row.split(';')))

        assert tables == expected
Esempio n. 2
0
    def test_create_table(self):
        db_handle = csv_handle.DatabaseCSVHandle(self.db_name)
        db_handle.csv_file_path = self.csv_dir
        db_handle.create_db()
        db_handle.create_table()
        tables = []
        try:
            con = sqlite3.connect(db_handle.db_name)
            cursor = con.cursor()
            cursor.execute(
                "SELECT name FROM sqlite_master WHERE type='table';")
            tables = cursor.fetchone()
            con.close()
        except Exception:
            pass
        finally:
            os.remove(db_handle.db_name)

        assert db_handle.table_name in tables
Esempio n. 3
0
 def test_create_database(self):
     db_handle = csv_handle.DatabaseCSVHandle(self.db_name)
     db_handle.create_db()
     expected = os.path.isfile(db_handle.db_name)
     os.remove(db_handle.db_name)
     assert expected