def test_get_json(self):
     expected = [
         {
             "name": "Baked Beans",
             "price": 0.99
         },
         {
             "name": "Biscuits",
             "price": 1.2
         },
         {
             "name": "Sardines",
             "price": 1.89
         },
         {
             "name": "Shampoo (Small)",
             "price": 2.0
         },
         {
             "name": "Shampoo (Medium)",
             "price": 2.5
         },
         {
             "name": "Shampoo (Large)",
             "price": 3.5
         },
     ]
     json_ = get_json("products.json")
     self.assertEqual(json_, expected)
Beispiel #2
0
 def _json2discounts(self, json_file_path: str) -> None:
     json_ = get_json(json_file_path)
     for discount in json_:
         discount_class = self.available_offers[discount["offer"]]
         # ignore as the base class does not have a second arg
         discont_obj = discount_class(discount["name"],
                                      discount["value"])  # type: ignore
         self.append(discont_obj)
Beispiel #3
0
	def __init__(self, path=None):
		if path is None:
			path = DEFAULT_PATH

		self.path = realpath(expanduser(path))
		self.raw = None
		if isfile(self.path):
			self.raw = get_json(self.path)
		if self.raw is None:
			self.raw = DEFAULT_BRAIN
Beispiel #4
0
    def __init__(self, path=None):
        if path is None:
            path = DEFAULT_PATH

        self.path = realpath(expanduser(path))
        self.raw = None
        if isfile(self.path):
            self.raw = get_json(self.path)
        if self.raw is None:
            self.raw = DEFAULT_BRAIN
Beispiel #5
0
def test_delete_pod_without_uuid_failure(context, monkeypatch):
    patch_k8s(monkeypatch)

    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()

    req = _client.delete("/pods/")
    assert req.status_code == 400
    data = get_json(req.data)
    assert 'The slave is unknown.' in data['message']
Beispiel #6
0
def test_get_pods(context, monkeypatch):
    patch_k8s(monkeypatch)

    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()
    req = _client.get("/pods")
    assert req.status_code == 200
    assert req.data
    data = get_json(req.data)
    assert isinstance(data, dict)
    assert "pods" in data
Beispiel #7
0
def test_add_pods_with_no_data_failure(context, monkeypatch):
    patch_k8s(monkeypatch)
    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()
    req = _client.post("/pods",
                       data=json.dumps({}),
                       headers={'Content-Type': 'application/json'})
    assert req.status_code == 400
    assert req.data
    data = get_json(req.data)
    assert 'The slave is unknown.' in data['message']
Beispiel #8
0
def test_add_pods_without_pipeline_with_good_slave_name(context, monkeypatch):
    patch_k8s(monkeypatch)

    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()
    data = {
        "slave_name": "active_context",
    }
    req = _client.post("/pods",
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    assert req.status_code == 200
    assert req.data
    data = get_json(req.data)
    assert isinstance(data, dict)
    assert "pods" in data
    assert data["pods"]
Beispiel #9
0
def test_add_pods_without_pipeline_with_bad_slave_name_failure(
        context, monkeypatch):
    patch_k8s(monkeypatch)

    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()
    data = {
        "slave_name": "test",
    }
    req = _client.post("/pods",
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    assert req.status_code == 400
    assert req.data
    data = get_json(req.data)
    assert isinstance(data, dict)
    assert 'The slave is unknown.' in data['message']
Beispiel #10
0
def test_add_pods_with_empty_security_pipeline_failure(context, monkeypatch):
    patch_k8s(monkeypatch)

    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()
    data = {
        "keystone_project_id": context.get('project_id'),
        "pdp_id": context.get('pdp_id'),
        "security_pipeline": "",
    }
    req = _client.post("/pods",
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    assert req.status_code == 400
    assert req.data
    data = get_json(req.data)
    assert 'The policy is unknown.' in data['message']
Beispiel #11
0
def test_add_pods(context, monkeypatch):
    patch_k8s(monkeypatch)

    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()
    data = {
        "keystone_project_id": context.get('project_id'),
        "pdp_id": context.get('pdp_id'),
        "security_pipeline": context.get('security_pipeline'),
    }
    req = _client.post("/pods",
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    assert req.status_code == 200
    assert req.data
    data = get_json(req.data)
    assert isinstance(data, dict)
    assert "pods" in data
    assert data["pods"]
Beispiel #12
0
def test_delete_pod_valid_uuid(context, monkeypatch):
    patch_k8s(monkeypatch)

    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()
    data = {
        "keystone_project_id": context.get('project_id'),
        "pdp_id": context.get('pdp_id'),
        "security_pipeline": context.get('security_pipeline'),
    }
    req = _client.post("/pods",
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    assert req.status_code == 200
    assert req.data
    data = get_json(req.data)
    for key in data["pods"]:
        req = _client.delete("/pods/{}".format(key))
        assert req.status_code == 200
Beispiel #13
0
def test_add_pod_with_slave_more_than_once_failure(context, monkeypatch):
    patch_k8s(monkeypatch)

    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()
    data = {
        "slave_name": "active_context",
    }
    req = _client.post("/pods",
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    req = _client.post("/pods",
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    assert req.status_code == 409
    assert req.data
    data = get_json(req.data)
    assert isinstance(data, dict)
    assert 'A Wrapper already exist for the specified slave.' in data[
        'message']
Beispiel #14
0
def test_add_different_pods_with_same_keystone_project_id_failure(
        context, monkeypatch):
    patch_k8s(monkeypatch)

    import moon_orchestrator.server
    server = moon_orchestrator.server.create_server()
    _client = server.app.test_client()
    data = {
        "keystone_project_id": context.get('project_id'),
        "pdp_id": context.get('pdp_id'),
        "security_pipeline": context.get('security_pipeline'),
    }
    req = _client.post("/pods",
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    data["pdp_id"] = data["pdp_id"] + "xyz"
    req = _client.post("/pods",
                       data=json.dumps(data),
                       headers={'Content-Type': 'application/json'})
    assert req.status_code == 409
    data = get_json(req.data)
    assert isinstance(data, dict)
    assert 'A Pipeline already exist for the specified slave.' in data[
        'message']
Beispiel #15
0
 def _json2items(self, json_file_path: str) -> None:
     json_ = get_json(json_file_path)
     for item in json_:
         self.append(Item(name=item["name"], price=item["price"]))