Skip to content

Commit

Permalink
Merge pull request #18 from SenteraLLC/feature/alert-url
Browse files Browse the repository at this point in the history
added url input to create alert function
  • Loading branch information
ZachMarston authored Jun 25, 2020
2 parents 57d9196 + b7d95a3 commit de21a4b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sentera/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Defines package version. Parsed by setup.py and imported by __init__.py."""

__version__ = "2.2.1"
__version__ = "2.3.0"
13 changes: 11 additions & 2 deletions sentera/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_weather(
return weather_df


def create_alert(field_sentera_id, name, message, token, key=None):
def create_alert(field_sentera_id, name, message, token, key=None, url=None):
"""
Create alert content and post alert mutation to https://api.sentera.com/graphql.
Expand All @@ -110,20 +110,28 @@ def create_alert(field_sentera_id, name, message, token, key=None):
:param message: brief description of the alert being made (string)
:param token: an authorization token needed to post the alert to the specified field (string)
:param key: (optional) A client-defined key to help identify the alert.
:param url: (optional) url link to more information about the alert (url)
:return: result of the request.post
"""
query = """mutation CreateAlert ($field_sentera_id: ID!, $name: String!, $message: String!, $key: String) {
query = """mutation CreateAlert (
$field_sentera_id: ID!,
$name: String!,
$message: String!,
$key: String,
$url: Url) {
create_alert (
field_sentera_id: $field_sentera_id
name: $name
message: $message
key: $key
url: $url
)
{
sentera_id
name
message
key
url
created_by {
sentera_id
first_name
Expand All @@ -138,6 +146,7 @@ def create_alert(field_sentera_id, name, message, token, key=None):
"name": name,
"message": message,
"key": key,
"url": url,
}
data = {"query": query, "variables": variables}
result = _run_sentera_query(data, token)
Expand Down
12 changes: 8 additions & 4 deletions sentera/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
@httpretty.httprettified
def test_create_alert_with_key_success():
def request_callback(request, uri, response_headers):
mutation = b"mutation CreateAlert ($field_sentera_id: ID!, $name: String!, $message: String!, $key: String) {\\n create_alert ("
variables = b'"variables": {"field_sentera_id": "gyq8ll6_AL_8brhbkSentera_CV_shar_e599fde_200326_182003", "name": "Southern Corn Rust Alert", "message": "Current weather conditions indicate things.", "key": "corn_rust"}'
mutation = b"mutation CreateAlert (\\n $field_sentera_id: ID!,\\n $name: String!,\\n $message: String!,\\n $key: String,\\n $url: Url) {\\n create_alert ("
variables = b'"variables": {"field_sentera_id": "gyq8ll6_AL_8brhbkSentera_CV_shar_e599fde_200326_182003", "name": "Southern Corn Rust Alert", "message": "Current weather conditions indicate things.", "key": "corn_rust", "url": "https://www.sentera.com"}'
print(request.body)
assert variables in request.body
assert mutation in request.body
return [
Expand All @@ -25,6 +26,7 @@ def request_callback(request, uri, response_headers):
"key": "corn_rust",
"name": "Southern Corn Rust Alert",
"message": "Current weather conditions indicate things.",
"url": "https://www.sentera.com",
"created_at": "2020-03-26T18:20:03Z",
}
}
Expand All @@ -41,6 +43,7 @@ def request_callback(request, uri, response_headers):
message="Current weather conditions indicate things.",
token="token123",
key="corn_rust",
url="https://www.sentera.com",
)
assert response["data"]["create_alert"]["key"] == "corn_rust"
assert len(httpretty.latest_requests()) == 1
Expand All @@ -49,8 +52,8 @@ def request_callback(request, uri, response_headers):
@httpretty.httprettified
def test_create_alert_without_key_success():
def request_callback(request, uri, response_headers):
mutation = b"mutation CreateAlert ($field_sentera_id: ID!, $name: String!, $message: String!, $key: String) {\\n create_alert ("
variables = b'"variables": {"field_sentera_id": "gyq8ll6_AL_8brhbkSentera_CV_shar_e599fde_200326_182003", "name": "Southern Corn Rust Alert", "message": "Current weather conditions indicate things.", "key": null}'
mutation = b"mutation CreateAlert (\\n $field_sentera_id: ID!,\\n $name: String!,\\n $message: String!,\\n $key: String,\\n $url: Url) {\\n create_alert ("
variables = b'"variables": {"field_sentera_id": "gyq8ll6_AL_8brhbkSentera_CV_shar_e599fde_200326_182003", "name": "Southern Corn Rust Alert", "message": "Current weather conditions indicate things.", "key": null, "url": null}'
assert variables in request.body
assert mutation in request.body
return [
Expand All @@ -64,6 +67,7 @@ def request_callback(request, uri, response_headers):
"key": None,
"name": "Southern Corn Rust Alert",
"message": "Current weather conditions indicate things.",
"url": None,
"created_at": "2020-03-26T18:20:03Z",
}
}
Expand Down

0 comments on commit de21a4b

Please sign in to comment.