Skip to content

Commit

Permalink
Merge pull request #267 from atlanticwave-sdx/fix/issue_265
Browse files Browse the repository at this point in the history
Changing data returned by list connection
  • Loading branch information
italovalcy committed May 13, 2024
2 parents 36f9541 + 8e37bf4 commit f2c914a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion sdx_controller/controllers/connection_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def getconnections(): # noqa: E501
values = db_instance.get_all_entries_in_collection("connections")
if not values:
return "No connection was found", 404
return values
return_values = {}
for connection in values:
connection_id = next(iter(connection))
return_values[connection_id] = json.loads(connection[connection_id])
return return_values


def place_connection(body):
Expand Down
2 changes: 1 addition & 1 deletion sdx_controller/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ paths:
content:
application/json:
schema:
type: array
type: object
items:
$ref: '#/components/schemas/connection'
application/xml:
Expand Down
21 changes: 21 additions & 0 deletions sdx_controller/test/test_connection_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import absolute_import

import unittest
from unittest.mock import patch

from flask import json

Expand Down Expand Up @@ -264,6 +265,26 @@ def test_z100_getconnection_by_id_success(self):
)
self.assertStatus(response, 200)

@patch("sdx_controller.utils.db_utils.DbUtils.get_all_entries_in_collection")
def test_z105_getconnections_fail(self, mock_get_all_entries):
"""Test case for getconnections."""
mock_get_all_entries.return_value = {}
response = self.client.open(
f"{BASE_PATH}/connections",
method="GET",
)
self.assertStatus(response, 404)

def test_z105_getconnections_success(self):
"""Test case for getconnections."""
response = self.client.open(
f"{BASE_PATH}/connections",
method="GET",
)
self.assertStatus(response, 200)

assert len(response.json) == 1


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion sdx_controller/utils/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ def read_from_db(self, collection, key):
def get_all_entries_in_collection(self, collection):
db_collection = self.sdxdb[collection]
# MongoDB has an ObjectId for each item, so need to exclude the ObjectIds
all_entries = list(db_collection.find({}, {"_id": 0}))
all_entries = db_collection.find({}, {"_id": 0})
return all_entries

0 comments on commit f2c914a

Please sign in to comment.