Skip to content

Commit

Permalink
Fixes several failing tests after broken main (#17222)
Browse files Browse the repository at this point in the history
Several problems slipped through after recent broken main event
end they were merged with failing tests. This PR fixes it as well
as brings correct approach for "initialize-local-virtualenv"
to get constraints from sources rather than PyPI constraints,
which makes it easier to synchronize with latest versions of
depenendencies.
  • Loading branch information
potiuk committed Jul 26, 2021
1 parent babc425 commit d01cc94
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion airflow/providers/google/ads/hooks/ads.py
Expand Up @@ -239,7 +239,7 @@ def _search(
request = self._get_client.get_type("SearchGoogleAdsRequest")
request.customer_id = client_id
request.query = query
request.page_size = 10000
request.page_size = page_size

iterator = service.search(request=request)
iterators.append(iterator)
Expand Down
4 changes: 2 additions & 2 deletions breeze
Expand Up @@ -255,8 +255,8 @@ function breeze::initialize_virtualenv() {
echo
pushd "${AIRFLOW_SOURCES}" >/dev/null 2>&1 || exit 1
set +e
pip install -e ".[devel]" \
--constraint "https://raw.githubusercontent.com/${CONSTRAINTS_GITHUB_REPOSITORY}/${DEFAULT_CONSTRAINTS_BRANCH}/constraints-${PYTHON_MAJOR_MINOR_VERSION}.txt"
pip install -e ".[devel_all]" \
--constraint "https://raw.githubusercontent.com/${CONSTRAINTS_GITHUB_REPOSITORY}/${DEFAULT_CONSTRAINTS_BRANCH}/constraints-source-providers-${PYTHON_MAJOR_MINOR_VERSION}.txt"
res=$?
set -e
popd
Expand Down
9 changes: 3 additions & 6 deletions tests/providers/amazon/aws/hooks/test_s3.py
Expand Up @@ -26,7 +26,6 @@
import pytest
from botocore.exceptions import ClientError, NoCredentialsError

from airflow.exceptions import AirflowException
from airflow.models import Connection
from airflow.providers.amazon.aws.hooks.s3 import S3Hook, provide_bucket_name, unify_bucket_name_and_key

Expand Down Expand Up @@ -366,12 +365,10 @@ def test_function(self, bucket_name=None):
assert test_bucket_name == 'bucket'

def test_delete_objects_key_does_not_exist(self, s3_bucket):
# The behaviour of delete changed in recent version of s3 mock libraries.
# It will succeed idempotently
hook = S3Hook()
with pytest.raises(AirflowException) as ctx:
hook.delete_objects(bucket=s3_bucket, keys=['key-1'])

assert isinstance(ctx.value, AirflowException)
assert str(ctx.value) == "Errors when deleting: ['key-1']"
hook.delete_objects(bucket=s3_bucket, keys=['key-1'])

def test_delete_objects_one_key(self, mocked_s3_res, s3_bucket):
key = 'key-1'
Expand Down
14 changes: 9 additions & 5 deletions tests/providers/google/ads/hooks/test_ads.py
Expand Up @@ -16,6 +16,7 @@
# under the License.

from unittest import mock
from unittest.mock import PropertyMock

import pytest

Expand Down Expand Up @@ -56,18 +57,21 @@ def test_get_service(self, mock_client, mock_hook):
@mock.patch("airflow.providers.google.ads.hooks.ads.GoogleAdsClient")
def test_search(self, mock_client, mock_hook):
service = mock_client.load_from_dict.return_value.get_service.return_value
mock_client.load_from_dict.return_value.get_type.side_effect = [PropertyMock(), PropertyMock()]
client_ids = ["1", "2"]
rows = ["row1", "row2"]
service.search.side_effects = rows

# Here we mock _extract_rows to assert calls and
# avoid additional __iter__ calls
mock_hook._extract_rows = list

query = "QUERY"
client_ids = ["1", "2"]
mock_hook.search(client_ids=client_ids, query="QUERY", page_size=2)
expected_calls = [mock.call(c, query=query, page_size=2) for c in client_ids]
service.search.assert_has_calls(expected_calls)
mock_hook.search(client_ids=client_ids, query=query, page_size=2)
for i, client_id in enumerate(client_ids):
name, args, kwargs = service.search.mock_calls[i]
assert kwargs['request'].customer_id == client_id
assert kwargs['request'].query == query
assert kwargs['request'].page_size == 2

def test_extract_rows(self, mock_hook):
iterators = [[1, 2, 3], [4, 5, 6]]
Expand Down
10 changes: 9 additions & 1 deletion tests/providers/google/cloud/hooks/test_bigquery.py
Expand Up @@ -1761,7 +1761,15 @@ def test_create_external_table_with_kms(self, mock_create):
allow_jagged_rows = False
encoding = "UTF-8"
labels = {'label1': 'test1', 'label2': 'test2'}
schema_fields = [{'mode': 'REQUIRED', 'name': 'id', 'type': 'STRING', 'description': None}]
schema_fields = [
{
'mode': 'REQUIRED',
'name': 'id',
'type': 'STRING',
'description': None,
'policyTags': {'names': []},
}
]
encryption_configuration = {"kms_key_name": "projects/p/locations/l/keyRings/k/cryptoKeys/c"}

self.hook.create_external_table(
Expand Down

0 comments on commit d01cc94

Please sign in to comment.