# Path: nomad/api/exceptions.py
# class BaseNomadException(Exception):
#     """General Error occurred when interacting with nomad API"""
#     def __init__(self, nomad_resp):
#         self.nomad_resp = nomad_resp
# 
#     def __str__(self):
#         if isinstance(self.nomad_resp, requests.Response) and hasattr(self.nomad_resp, "text"):
#             return 'The {0} was raised with following response: {1}.'.format(self.__class__.__name__, self.nomad_resp.text)
#         else:
#             return 'The {0} was raised due to the following error: {1}'.format(self.__class__.__name__,  str(self.nomad_resp))


import os
import pytest
import json
import responses
import tests.common as common
from nomad.api.exceptions import BaseNomadException


# fix No data when you are using namespaces #82
@responses.activate
def test_get_jobs_with_namespace(nomad_setup_with_namespace):
    responses.add(
        responses.GET,
        "http://{ip}:{port}/v1/jobs?namespace={namespace}".format(ip=common.IP, port=common.NOMAD_PORT, namespace=common.NOMAD_NAMESPACE),
        status=200,
        json=[{"Region": "global","ID": "my-job", "ParentID": "", "Name": "my-job","Namespace": common.NOMAD_NAMESPACE, "Type": "batch", "Priority": 50}]
    )
    assert common.NOMAD_NAMESPACE in nomad_setup_with_namespace.jobs.get_jobs()[0]["Namespace"]


@responses.activate
def test_get_jobs_with_namespace_override_no_namespace_declared_on_create_incorrect_declared_namespace(nomad_setup):
    responses.add(
        responses.GET,
        "http://{ip}:{port}/v1/jobs?namespace={namespace}".format(ip=common.IP, port=common.NOMAD_PORT, namespace=common.NOMAD_NAMESPACE),
        status=200,
        json=[{"Region": "global","ID": "my-job", "ParentID": "", "Name": "my-job","Namespace": common.NOMAD_NAMESPACE, "Type": "batch", "Priority": 50}]
    )

    with pytest.raises(BaseNomadException):
        nomad_setup.jobs.get_jobs(namespace="should-raise")


@responses.activate
def test_get_jobs_with_namespace_override_no_namespace_declared_on_create(nomad_setup):
    responses.add(

# Path: nomad/api/exceptions.py
# class BaseNomadException(Exception):
#     """General Error occurred when interacting with nomad API"""
#     def __init__(self, nomad_resp):
#         self.nomad_resp = nomad_resp
# 
#     def __str__(self):
#         if isinstance(self.nomad_resp, requests.Response) and hasattr(self.nomad_resp, "text"):
#             return 'The {0} was raised with following response: {1}.'.format(self.__class__.__name__, self.nomad_resp.text)
#         else:
#             return 'The {0} was raised due to the following error: {1}'.format(self.__class__.__name__,  str(self.nomad_resp))


# Path: tests/test_jobs.py
import os
import pytest
import json
import responses
import tests.common as common
from nomad.api.exceptions import BaseNomadException



# fix No data when you are using namespaces #82
@responses.activate
def test_get_jobs_with_namespace(nomad_setup_with_namespace):
    responses.add(
        responses.GET,
        "http://{ip}:{port}/v1/jobs?namespace={namespace}".format(ip=common.IP, port=common.NOMAD_PORT, namespace=common.NOMAD_NAMESPACE),
        status=200,
        json=[{"Region": "global","ID": "my-job", "ParentID": "", "Name": "my-job","Namespace": common.NOMAD_NAMESPACE, "Type": "batch", "Priority": 50}]
    )
    assert common.NOMAD_NAMESPACE in nomad_setup_with_namespace.jobs.get_jobs()[0]["Namespace"]


@responses.activate
def test_get_jobs_with_namespace_override_no_namespace_declared_on_create_incorrect_declared_namespace(nomad_setup):
    responses.add(
        responses.GET,
        "http://{ip}:{port}/v1/jobs?namespace={namespace}".format(ip=common.IP, port=common.NOMAD_PORT, namespace=common.NOMAD_NAMESPACE),
        status=200,
        json=[{"Region": "global","ID": "my-job", "ParentID": "", "Name": "my-job","Namespace": common.NOMAD_NAMESPACE, "Type": "batch", "Priority": 50}]
    )

    with pytest.raises(BaseNomadException):
        nomad_setup.jobs.get_jobs(namespace="should-raise")


@responses.activate
def test_get_jobs_with_namespace_override_no_namespace_declared_on_create(nomad_setup):
    responses.add(

        responses.GET,