Skip to content

Commit fc6fc27

Browse files
DStapeSergeyPirogov
authored andcommitted
Add NginxContainer (#16)
1 parent 6d91268 commit fc6fc27

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

testcontainers/nginx.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
from testcontainers.core.generic import GenericContainer
14+
15+
16+
class NginxContainer(GenericContainer):
17+
def __init__(self, image="nginx:latest", port_to_expose=80):
18+
super(NginxContainer, self).__init__(image)
19+
self.port_to_expose = port_to_expose
20+
self.with_exposed_ports(self.port_to_expose)

tests/test_nginx_container.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import requests
2+
3+
from testcontainers.nginx import NginxContainer
4+
5+
6+
def test_docker_run_nginx():
7+
nginx_container = NginxContainer("nginx:1.13.8")
8+
with nginx_container as nginx:
9+
port = nginx.port_to_expose
10+
url = "http://{}:{}/".format(nginx.get_container_host_ip(),
11+
nginx.get_exposed_port(port))
12+
r = requests.get(url)
13+
assert(r.status_code == 200)
14+
assert('Welcome to nginx!' in r.text)

0 commit comments

Comments
 (0)