Skip to content

Commit

Permalink
Ignore None type values in kwargs (#7)
Browse files Browse the repository at this point in the history
* Ignore None type values in kwargs

* Update gcn_kafka/core.py

Co-authored-by: Leo Singer <[email protected]>

* test methods

* Fixed looking at the wrong object

* Update gcn_kafka/test/test_core.py

Co-authored-by: Leo Singer <[email protected]>

* Update gcn_kafka/test/test_core.py

Co-authored-by: Leo Singer <[email protected]>

Co-authored-by: Leo Singer <[email protected]>
  • Loading branch information
dakota002 and lpsinger authored Aug 19, 2022
1 parent 6016971 commit cb89251
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gcn_kafka/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def get_config(mode, config, **kwargs):
# Merge configuration from user.
config = {**(config or {}), **kwargs}
config = update_config(config, kwargs)

# SSL configuration.
if config.setdefault("security.protocol", "sasl_ssl") == "sasl_ssl":
Expand Down Expand Up @@ -54,6 +54,12 @@ def get_config(mode, config, **kwargs):
return config


def update_config(config, **kwargs):
result = dict(config)
result.update({k: v for k, v in kwargs.items() if v is not None})
return result


class Producer(confluent_kafka.Producer):
def __init__(
self,
Expand Down
34 changes: 34 additions & 0 deletions gcn_kafka/test/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from ..core import update_config


def test_update_config_no_overwrite():
config = {
'client_id':'qwertyuiopasdfghjklzxcvbnm',
'client_secret':'qwertyuiopljhgfdsazxcvbnmlkjhgfdsaertyuio',
'domain':'test.test.test'
}

newConfig = update_config(
config,
client_id=None,
client_secret=None
)

assert newConfig == config


def test_update_config_with_overwrite():
config = {
'client_id':'qwertyuiopasdfghjklzxcvbnm',
'client_secret':'qwertyuiopljhgfdsazxcvbnmlkjhgfdsaertyuio',
'domain':'test.test.test'
}

newConfig = update_config(
config,
client_id="client_id update Success",
client_secret="client_secret update Success"
)

assert newConfig['client_id'] == "client_id update Success"
assert newConfig['client_secret'] == "client_secret update Success"

0 comments on commit cb89251

Please sign in to comment.