Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.getenv replaced with os.environ #178

Merged
merged 20 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build_and_publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ jobs:
make venv

- name: build documentation
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_API_ID: ${{ secrets.TG_API_ID }}
TG_API_HASH: ${{ secrets.TG_API_HASH }}
TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }}
run: |
make doc

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ jobs:
touch venv # disable venv target

- name: run tests
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_API_ID: ${{ secrets.TG_API_ID }}
TG_API_HASH: ${{ secrets.TG_API_HASH }}
TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }}
run: |
make test TEST_ALLOW_SKIP=telegram
10 changes: 10 additions & 0 deletions .github/workflows/test_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
shell: bash

- name: run pytest
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_API_ID: ${{ secrets.TG_API_ID }}
TG_API_HASH: ${{ secrets.TG_API_HASH }}
TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }}
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
source <(cat .env_file | sed 's/=/=/' | sed 's/^/export /')
Expand Down Expand Up @@ -72,6 +77,11 @@ jobs:
shell: bash

- name: run pytest
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_API_ID: ${{ secrets.TG_API_ID }}
TG_API_HASH: ${{ secrets.TG_API_HASH }}
TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }}
run: |
source <(cat .env_file | sed 's/=/=/' | sed 's/^/export /')
pytest --tb=long -vv --cache-clear --no-cov --allow-skip=all tests/
Expand Down
24 changes: 12 additions & 12 deletions tests/context_storages/test_dbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ def test_mongo(testing_context, context_id):

db = context_storage_factory(
"mongodb://{}:{}@localhost:27017/{}".format(
os.getenv("MONGO_INITDB_ROOT_USERNAME"),
os.getenv("MONGO_INITDB_ROOT_PASSWORD"),
os.getenv("MONGO_INITDB_ROOT_USERNAME"),
os.environ["MONGO_INITDB_ROOT_USERNAME"],
os.environ["MONGO_INITDB_ROOT_PASSWORD"],
os.environ["MONGO_INITDB_ROOT_USERNAME"],
)
)
generic_test(db, testing_context, context_id)
Expand All @@ -143,7 +143,7 @@ def test_mongo(testing_context, context_id):
@pytest.mark.skipif(not redis_available, reason="Redis dependencies missing")
@pytest.mark.docker
def test_redis(testing_context, context_id):
db = context_storage_factory("redis://{}:{}@localhost:6379/{}".format("", os.getenv("REDIS_PASSWORD"), "0"))
db = context_storage_factory("redis://{}:{}@localhost:6379/{}".format("", os.environ["REDIS_PASSWORD"], "0"))
generic_test(db, testing_context, context_id)
asyncio.run(delete_redis(db))

Expand All @@ -154,9 +154,9 @@ def test_redis(testing_context, context_id):
def test_postgres(testing_context, context_id):
db = context_storage_factory(
"postgresql+asyncpg://{}:{}@localhost:5432/{}".format(
os.getenv("POSTGRES_USERNAME"),
os.getenv("POSTGRES_PASSWORD"),
os.getenv("POSTGRES_DB"),
os.environ["POSTGRES_USERNAME"],
os.environ["POSTGRES_PASSWORD"],
os.environ["POSTGRES_DB"],
pseusys marked this conversation as resolved.
Show resolved Hide resolved
)
)
generic_test(db, testing_context, context_id)
Expand All @@ -177,9 +177,9 @@ def test_sqlite(testing_file, testing_context, context_id):
def test_mysql(testing_context, context_id):
db = context_storage_factory(
"mysql+asyncmy://{}:{}@localhost:3307/{}".format(
os.getenv("MYSQL_USERNAME"),
os.getenv("MYSQL_PASSWORD"),
os.getenv("MYSQL_DATABASE"),
os.environ["MYSQL_USERNAME"],
os.environ["MYSQL_PASSWORD"],
os.environ["MYSQL_DATABASE"],
)
)
generic_test(db, testing_context, context_id)
Expand All @@ -192,8 +192,8 @@ def test_mysql(testing_context, context_id):
def test_ydb(testing_context, context_id):
db = context_storage_factory(
"{}{}".format(
os.getenv("YDB_ENDPOINT"),
os.getenv("YDB_DATABASE"),
os.environ["YDB_ENDPOINT"],
os.environ["YDB_DATABASE"],
),
table_name="test",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/messengers/telegram/test_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"3_buttons_with_callback",
],
)
def test_client_tutorials_without_telegram(tutorial_module_name):
def test_client_tutorials_without_telegram(tutorial_module_name, env_vars):
tutorial_module = importlib.import_module(f"tutorials.{dot_path_to_addon}.{tutorial_module_name}")
pipeline = tutorial_module.pipeline
happy_path = tutorial_module.happy_path
Expand Down
6 changes: 3 additions & 3 deletions tutorials/context_storages/2_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

# %%
db_uri = "postgresql+asyncpg://{}:{}@localhost:5432/{}".format(
os.getenv("POSTGRES_USERNAME"),
os.getenv("POSTGRES_PASSWORD"),
os.getenv("POSTGRES_DB"),
os.environ["POSTGRES_USERNAME"],
os.environ["POSTGRES_PASSWORD"],
os.environ["POSTGRES_DB"],
)
db = context_storage_factory(db_uri)

Expand Down
6 changes: 3 additions & 3 deletions tutorials/context_storages/3_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

# %%
db_uri = "mongodb://{}:{}@localhost:27017/{}".format(
os.getenv("MONGO_INITDB_ROOT_USERNAME"),
os.getenv("MONGO_INITDB_ROOT_PASSWORD"),
os.getenv("MONGO_INITDB_ROOT_USERNAME"),
os.environ["MONGO_INITDB_ROOT_USERNAME"],
os.environ["MONGO_INITDB_ROOT_PASSWORD"],
os.environ["MONGO_INITDB_ROOT_USERNAME"],
)
db = context_storage_factory(db_uri)

Expand Down
2 changes: 1 addition & 1 deletion tutorials/context_storages/4_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


# %%
db_uri = "redis://{}:{}@localhost:6379/{}".format("", os.getenv("REDIS_PASSWORD"), "0")
db_uri = "redis://{}:{}@localhost:6379/{}".format("", os.environ["REDIS_PASSWORD"], "0")
db = context_storage_factory(db_uri)


Expand Down
6 changes: 3 additions & 3 deletions tutorials/context_storages/5_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

# %%
db_uri = "mysql+asyncmy://{}:{}@localhost:3307/{}".format(
os.getenv("MYSQL_USERNAME"),
os.getenv("MYSQL_PASSWORD"),
os.getenv("MYSQL_DATABASE"),
os.environ["MYSQL_USERNAME"],
os.environ["MYSQL_PASSWORD"],
os.environ["MYSQL_DATABASE"],
)
db = context_storage_factory(db_uri)

Expand Down
4 changes: 2 additions & 2 deletions tutorials/context_storages/7_yandex_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
# db_uri="grpc://localhost:2136/local"

db_uri = "{}{}".format(
os.getenv("YDB_ENDPOINT"),
os.getenv("YDB_DATABASE"),
os.environ["YDB_ENDPOINT"],
os.environ["YDB_DATABASE"],
)
db = context_storage_factory(db_uri)

Expand Down
4 changes: 1 addition & 3 deletions tutorials/messengers/telegram/1_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@


# %%
interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", ""))
interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"])


# %%
Expand All @@ -73,8 +73,6 @@


def main():
if not os.getenv("TG_BOT_TOKEN"):
print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.")
pipeline.run()


Expand Down
4 changes: 1 addition & 3 deletions tutorials/messengers/telegram/2_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
}

interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", ""))
interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"])

# this variable is only for testing
happy_path = (
Expand Down Expand Up @@ -158,8 +158,6 @@


def main():
if not os.getenv("TG_BOT_TOKEN"):
print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.")
pipeline.run()


Expand Down
4 changes: 1 addition & 3 deletions tutorials/messengers/telegram/3_buttons_with_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
),
)

interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", ""))
interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"])


# %%
Expand All @@ -151,8 +151,6 @@


def main():
if not os.getenv("TG_BOT_TOKEN"):
print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.")
pipeline.run()


Expand Down
4 changes: 1 addition & 3 deletions tutorials/messengers/telegram/4_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@


# %%
interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", ""))
interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"])


# %%
Expand All @@ -115,8 +115,6 @@


def main():
if not os.getenv("TG_BOT_TOKEN"):
print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.")
pipeline.run()


Expand Down
4 changes: 1 addition & 3 deletions tutorials/messengers/telegram/5_conditions_with_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


# %%
interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", ""))
interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"])


# %%
Expand Down Expand Up @@ -167,8 +167,6 @@ def extract_data(ctx: Context, _: Pipeline): # A function to extract data with


def main():
if not os.getenv("TG_BOT_TOKEN"):
print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.")
pipeline.run()


Expand Down
4 changes: 1 addition & 3 deletions tutorials/messengers/telegram/6_conditions_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@


# %%
interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", ""))
interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"])


# %%
Expand All @@ -106,8 +106,6 @@


def main():
if not os.getenv("TG_BOT_TOKEN"):
print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.")
pipeline.run()


Expand Down
4 changes: 1 addition & 3 deletions tutorials/messengers/telegram/7_polling_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# %%
interface = PollingTelegramInterface(
token=os.getenv("TG_BOT_TOKEN", ""),
token=os.environ["TG_BOT_TOKEN"],
interval=2,
allowed_updates=update_types,
timeout=30,
Expand All @@ -53,8 +53,6 @@


def main():
if not os.getenv("TG_BOT_TOKEN"):
print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.")
pipeline.run()


Expand Down
4 changes: 1 addition & 3 deletions tutorials/messengers/telegram/8_webhook_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


# %%
interface = CallbackTelegramInterface(token=os.getenv("TG_BOT_TOKEN", ""))
interface = CallbackTelegramInterface(token=os.environ["TG_BOT_TOKEN"])


# %%
Expand All @@ -49,8 +49,6 @@


def main():
if not os.getenv("TG_BOT_TOKEN"):
print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.")
pipeline.run()


Expand Down
Loading