Commit 9efe5ff0 authored by Yannick Kirschhoffer's avatar Yannick Kirschhoffer

Add extra tests on the docker configuration parser by using mockups.

parent 259156e3
......@@ -20,7 +20,7 @@ class Container:
self.image = image
self.ports = ports
def __str__(self) -> str:
def __repr__(self) -> str:
return '%s - %s - %s %s' % (self.name, self.status, self.networks, self.ports)
......@@ -28,8 +28,8 @@ class Configuration:
def __init__(self, containers: List[Container]):
self.containers = containers
def __str__(self):
return str([str(c) for c in self.containers])
def __repr__(self):
return str([repr(c) for c in self.containers])
class ConfigParser:
......
import unittest
from unittest.mock import patch
from docker import Client
from docker_ascii_map.docker_config import ConfigParser, PortMapping
class ConfigTests(unittest.TestCase):
def test_portmapping(self):
self.assertEqual('80:8080', str(PortMapping(private_port=8080, public_port=80)))
def test_empty_config(self):
with patch.object(Client, 'containers', return_value=[]) as mock_method:
configuration_parser = ConfigParser()
self.assertEqual([], configuration_parser.get_configuration().containers)
def test_single_container(self):
with patch.object(Client, 'containers', return_value=[
{'Names': ['/im1'], 'State': 'running', 'Image': 'ubuntu:latest',
'NetworkSettings': {'Networks': {}}, 'Ports': []}]) as mock_method:
configuration_parser = ConfigParser()
self.assertEqual('[\'im1 - running - [] []\']', str(configuration_parser.get_configuration()))
mock_method.assert_called_once_with(all=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment