Example #1
0
 def test_get_tree_by_id_validate_returns_err(self):
     db_interface.validate_and_retrieve_client = Mock()
     client = MagicMock()
     client.close.return_value = None
     db_interface.validate_and_retrieve_client.side_effect = SystemError(
         Mock(status=500), "System Error")
     with pytest.raises(SystemError):
         get_tree_by_id(1)
Example #2
0
    def test_get_tree_by_id_not_in_db(self):
        db_interface.validate_and_retrieve_client = Mock()
        client = MagicMock()
        client.close.return_value = None
        db_interface.validate_and_retrieve_client.return_value = client
        client[VERWIKI_DB_NAME][TREES_TABLE_NAME].find_one.return_value = None

        with pytest.raises(KeyError):
            get_tree_by_id(1)
Example #3
0
    def test_get_tree_by_id_malformed_data(self):
        db_interface.validate_and_retrieve_client = Mock()
        client = MagicMock()
        client.close.return_value = None
        db_interface.validate_and_retrieve_client.return_value = client
        client[VERWIKI_DB_NAME][TREES_TABLE_NAME].find_one.return_value = {
            "noDataKey": 96
        }

        with pytest.raises(TypeError):
            get_tree_by_id(1)
Example #4
0
    def test_get_tree_by_id_exists_in_db(self):
        db_interface.validate_and_retrieve_client = Mock()
        client = MagicMock()
        client.close.return_value = None
        db_interface.validate_and_retrieve_client.return_value = client
        mock_tree = {"children": []}
        client[VERWIKI_DB_NAME][TREES_TABLE_NAME].find_one.return_value = {
            "data": mock_tree
        }

        assert get_tree_by_id(1) == mock_tree
Example #5
0
 def get_tree_by_id(id):
     """
     Returns the tree corresponding to the ID else an error status that
     the client must handle.
     """
     try:
         tree = db_interface.get_tree_by_id(int(id))
         return jsonify(tree)
     except KeyError as e:
         nf = NotFound()
         nf.description = str(e)
         raise nf
     except Exception as e:
         internalSrvErr = InternalServerError()
         internalSrvErr.description = str(e)
         raise internalSrvErr