'Test load data queries.
These require Hadoop, because they ask the metastore
about whether a table is partitioned.'

def test_load_data(self):

    resp = self.client.get(('/metastore/table/%s/test/load' % self.db_name), follow=True)
    assert_true(('Path' in resp.content))
    data_dir = ('%(prefix)s/tmp' % {'prefix': self.cluster.fs_prefix})
    data_path = (data_dir + '/foo')
    self.cluster.fs.mkdir(data_dir)
    self.cluster.fs.create(data_path, data='123')
    response = self.client.post(('/metastore/table/%s/test/load' % self.db_name), {'path': data_path, 'overwrite': True}, follow=True)
    data = json.loads(response.content)
    query = QueryHistory.objects.get(id=data['query_history_id'])
    assert_equal_mod_whitespace(("LOAD    DATA    INPATH    '%(data_path)s'    OVERWRITE    INTO    TABLE    `%(db)s`.`test`" % {'data_path': data_path, 'db': self.db_name}), query.query)
    resp = self.client.post(('/metastore/table/%s/test/load' % self.db_name), {'path': data_path, 'overwrite': False}, follow=True)
    query = QueryHistory.objects.latest('id')
    assert_equal_mod_whitespace(("LOAD    DATA    INPATH    '%(data_path)s'    INTO    TABLE    `%(db)s`.`test`" % {'data_path': data_path, 'db': self.db_name}), query.query)
    resp = self.client.post(('/metastore/table/%s/test_partitions/load' % self.db_name), {'path': data_path, 'partition_0': 'alpha', 'partition_1': 12345}, follow=True)
    query = QueryHistory.objects.latest('id')
    assert_equal_mod_whitespace(query.query, ("LOAD    DATA    INPATH    '%(data_path)s'    INTO    TABLE    `%(db)s`.`test_partitions`    PARTITION    (baz='alpha',    boom='12345')" % {'data_path': data_path, 'db': self.db_name}))
