From 9c16ded04188596345951bd4c9402400e688ebe2 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sat, 9 Jan 2016 13:33:19 +0100
Subject: [PATCH] Fix bug in explorer

---
 src/sakia/core/graph/explorer_graph.py        |  6 +++---
 .../unit/core/graph/test_explorer_graph.py    | 21 +++++++++++++++++--
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/sakia/core/graph/explorer_graph.py b/src/sakia/core/graph/explorer_graph.py
index 11c87979..af804f5f 100644
--- a/src/sakia/core/graph/explorer_graph.py
+++ b/src/sakia/core/graph/explorer_graph.py
@@ -33,8 +33,8 @@ class ExplorerGraph(BaseGraph):
         if self.exploration_task:
             if self.explored_identity is not identity or steps != self.steps:
                 self.exploration_task.cancel()
-            else:
-                return
+            #else:
+            #    return
         self.nx_graph.clear()
         self.explored_identity = identity
         self.steps = steps
@@ -69,6 +69,7 @@ class ExplorerGraph(BaseGraph):
 
         for step in range(0, steps):
             while len(explorable[step]) > 0:
+                current_identity = explorable[step].pop()
                 # for each pubkey connected...
                 if current_identity not in explored:
                     self.current_identity_changed.emit(current_identity.pubkey)
@@ -95,5 +96,4 @@ class ExplorerGraph(BaseGraph):
                     explored.append(current_identity)
                     logging.debug("New identity explored : {pubkey}".format(pubkey=current_identity.pubkey[:5]))
                     self.graph_changed.emit()
-                current_identity = explorable[step].pop()
         self.current_identity_changed.emit("")
diff --git a/src/sakia/tests/unit/core/graph/test_explorer_graph.py b/src/sakia/tests/unit/core/graph/test_explorer_graph.py
index 5147f404..035faab3 100644
--- a/src/sakia/tests/unit/core/graph/test_explorer_graph.py
+++ b/src/sakia/tests/unit/core/graph/test_explorer_graph.py
@@ -72,7 +72,7 @@ class TestExplorerGraph(unittest.TestCase, QuamashTest):
                                                                }
                                                            ])
 
-        self.idC.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certifierd_by',
+        self.idC.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certified_by',
                                                            return_value=[
                                                                {
                                                                    'cert_time': 49100,
@@ -123,7 +123,7 @@ class TestExplorerGraph(unittest.TestCase, QuamashTest):
     @patch('sakia.core.Application')
     @patch('sakia.core.Community')
     @patch('time.time', Mock(return_value=50000))
-    def test_explore_full(self, app, community):
+    def test_explore_full_from_center(self, app, community):
         community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
         community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
         app.preferences = {'expert_mode': True}
@@ -137,6 +137,23 @@ class TestExplorerGraph(unittest.TestCase, QuamashTest):
 
         self.lp.run_until_complete(exec_test())
 
+    @patch('sakia.core.Application')
+    @patch('sakia.core.Community')
+    @patch('time.time', Mock(return_value=50000))
+    def test_explore_full_from_extremity(self, app, community):
+        community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
+        community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
+        app.preferences = {'expert_mode': True}
+
+        explorer_graph = ExplorerGraph(app, community)
+
+        async def exec_test():
+            await explorer_graph._explore(self.idA, 5)
+            self.assertEqual(len(explorer_graph.nx_graph.nodes()), 5)
+            self.assertEqual(len(explorer_graph.nx_graph.edges()), 4)
+
+        self.lp.run_until_complete(exec_test())
+
     @patch('sakia.core.Application')
     @patch('sakia.core.Community')
     @patch('time.time', Mock(return_value=50000))
-- 
GitLab