Skip to content

Commit

Permalink
automate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rveachkc committed Dec 21, 2018
1 parent 54c8623 commit 6db800c
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 7 deletions.
28 changes: 22 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "requirements.txt" }}
- v1-dependencies-{{ checksum "dev-requirements.txt" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

Expand All @@ -24,12 +24,12 @@ jobs:
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
pip install -r dev-requirements.txt
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "requirements.txt" }}
key: v1-dependencies-{{ checksum "dev-requirements.txt" }}

# run tests!
# this example uses Django's built-in test-runner
Expand All @@ -45,8 +45,24 @@ jobs:
#- store_artifacts:
# path: test-reports
# destination: test-reports


test:
docker:
- image: circleci/python:3-stretch
working_directory: ~/repo

steps:
- checkout

- restore_cache:
key: v1-dependencies-{{ checksum "dev-requirements.txt" }}
- run:
name: verify git tag vs version
command: |
python3 -m venv venv
. venv/bin/activate
python setup.py verify
pytest
deploy:
docker:
- image: circleci/python:3-stretch
Expand All @@ -56,7 +72,7 @@ jobs:
- checkout

- restore_cache:
key: v1-dependencies-{{ checksum "requirements.txt" }}
key: v1-dependencies-{{ checksum "dev-requirements.txt" }}

- run:
name: verify git tag vs version
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pymsteams

* Master: [![CircleCI](https://circleci.com/gh/rveachkc/pymsteams/tree/master.svg?style=svg)](https://circleci.com/gh/rveachkc/pymsteams/tree/master)
* Develop: [![CircleCI](https://circleci.com/gh/rveachkc/pymsteams/tree/develop.svg?style=svg)](https://circleci.com/gh/rveachkc/pymsteams/tree/develop)

Python Wrapper Library to send requests to Microsoft Teams Webhooks.
Microsoft refers to these messages as Connector Cards. A message can be sent with only the main Connector Card, or additional sections can be included into the message.

Expand Down
22 changes: 22 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
atomicwrites==1.2.1
attrs==18.2.0
bleach==3.0.2
certifi==2018.4.16
chardet==3.0.4
colorama==0.4.1
docutils==0.14
idna==2.7
more-itertools==4.3.0
pkginfo==1.4.2
pluggy==0.8.0
py==1.7.0
Pygments==2.3.1
pytest==4.0.2
readme-renderer==24.0
requests==2.21.0
requests-toolbelt==0.8.0
six==1.12.0
tqdm==4.28.1
twine==1.12.1
urllib3==1.23
webencodings==0.5.1
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

65 changes: 65 additions & 0 deletions test/test_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
import sys

# add scripts to the path
sys.path.append(
os.path.split(
os.path.dirname(
os.path.abspath(__file__)
)
)[0]
)
import pymsteams

def test_env_webhook_url():
"""
Test that we have the webhook set as an environment variable.
This is testing our test environment, not the code.
"""
webhook_url = os.getenv("MS_TEAMS_WEBHOOK", None)
assert webhook_url
assert webhook_url.find("https") == 0

def test_send_message():
"""
This sends a simple text message with a title and link button.
"""

teams_message = pymsteams.connectorcard(os.getenv("MS_TEAMS_WEBHOOK"))
teams_message.text("This is a simple text message.")
teams_message.title("Simple Message Title")
teams_message.addLinkButton("Go to the Repo", "https://github.com/rveachkc/pymsteams")
teams_message.send()


def test_send_sectioned_message():
"""
This sends a message with sections.
"""

# start the message
teams_message = pymsteams.connectorcard(os.getenv("MS_TEAMS_WEBHOOK"))
teams_message.text("This is the main title.")
teams_message.title("Sectioned Message Title")

# section 1
section_1 = pymsteams.cardsection()
section_1.title("Section 1 title")
section_1.activityTitle("my activity title")
section_1.activitySubtitle("my activity subtitle")
section_1.activityImage("https://raw.githubusercontent.com/rveachkc/pymsteams/develop/test/desk_toys_1.jpg")
section_1.activityText("This is my activity Text. You should see an activity image, activity title, activity subtitle, and this text (of course).")
section_1.addFact("Fact", "this is fine")
section_1.addFact("Fact", "this is also fine")
section_1.text("This is my section 1 text. This section has an activity above and two facts below.")
teams_message.addSection(section_1)

# section 2
section_2 = pymsteams.cardsection()
section_2.text("This is section 2. You should see an image. This section does not have facts or a title.")
section_2.addImage("https://raw.githubusercontent.com/rveachkc/pymsteams/develop/test/desk_toys_2.jpg", ititle="Pew Pew Pew")
teams_message.addSection(section_2)


# send
teams_message.send()

0 comments on commit 6db800c

Please sign in to comment.