def test_set_cpu_price(self, session, create_server_cluster_test_data):
     test_cluster_id = 2
     test_new_cpu_price = 5.2
     ClusterManager(session).set_cpu_price(cluster_id=test_cluster_id,
                                           new_cpu_price=test_new_cpu_price)
     cluster_cpu_price = (session.query(
         Cluster.cpu_price).filter_by(id=test_cluster_id).scalar())
     assert cluster_cpu_price == test_new_cpu_price
 def test_set_cpu_price_when_cluster_doesnt_exists(self, session):
     test_cluster_id = 2
     test_new_cpu_price = 5.2
     with pytest.raises(ClusterManagerException) as excinfo:
         ClusterManager(session).set_cpu_price(
             cluster_id=test_cluster_id, new_cpu_price=test_new_cpu_price)
     assert EXC_CLUSTER_DOESNT_EXISTS.format(test_cluster_id) in str(
         excinfo.value)
 def test_set_memory_price_when_price_was_set(
         self, session, create_server_cluster_test_data):
     test_cluster_id = 1
     test_new_memory_price = 4.2
     old_cluster_memory_price = (session.query(
         Cluster.memory_price).filter_by(id=test_cluster_id).scalar())
     ClusterManager(session).set_memory_price(
         cluster_id=test_cluster_id, new_memory_price=test_new_memory_price)
     new_cluster_memory_price = (session.query(
         Cluster.memory_price).filter_by(id=test_cluster_id).scalar())
     assert new_cluster_memory_price != old_cluster_memory_price
     assert new_cluster_memory_price == test_new_memory_price
示例#4
0
    def dispatch_request(self):
        data_for_update = json.loads(request.data)

        for parameter in PARAMETERS_SERVER_CLUSTER_CPU_PRICE:
            if parameter not in data_for_update:
                return (
                    jsonify({"error":
                             EXC_FIELD_IS_REQUIRED.format(parameter)}),
                    400,
                )
        try:
            valid_data_for_create = UpdateServerClusterModel(**data_for_update)
        except ValidationError as e:
            return jsonify({"error": e.errors()}), 400
        try:
            ClusterManager(db.session).set_cpu_price(
                cluster_id=valid_data_for_create.id,
                new_cpu_price=valid_data_for_create.cpu_price,
            )
        except ClusterManagerException as exc:
            return jsonify({"error": exc.error_text}), 400
        return jsonify({"success": True})