From 683f9b984a7e8cef59141d0363be037c83a5089b Mon Sep 17 00:00:00 2001
From: Thor77 <thor77@thor77.org>
Date: Tue, 28 Mar 2017 21:44:06 +0100
Subject: [PATCH] Add testcase for wrong identifier with identmap

If a client connects with a secondary identifier first,
this one is used as the identifier for the Client-object instead of the
primary one.
---
 .../tests/res/test.log.identmap_wrong_identifier  |  7 +++++++
 tsstats/tests/test_ident_map.py                   | 15 +++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 tsstats/tests/res/test.log.identmap_wrong_identifier

diff --git a/tsstats/tests/res/test.log.identmap_wrong_identifier b/tsstats/tests/res/test.log.identmap_wrong_identifier
new file mode 100644
index 0000000..3ad89fb
--- /dev/null
+++ b/tsstats/tests/res/test.log.identmap_wrong_identifier
@@ -0,0 +1,7 @@
+2017-03-28 01:00:00.000000|INFO    |VirtualServer|   1| listening on 0.0.0.0:9987
+2017-03-28 03:00:00.000000|INFO    |VirtualServerBase|  2| client connected 'Client1'(id:2) from 1.2.3.4:1234
+2017-03-28 04:00:00.000000|INFO    |VirtualServerBase|  2| client disconnected 'Client1'(id:2) reason 'reasonmsg=ByeBye!'
+2017-03-28 01:00:00.000000|INFO    |VirtualServerBase|  2| client connected 'Client1'(id:1) from 1.2.3.4:1234
+2017-03-28 02:00:00.000000|INFO    |VirtualServerBase|  2| client disconnected 'Client1'(id:1) reason 'reasonmsg=ByeBye!'
+2017-03-28 05:00:00.000000|INFO    |VirtualServerBase|  2| client connected 'Client1'(id:3) from 1.2.3.4:1234
+2017-03-28 06:00:00.000000|INFO    |VirtualServerBase|  2| client disconnected 'Client1'(id:3) reason 'reasonmsg=ByeBye!'
diff --git a/tsstats/tests/test_ident_map.py b/tsstats/tests/test_ident_map.py
index e1cb26d..4aa63c6 100644
--- a/tsstats/tests/test_ident_map.py
+++ b/tsstats/tests/test_ident_map.py
@@ -1,6 +1,7 @@
 import pytest
 
 from tsstats.client import Client, Clients
+from tsstats.log import _parse_details
 from tsstats.utils import transform_pretty_identmap
 
 
@@ -51,3 +52,17 @@ def test_transform_pretty_identmap(test_input, expected):
     transformed_identmap = transform_pretty_identmap(test_input)
     for alternate, primary in expected:
         assert transformed_identmap[alternate] == primary
+
+
+def test_ident_map_wrong_identifier():
+    clients = _parse_details(
+        'tsstats/tests/res/test.log.identmap_wrong_identifier', ident_map={
+            '2': '1',
+            '3': '1'
+        }
+    )
+    client = clients.get('1')
+    # assert client exists
+    assert client
+    # assert correct identifier
+    assert client.identifier == '1'