示例#1
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))
示例#2
0
    def test_create_tables(self):
        ws = Workspace(self.client, self.db_client, self.config)

        ws.create_tables()

        self.db_client.assert_has_calls([
            mock.call.write(
                workspace.CREATE_PROJECTS_TABLE.format(
                    table_name=workspace.PROJECTS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_PROJECT_MEMBERSHIPS_TABLE.format(
                    table_name=workspace.PROJECT_MEMBERSHIPS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_USERS_TABLE.format(
                    table_name=workspace.USERS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_FOLLOWERS_TABLE.format(
                    table_name=workspace.FOLLOWERS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_CUSTOM_FIELDS_TABLE.format(
                    table_name=workspace.CUSTOM_FIELDS_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_CUSTOM_FIELD_ENUM_VALUES_TABLE.format(
                    table_name=workspace.CUSTOM_FIELD_ENUM_VALUES_TABLE_NAME)),
            mock.call.write(
                workspace.CREATE_CUSTOM_FIELD_VALUES_TABLE.format(
                    table_name=workspace.CUSTOM_FIELD_VALUES_TABLE_NAME)),
        ],
                                        any_order=True)
示例#3
0
    def test_add_same_project(self):
        self.db_client.read.return_value = [fixtures.row(id=1, name="foo")]

        ws = Workspace(self.client, self.db_client, self.config)

        ws.add_project(fixtures.project(id=1, name="foo"))

        self.db_client.write.assert_not_called()
示例#4
0
    def test_add_new_user(self):
        self.db_client.read.return_value = [fixtures.row(id=1, name="foo")]

        ws = Workspace(self.client, self.db_client, self.config)

        ws.add_user(fixtures.user(id=2, name="bar"))

        self.db_client.write.assert_called_once_with(
            workspace.INSERT_USER.format(
                table_name=workspace.USERS_TABLE_NAME), 2, "bar")
示例#5
0
    def test_add_follower(self):
        self.db_client.read.return_value = [fixtures.row(id=2, name="foo")]

        ws = Workspace(self.client, self.db_client, self.config)

        ws.add_follower(1, fixtures.user(id=2, name="foo"))

        self.db_client.write.assert_called_once_with(
            workspace.INSERT_FOLLOWER.format(
                table_name=workspace.FOLLOWERS_TABLE_NAME), (1, 2))
示例#6
0
    def test_add_existing_project(self):
        self.db_client.read.return_value = [fixtures.row(id=1, name="foo")]

        ws = Workspace(self.client, self.db_client, self.config)

        ws.add_project(fixtures.project(id=1, name="bar"))

        self.db_client.write.assert_called_once_with(
            workspace.INSERT_PROJECT.format(
                table_name=workspace.PROJECTS_TABLE_NAME), 1, "bar")
示例#7
0
    def test_default_table_names(self):
        ws = Workspace(self.client, self.db_client, self.config)

        self.assertEqual(ws.projects_table_name(),
                         workspace.PROJECTS_TABLE_NAME)
        self.assertEqual(ws.project_memberships_table_name(),
                         workspace.PROJECT_MEMBERSHIPS_TABLE_NAME)
        self.assertEqual(ws.users_table_name(), workspace.USERS_TABLE_NAME)
        self.assertEqual(ws.followers_table_name(),
                         workspace.FOLLOWERS_TABLE_NAME)
        self.assertEqual(ws.custom_fields_table_name(),
                         workspace.CUSTOM_FIELDS_TABLE_NAME)
        self.assertEqual(ws.custom_field_enum_values_table_name(),
                         workspace.CUSTOM_FIELD_ENUM_VALUES_TABLE_NAME)
        self.assertEqual(ws.custom_field_values_table_name(),
                         workspace.CUSTOM_FIELD_VALUES_TABLE_NAME)
示例#8
0
    def test_custom_table_name(self):
        self.config.projects_table_name = "custom projects"
        self.config.project_memberships_table_name = "custom project_memberships"
        self.config.users_table_name = "custom users"
        self.config.followers_table_name = "custom followers"
        self.config.custom_fields_table_name = "custom custom_fields"
        self.config.custom_field_enum_values_table_name = "custom custom_field_enum_values"
        self.config.custom_field_values_table_name = "custom custom_field_values"
        ws = Workspace(self.client, self.db_client, self.config)

        self.assertEqual(ws.projects_table_name(), "custom projects")
        self.assertEqual(ws.project_memberships_table_name(),
                         "custom project_memberships")
        self.assertEqual(ws.users_table_name(), "custom users")
        self.assertEqual(ws.followers_table_name(), "custom followers")
        self.assertEqual(ws.custom_fields_table_name(), "custom custom_fields")
        self.assertEqual(ws.custom_field_enum_values_table_name(),
                         "custom custom_field_enum_values")
        self.assertEqual(ws.custom_field_values_table_name(),
                         "custom custom_field_values")