Adjust tests to work in server mode

This commit is contained in:
gruebel 2019-12-19 21:41:32 +01:00
parent 03fd04db33
commit a67660b8a4

View File

@ -1,11 +1,9 @@
import json import json
from datetime import datetime from datetime import datetime, timezone
import boto3 import boto3
import pytz
import sure # noqa import sure # noqa
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
from freezegun import freeze_time
from nose.tools import assert_raises from nose.tools import assert_raises
from moto import mock_codepipeline, mock_iam from moto import mock_codepipeline, mock_iam
@ -347,7 +345,6 @@ def test_create_pipeline_errors():
) )
@freeze_time("2019-01-01 12:00:00")
@mock_codepipeline @mock_codepipeline
def test_get_pipeline(): def test_get_pipeline():
client = boto3.client("codepipeline", region_name="us-east-1") client = boto3.client("codepipeline", region_name="us-east-1")
@ -452,13 +449,11 @@ def test_get_pipeline():
"version": 1, "version": 1,
} }
) )
response["metadata"].should.equal( response["metadata"]["pipelineArn"].should.equal(
{ "arn:aws:codepipeline:us-east-1:123456789012:test-pipeline"
"pipelineArn": "arn:aws:codepipeline:us-east-1:123456789012:test-pipeline",
"created": datetime.now(pytz.utc),
"updated": datetime.now(pytz.utc),
}
) )
response["metadata"]["created"].should.be.a(datetime)
response["metadata"]["updated"].should.be.a(datetime)
@mock_codepipeline @mock_codepipeline
@ -480,8 +475,6 @@ def test_get_pipeline_errors():
def test_update_pipeline(): def test_update_pipeline():
client = boto3.client("codepipeline", region_name="us-east-1") client = boto3.client("codepipeline", region_name="us-east-1")
role_arn = get_role_arn() role_arn = get_role_arn()
with freeze_time("2019-01-01 12:00:00"):
created_time = datetime.now(pytz.utc)
client.create_pipeline( client.create_pipeline(
pipeline={ pipeline={
"name": "test-pipeline", "name": "test-pipeline",
@ -529,8 +522,10 @@ def test_update_pipeline():
tags=[{"key": "key", "value": "value"}], tags=[{"key": "key", "value": "value"}],
) )
with freeze_time("2019-01-02 12:00:00"): response = client.get_pipeline(name="test-pipeline")
updated_time = datetime.now(pytz.utc) created_time = response["metadata"]["created"]
updated_time = response["metadata"]["updated"]
response = client.update_pipeline( response = client.update_pipeline(
pipeline={ pipeline={
"name": "test-pipeline", "name": "test-pipeline",
@ -630,14 +625,9 @@ def test_update_pipeline():
} }
) )
response = client.get_pipeline(name="test-pipeline") metadata = client.get_pipeline(name="test-pipeline")["metadata"]
response["metadata"].should.equal( metadata["created"].should.equal(created_time)
{ metadata["updated"].should.be.greater_than(updated_time)
"pipelineArn": "arn:aws:codepipeline:us-east-1:123456789012:test-pipeline",
"created": created_time,
"updated": updated_time,
}
)
@mock_codepipeline @mock_codepipeline
@ -699,7 +689,6 @@ def test_update_pipeline_errors():
) )
@freeze_time("2019-01-01 12:00:00")
@mock_codepipeline @mock_codepipeline
def test_list_pipelines(): def test_list_pipelines():
client = boto3.client("codepipeline", region_name="us-east-1") client = boto3.client("codepipeline", region_name="us-east-1")
@ -796,25 +785,17 @@ def test_list_pipelines():
response = client.list_pipelines() response = client.list_pipelines()
response["pipelines"].should.equal( response["pipelines"].should.have.length_of(2)
[ response["pipelines"][0]["name"].should.equal("test-pipeline-1")
{ response["pipelines"][0]["version"].should.equal(1)
"name": "test-pipeline-1", response["pipelines"][0]["created"].should.be.a(datetime)
"version": 1, response["pipelines"][0]["updated"].should.be.a(datetime)
"created": datetime.now(pytz.utc), response["pipelines"][1]["name"].should.equal("test-pipeline-2")
"updated": datetime.now(pytz.utc), response["pipelines"][1]["version"].should.equal(1)
}, response["pipelines"][1]["created"].should.be.a(datetime)
{ response["pipelines"][1]["updated"].should.be.a(datetime)
"name": "test-pipeline-2",
"version": 1,
"created": datetime.now(pytz.utc),
"updated": datetime.now(pytz.utc),
},
]
)
@freeze_time("2019-01-01 12:00:00")
@mock_codepipeline @mock_codepipeline
def test_delete_pipeline(): def test_delete_pipeline():
client = boto3.client("codepipeline", region_name="us-east-1") client = boto3.client("codepipeline", region_name="us-east-1")
@ -863,16 +844,7 @@ def test_delete_pipeline():
], ],
}, },
) )
client.list_pipelines()["pipelines"].should.equal( client.list_pipelines()["pipelines"].should.have.length_of(1)
[
{
"name": "test-pipeline",
"version": 1,
"created": datetime.now(pytz.utc),
"updated": datetime.now(pytz.utc),
}
]
)
client.delete_pipeline(name="test-pipeline") client.delete_pipeline(name="test-pipeline")