turbaszek commented on a change in pull request #9472:
URL: https://github.com/apache/airflow/pull/9472#discussion_r455681698
##########
File path: tests/providers/apache/hive/hooks/test_hive.py
##########
@@ -557,6 +557,11 @@ def test_table_exists(self):
self.hook.metastore.__enter__().get_table.assert_called_with(
dbname='default', tbl_name='does-not-exist')
+
@mock.patch('airflow.providers.apache.hive.hooks.hive.HiveMetastoreHook.drop_partitions')
+ def test_drop_partition(self, thrift_mock):
+ self.hook.drop_partitions(self.table, db=self.database,
part_vals=[DEFAULT_DATE_DS])
+ thrift_mock.assert_called_once_with(self.table, db=self.database,
part_vals=[DEFAULT_DATE_DS])
+
Review comment:
This test now check if `drop_partitions` was called. And it was a line
above the assertion :)
To use mock we should mock the metastore client, because we believe it was
tested and works as expected.So I would suggest something like this:
```python
@mock.patch('airflow.providers.apache.hive.hooks.hive.HiveMetastoreHook.table_exists')
@mock.patch('airflow.providers.apache.hive.hooks.hive.HiveMetastoreHook.metastore')
def test_drop_partition(self, metastore_mock, table_exist_mock):
# Here we mock behaviour of `with self.metastore as client`
client_drop_partition = metastore_mock.__enter__.return_value
# Here we want to be sure that we enter the right place of if
clause
table_exist_mock.return_value = True
# Here we call the method
self.hook.drop_partitions(self.table, db=self.database,
part_vals=[DEFAULT_DATE_DS])
# First lets check if we check if table exists
table_exist_mock.assert_called_once_with(self.table, self.database)
# And now we check if the underlying client.drop_partition method
was called
client_drop_partition.assert_called_once_with(self.table,
db=self.database, part_vals=[DEFAULT_DATE_DS])
```
The comments can be skipped, I'm also not sure if the `__enter__` mock is
100% right (something like this for sure). In case of any questions I'm happy
to help
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]