예제 #1
0
    def test_dry_write(self):
        db_wrapper = DatabaseWrapper(self.conn, dry=True)

        self.assertEqual(db_wrapper.num_writes, 0)
        self.assertEqual(db_wrapper.num_executed, 0)

        db_wrapper.write(TEST_SQL, PARAM1, PARAM2)

        self.assertEqual(db_wrapper.num_writes, 1)
        self.assertEqual(db_wrapper.num_executed, 0)

        self.assertEqual(self.conn.mock_calls, [])
예제 #2
0
    def test_write(self):
        db_wrapper = DatabaseWrapper(self.conn)

        self.assertEqual(db_wrapper.num_writes, 0)
        self.assertEqual(db_wrapper.num_executed, 0)

        db_wrapper.write(TEST_SQL, PARAM1, PARAM2)

        self.assertEqual(db_wrapper.num_writes, 1)
        self.assertEqual(db_wrapper.num_executed, 1)

        self.assertEqual(self.conn.mock_calls, [
            mock.call.cursor(),
            mock.call.cursor().execute(TEST_SQL, PARAM1, PARAM2),
        ])
예제 #3
0
def main():
    args = arg_parser().parse_args()

    client = build_asana_client(args)

    db_client = None
    if args.odbc_string:
        print("Connecting to database.")
        db_client = pyodbc.connect(args.odbc_string)
        db_client.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
        db_client.setencoding(encoding='utf-8')

    db_wrapper = DatabaseWrapper(db_client, dump_sql=args.dump_sql, dry=args.dry)

    workspace = Workspace(client, db_wrapper, args)
    project = Project(
            client, db_wrapper, workspace, args, default_fields(workspace))

    if args.command == 'create':
        project.create_table()
        workspace.create_tables()
    elif args.command == 'export':
        project.export()
    elif args.command == 'synchronize':
        project.synchronize()

    if not args.dry:
        db_client.commit()

    if args.dump_perf:
        print("API Requests: {}".format(client.num_requests))
        print("DB Commands: reads = {}, writes = {}, executed = {}".format(
            db_wrapper.num_reads, db_wrapper.num_writes, db_wrapper.num_commands_executed))
예제 #4
0
    def test_dry_read(self):
        self.conn.cursor().fetchall.return_value = [0, 1]
        self.conn.reset_mock()  # Ignore the call above.

        db_wrapper = DatabaseWrapper(self.conn, dry=True)

        self.assertEqual(db_wrapper.num_reads, 0)
        self.assertEqual(db_wrapper.num_executed, 0)

        self.assertEqual(db_wrapper.read(TEST_SQL, PARAM1, PARAM2), [0, 1])

        self.assertEqual(db_wrapper.num_reads, 1)
        self.assertEqual(db_wrapper.num_executed, 1)

        self.assertEqual(self.conn.mock_calls, [
            mock.call.cursor(),
            mock.call.cursor().execute(TEST_SQL, PARAM1, PARAM2),
            mock.call.cursor().fetchall(),
        ])