Techdebt: Replace sure with regular assertions in GuardDuty (#6569)
This commit is contained in:
parent
414a9e6c86
commit
69a207df86
@ -1,6 +1,5 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import pytest
|
import pytest
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
|
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
from moto import mock_guardduty
|
from moto import mock_guardduty
|
||||||
@ -16,16 +15,16 @@ def test_create_detector():
|
|||||||
DataSources={"S3Logs": {"Enable": True}},
|
DataSources={"S3Logs": {"Enable": True}},
|
||||||
Tags={},
|
Tags={},
|
||||||
)
|
)
|
||||||
response.should.have.key("DetectorId")
|
assert "DetectorId" in response
|
||||||
response["DetectorId"].shouldnt.equal(None)
|
assert response["DetectorId"] is not None
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
def test_create_detector_with_minimal_params():
|
def test_create_detector_with_minimal_params():
|
||||||
client = boto3.client("guardduty", region_name="us-east-1")
|
client = boto3.client("guardduty", region_name="us-east-1")
|
||||||
response = client.create_detector(Enable=True)
|
response = client.create_detector(Enable=True)
|
||||||
response.should.have.key("DetectorId")
|
assert "DetectorId" in response
|
||||||
response["DetectorId"].shouldnt.equal(None)
|
assert response["DetectorId"] is not None
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -40,10 +39,9 @@ def test_get_detector_with_s3():
|
|||||||
)["DetectorId"]
|
)["DetectorId"]
|
||||||
|
|
||||||
resp = client.get_detector(DetectorId=detector_id)
|
resp = client.get_detector(DetectorId=detector_id)
|
||||||
resp.should.have.key("FindingPublishingFrequency").equals("ONE_HOUR")
|
assert resp["FindingPublishingFrequency"] == "ONE_HOUR"
|
||||||
resp.should.have.key("DataSources")
|
assert resp["DataSources"]["S3Logs"] == {"Status": "ENABLED"}
|
||||||
resp["DataSources"].should.have.key("S3Logs").equals({"Status": "ENABLED"})
|
assert "CreatedAt" in resp
|
||||||
resp.should.have.key("CreatedAt")
|
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -61,14 +59,10 @@ def test_get_detector_with_all_data_sources():
|
|||||||
)["DetectorId"]
|
)["DetectorId"]
|
||||||
|
|
||||||
resp = client.get_detector(DetectorId=detector_id)
|
resp = client.get_detector(DetectorId=detector_id)
|
||||||
resp.should.have.key("FindingPublishingFrequency").equals("ONE_HOUR")
|
assert resp["FindingPublishingFrequency"] == "ONE_HOUR"
|
||||||
resp.should.have.key("DataSources")
|
assert resp["DataSources"]["S3Logs"] == {"Status": "ENABLED"}
|
||||||
resp["DataSources"].should.have.key("S3Logs").equals({"Status": "ENABLED"})
|
assert resp["DataSources"]["Kubernetes"]["AuditLogs"] == {"Status": "ENABLED"}
|
||||||
resp["DataSources"].should.have.key("Kubernetes")
|
assert "CreatedAt" in resp
|
||||||
resp["DataSources"]["Kubernetes"].should.have.key("AuditLogs").equals(
|
|
||||||
{"Status": "ENABLED"}
|
|
||||||
)
|
|
||||||
resp.should.have.key("CreatedAt")
|
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -92,13 +86,9 @@ def test_update_detector():
|
|||||||
)
|
)
|
||||||
|
|
||||||
resp = client.get_detector(DetectorId=detector_id)
|
resp = client.get_detector(DetectorId=detector_id)
|
||||||
resp.should.have.key("FindingPublishingFrequency").equals("SIX_HOURS")
|
assert resp["FindingPublishingFrequency"] == "SIX_HOURS"
|
||||||
resp.should.have.key("DataSources")
|
assert resp["DataSources"]["S3Logs"] == {"Status": "ENABLED"}
|
||||||
resp["DataSources"].should.have.key("S3Logs").equals({"Status": "ENABLED"})
|
assert resp["DataSources"]["Kubernetes"]["AuditLogs"] == {"Status": "DISABLED"}
|
||||||
resp["DataSources"].should.have.key("Kubernetes")
|
|
||||||
resp["DataSources"]["Kubernetes"].should.have.key("AuditLogs").equals(
|
|
||||||
{"Status": "DISABLED"}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -106,7 +96,7 @@ def test_list_detectors_initial():
|
|||||||
client = boto3.client("guardduty", region_name="us-east-1")
|
client = boto3.client("guardduty", region_name="us-east-1")
|
||||||
|
|
||||||
response = client.list_detectors()
|
response = client.list_detectors()
|
||||||
response.should.have.key("DetectorIds").equals([])
|
assert response["DetectorIds"] == []
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -122,8 +112,7 @@ def test_list_detectors():
|
|||||||
d2 = client.create_detector(Enable=False)["DetectorId"]
|
d2 = client.create_detector(Enable=False)["DetectorId"]
|
||||||
|
|
||||||
response = client.list_detectors()
|
response = client.list_detectors()
|
||||||
response.should.have.key("DetectorIds")
|
assert set(response["DetectorIds"]) == {d1, d2}
|
||||||
set(response["DetectorIds"]).should.equal({d1, d2})
|
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -147,9 +136,10 @@ def test_delete_detector():
|
|||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.get_detector(DetectorId=detector_id)
|
client.get_detector(DetectorId=detector_id)
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("BadRequestException")
|
assert err["Code"] == "BadRequestException"
|
||||||
err["Message"].should.equal(
|
assert (
|
||||||
"The request is rejected because the input detectorId is not owned by the current account."
|
err["Message"]
|
||||||
|
== "The request is rejected because the input detectorId is not owned by the current account."
|
||||||
)
|
)
|
||||||
|
|
||||||
client.list_detectors().should.have.key("DetectorIds").equals([])
|
assert client.list_detectors()["DetectorIds"] == []
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import pytest
|
import pytest
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
|
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
from moto import mock_guardduty
|
from moto import mock_guardduty
|
||||||
@ -16,7 +15,7 @@ def test_create_filter():
|
|||||||
Name="my first filter",
|
Name="my first filter",
|
||||||
FindingCriteria={"Criterion": {"x": {"Eq": ["y"]}}},
|
FindingCriteria={"Criterion": {"x": {"Eq": ["y"]}}},
|
||||||
)
|
)
|
||||||
resp.should.have.key("Name").equals("my first filter")
|
assert resp["Name"] == "my first filter"
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -31,7 +30,7 @@ def test_create_filter__defaults():
|
|||||||
)
|
)
|
||||||
|
|
||||||
resp = client.get_filter(DetectorId=detector_id, FilterName="my first filter")
|
resp = client.get_filter(DetectorId=detector_id, FilterName="my first filter")
|
||||||
resp.should.have.key("Rank").equals(1)
|
assert resp["Rank"] == 1
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -46,8 +45,8 @@ def test_get_filter():
|
|||||||
)
|
)
|
||||||
|
|
||||||
resp = client.get_filter(DetectorId=detector_id, FilterName="my first filter")
|
resp = client.get_filter(DetectorId=detector_id, FilterName="my first filter")
|
||||||
resp.should.have.key("Name").equals("my first filter")
|
assert resp["Name"] == "my first filter"
|
||||||
resp.should.have.key("FindingCriteria").equals({"Criterion": {"x": {"Eq": ["y"]}}})
|
assert resp["FindingCriteria"] == {"Criterion": {"x": {"Eq": ["y"]}}}
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -68,14 +67,14 @@ def test_update_filter():
|
|||||||
Rank=21,
|
Rank=21,
|
||||||
Action="NOOP",
|
Action="NOOP",
|
||||||
)
|
)
|
||||||
resp.should.have.key("Name").equals("my first filter")
|
assert resp["Name"] == "my first filter"
|
||||||
|
|
||||||
resp = client.get_filter(DetectorId=detector_id, FilterName="my first filter")
|
resp = client.get_filter(DetectorId=detector_id, FilterName="my first filter")
|
||||||
resp.should.have.key("Name").equals("my first filter")
|
assert resp["Name"] == "my first filter"
|
||||||
resp.should.have.key("Description").equals("with desc")
|
assert resp["Description"] == "with desc"
|
||||||
resp.should.have.key("Rank").equals(21)
|
assert resp["Rank"] == 21
|
||||||
resp.should.have.key("Action").equals("NOOP")
|
assert resp["Action"] == "NOOP"
|
||||||
resp.should.have.key("FindingCriteria").equals({"Criterion": {"x": {"Eq": ["y"]}}})
|
assert resp["FindingCriteria"] == {"Criterion": {"x": {"Eq": ["y"]}}}
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -94,4 +93,4 @@ def test_delete_filter():
|
|||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.get_filter(DetectorId=detector_id, FilterName="my first filter")
|
client.get_filter(DetectorId=detector_id, FilterName="my first filter")
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("BadRequestException")
|
assert err["Code"] == "BadRequestException"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
|
|
||||||
from moto import mock_guardduty
|
from moto import mock_guardduty
|
||||||
|
|
||||||
@ -8,8 +7,7 @@ from moto import mock_guardduty
|
|||||||
def test_enable_organization_admin_account():
|
def test_enable_organization_admin_account():
|
||||||
client = boto3.client("guardduty", region_name="us-east-1")
|
client = boto3.client("guardduty", region_name="us-east-1")
|
||||||
resp = client.enable_organization_admin_account(AdminAccountId="")
|
resp = client.enable_organization_admin_account(AdminAccountId="")
|
||||||
resp.should.have.key("ResponseMetadata")
|
assert resp["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||||
resp["ResponseMetadata"].should.have.key("HTTPStatusCode").equals(200)
|
|
||||||
|
|
||||||
|
|
||||||
@mock_guardduty
|
@mock_guardduty
|
||||||
@ -18,7 +16,7 @@ def test_list_organization_admin_accounts():
|
|||||||
client.enable_organization_admin_account(AdminAccountId="someaccount")
|
client.enable_organization_admin_account(AdminAccountId="someaccount")
|
||||||
|
|
||||||
resp = client.list_organization_admin_accounts()
|
resp = client.list_organization_admin_accounts()
|
||||||
resp.should.have.key("AdminAccounts").length_of(1)
|
assert len(resp["AdminAccounts"]) == 1
|
||||||
resp["AdminAccounts"].should.contain(
|
assert {"AdminAccountId": "someaccount", "AdminStatus": "ENABLED"} in resp[
|
||||||
{"AdminAccountId": "someaccount", "AdminStatus": "ENABLED"}
|
"AdminAccounts"
|
||||||
)
|
]
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import json
|
import json
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
|
|
||||||
import moto.server as server
|
import moto.server as server
|
||||||
|
|
||||||
@ -10,5 +9,5 @@ def test_create_without_enable_option():
|
|||||||
|
|
||||||
body = {"enable": "True"}
|
body = {"enable": "True"}
|
||||||
response = test_client.post("/detector", data=json.dumps(body))
|
response = test_client.post("/detector", data=json.dumps(body))
|
||||||
response.status_code.should.equal(200)
|
assert response.status_code == 200
|
||||||
json.loads(response.data).should.have.key("detectorId")
|
assert "detectorId" in json.loads(response.data)
|
||||||
|
Loading…
Reference in New Issue
Block a user