Пример #1
0
def test_error_post_operation(mock_requests, mock_error):
    mock_requests.post.return_value.status_code = 401
    mock_requests.post.return_value.text = "unauthorized"
    api = PublicAPI("ABCD")
    api.post_operation(start="2019-06-01T12:00:00", keyword="Brand 2")
    mock_error.assert_called_with(
        "Error while sending API call 'post operation': 401 unauthorized")
Пример #2
0
def test_error_post_operation(mock_requests, mock_error):
    mock_requests.post.return_value.status_code = 401
    mock_requests.post.return_value.text = "unauthorized"
    api = PublicAPI("ABCD")
    api.post_operation(
        start = "2019-06-01T12:00:00",
        keyword = "Brand 2")
    mock_error.assert_called_with("Error while sending API call 'post operation': 401 unauthorized")
Пример #3
0
def test_minimal_post_operation(mock_requests, mock_info):
    mock_requests.post.return_value.status_code = 204
    api = PublicAPI(TOKEN)
    api.post_operation(start="2019-06-01T12:00:00", keyword="Brand 2")
    mock_requests.post.assert_called_once_with(
        f"https://connectapi.feuersoftware.com/interfaces/public/operation?updateStrategy=none",
        data='{'
        '"start": "2019-06-01T12:00:00", '
        '"keyword": "Brand 2"}',
        headers={
            "authorization": f"bearer {TOKEN}",
            "accept": "application/json",
            "content-type": "application/json"
        })
    mock_info.assert_called_with("Success, API call 'post operation' complete")
Пример #4
0
def test_minimal_post_operation(mock_requests, mock_info):
    mock_requests.post.return_value.status_code = 204
    api = PublicAPI(TOKEN)
    api.post_operation(
        start = "2019-06-01T12:00:00",
        keyword = "Brand 2")
    mock_requests.post.assert_called_once_with(
        f"https://connectapi.feuersoftware.com/interfaces/public/operation?updateStrategy=none",
        data='{'
             '"start": "2019-06-01T12:00:00", '
             '"keyword": "Brand 2"}',
        headers={"authorization": f"bearer {TOKEN}",
        "accept": "application/json",
        "content-type": "application/json"})
    mock_info.assert_called_with("Success, API call 'post operation' complete")
Пример #5
0
def test_full_post_operation(mock_requests, mock_info):
    mock_requests.post.return_value.status_code = 204
    api = PublicAPI(TOKEN)
    api.post_operation(start="2019-06-01T12:00:00",
                       end="2019-06-01T14:00:00",
                       keyword="Brand 2",
                       update_strategy="none",
                       status="new",
                       alarmenabled=True,
                       address="Teststrasse 10, 12345 Musterstadt",
                       position={
                           "latitude": "47.592127",
                           "longitude": "8.296870"
                       },
                       facts="Küchenbrand",
                       ric="12B",
                       number=54321,
                       properties=[{
                           "key": "Fettbrand",
                           "value": "Nein"
                       }, {
                           "key": "Noch·Personen·im·Gebäude",
                           "value": "Ja"
                       }])
    mock_requests.post.assert_called_once_with(
        f"https://connectapi.feuersoftware.com/interfaces/public/operation?updateStrategy=none",
        data='{'
        '"start": "2019-06-01T12:00:00", '
        '"keyword": "Brand 2", '
        '"end": "2019-06-01T14:00:00", '
        '"status": "new", '
        '"alarmenabled": true, '
        '"address": "Teststrasse 10, 12345 Musterstadt", '
        '"position": {"latitude": "47.592127", "longitude": "8.296870"}, '
        '"facts": "K\\u00fcchenbrand", '
        '"ric": "12B", '
        '"number": 54321, '
        '"properties": ['
        '{"key": "Fettbrand", "value": "Nein"}, '
        '{"key": "Noch\\u00b7Personen\\u00b7im\\u00b7Geb\\u00e4ude", "value": "Ja"}'
        ']}',
        headers={
            "authorization": f"bearer {TOKEN}",
            "accept": "application/json",
            "content-type": "application/json"
        })
    mock_info.assert_called_with("Success, API call 'post operation' complete")
Пример #6
0
def test_full_post_operation(mock_requests, mock_info):
    mock_requests.post.return_value.status_code = 204
    api = PublicAPI(TOKEN)
    api.post_operation(
        start = "2019-06-01T12:00:00",
        end = "2019-06-01T14:00:00",
        keyword = "Brand 2",
        update_strategy = "none",
        status = "new",
        alarmenabled = True,
        address = "Teststrasse 10, 12345 Musterstadt",
        position = {"latitude":"47.592127", "longitude":"8.296870"},
        facts =  "Küchenbrand",
        ric = "12B",
        number = 54321,
        properties = [
            {"key":"Fettbrand","value":"Nein"},
            {"key":"Noch·Personen·im·Gebäude","value":"Ja"}])
    mock_requests.post.assert_called_once_with(
        f"https://connectapi.feuersoftware.com/interfaces/public/operation?updateStrategy=none",
        data='{'
             '"start": "2019-06-01T12:00:00", '
             '"keyword": "Brand 2", '
             '"end": "2019-06-01T14:00:00", '
             '"status": "new", '
             '"alarmenabled": true, '
             '"address": "Teststrasse 10, 12345 Musterstadt", '
             '"position": {"latitude": "47.592127", "longitude": "8.296870"}, '
             '"facts": "K\\u00fcchenbrand", '
             '"ric": "12B", '
             '"number": 54321, '
             '"properties": ['
                '{"key": "Fettbrand", "value": "Nein"}, '
                '{"key": "Noch\\u00b7Personen\\u00b7im\\u00b7Geb\\u00e4ude", "value": "Ja"}'
             ']}',
        headers={"authorization": f"bearer {TOKEN}",
        "accept": "application/json",
        "content-type": "application/json"})
    mock_info.assert_called_with("Success, API call 'post operation' complete")
Пример #7
0
 def alert(self, account, alarmdata):
     """Send alarm data to Feuersoftware API."""
     api = PublicAPI(account.get("connect").get("token"))
     r = api.post_operation(
         start=alarmdata.get("start"),
         keyword=alarmdata.get("keyword"),
         status="new",
         alarmenabled=True,
         address=alarmdata.get("address"),
         facts=alarmdata.get("facts"),
         number=alarmdata.get("number"),
         properties=alarmdata.get("properties"),
         ric=alarmdata.get("ric"),
     )