Ejemplo n.º 1
0
    def test_get_load_parameters(self):
        actual_load_config = bq._get_load_parameters(
            TestCases.test_input_config, None, None)
        expected_load_config = {
            'type': 'pydatalab.bq.load',
            'path': 'test_path_%(_ts_month)s',
            'table': 'test_table',
            'schema': 'test_schema',
            'mode': 'append',
            'format': 'csv',
            'csv_options': {
                'delimiter': ';',
                'quote': '"',
                'skip': 9,
                'strict': False
            },
        }
        self.assertDictEqual(actual_load_config, expected_load_config)

        # Table is present in output config
        input_config = {
            'path': 'test_path_%(_ts_month)s',
            'format': 'csv',
            'csv': {
                'delimiter': ';',
                'quote': '"',
                'skip': 9,
                'strict': False
            },
        }
        output_config = {
            'table': 'test_table',
            'schema': 'test_schema',
            'mode': 'append',
        }
        actual_load_config = bq._get_load_parameters(input_config, None,
                                                     output_config)
        self.assertDictEqual(actual_load_config, expected_load_config)

        # Path is absent
        input_config = {'table': 'test_table', 'schema': 'test_schema'}
        actual_load_config = bq._get_load_parameters(input_config, None, None)
        self.assertIsNone(actual_load_config)

        # Path and table are absent
        input_config = {'schema': 'test_schema'}
        actual_load_config = bq._get_load_parameters(input_config, None, None)
        self.assertIsNone(actual_load_config)

        # Table is absent
        input_config = {'path': 'test_path', 'schema': 'test_schema'}
        actual_load_config = bq._get_load_parameters(input_config, None, None)
        self.assertIsNone(actual_load_config)
Ejemplo n.º 2
0
  def test_get_load_parameters(self):
    actual_load_config = bq._get_load_parameters(TestCases.test_input_config, None, None)
    expected_load_config = {
      'type': 'pydatalab.bq.load',
      'path': 'test_path_%(_ts_month)s',
      'table': 'test_table',
      'schema': 'test_schema',
      'mode': 'append',
      'format': 'csv',
      'csv_options': {'delimiter': ';', 'quote': '"', 'skip': 9, 'strict': False},
    }
    self.assertDictEqual(actual_load_config, expected_load_config)

    # Table is present in output config
    input_config = {
      'path': 'test_path_%(_ts_month)s',
      'format': 'csv',
      'csv': {'delimiter': ';', 'quote': '"', 'skip': 9, 'strict': False},
    }
    output_config = {
      'table': 'test_table',
      'schema': 'test_schema',
      'mode': 'append',
    }
    actual_load_config = bq._get_load_parameters(input_config, None, output_config)
    self.assertDictEqual(actual_load_config, expected_load_config)

    # Path is absent
    input_config = {
      'table': 'test_table',
      'schema': 'test_schema'
    }
    actual_load_config = bq._get_load_parameters(input_config, None, None)
    self.assertIsNone(actual_load_config)

    # Path and table are absent
    input_config = {
      'schema': 'test_schema'
    }
    actual_load_config = bq._get_load_parameters(input_config, None, None)
    self.assertIsNone(actual_load_config)

    # Table is absent
    input_config = {
      'path': 'test_path',
      'schema': 'test_schema'
    }
    actual_load_config = bq._get_load_parameters(input_config, None, None)
    self.assertIsNone(actual_load_config)
Ejemplo n.º 3
0
  def test_get_load_parameters(self):
    input_config = {
      'path': 'test_path',
      'table': 'test_table',
      'schema': 'test_schema',
      'csv': {
        'delimiter': ';',
        'skip': 9
      },
    }
    actual_load_config = bq._get_load_parameters(input_config)
    expected_load_config = {
      'type': 'pydatalab.bq.load',
      'format': 'csv',
      'path': 'test_path',
      'table': 'test_table',
      'schema': 'test_schema',
      'mode': 'create',
      'csv_options': {
        'delimiter': ';',
        'skip': 9
      }
    }
    self.assertDictEqual(actual_load_config, expected_load_config)

    input_config = {
      'path': 'test_path',
      'table': 'test_table',
    }
    actual_load_config = bq._get_load_parameters(input_config)
    self.assertEqual(actual_load_config['mode'], 'append')

    input_config = {
      'table': 'test_table',
      'schema': 'test_schema'
    }
    actual_load_config = bq._get_load_parameters(input_config)
    self.assertIsNone(actual_load_config)

    input_config = {
      'schema': 'test_schema'
    }
    actual_load_config = bq._get_load_parameters(input_config)
    self.assertIsNone(actual_load_config)

    input_config = {
      'path': 'test_path',
    }
    actual_load_config = bq._get_load_parameters(input_config)
    expected_load_config = {
      'type': 'pydatalab.bq.load',
      'format': 'csv',
      'csv_options': None,
      'path': 'test_path',
    }
    self.assertDictEqual(actual_load_config, expected_load_config)

    input_config = {
      'path': 'test_path',
      'format': 'json'
    }
    actual_load_config = bq._get_load_parameters(input_config)
    expected_load_config = {
      'type': 'pydatalab.bq.load',
      'format': 'json',
      'path': 'test_path',
      'csv_options': None
    }
    self.assertDictEqual(actual_load_config, expected_load_config)