def test_del_by_region_id_tx(mocker):
    from console.services.region_services import region_services
    from console.models.main import RegionConfig

    RegionConfig.objects.create(**region_config_data)
    mocker.patch(
        "console.services.region_services.region_services.update_region_config",
        side_effect=Exception('Boom!'))
    with pytest.raises(Exception):
        region_services.del_by_region_id("3dddf798efc34be4acbd1442a81daff2")
    region = RegionConfig.objects.get(
        region_id="3dddf798efc34be4acbd1442a81daff2")
    assert region.region_id == "3dddf798efc34be4acbd1442a81daff2"
def test_del_by_region_ok():
    from console.services.region_services import region_services
    from console.models.main import RegionConfig

    region_config_data["status"] = 1
    RegionConfig.objects.create(**region_config_data)
    region_services.update_region_config()
    region_services.check_region_in_config("test-region")
    region_services.del_by_region_id("3dddf798efc34be4acbd1442a81daff2")

    with pytest.raises(RegionConfig.DoesNotExist):
        RegionConfig.objects.get(region_id="3dddf798efc34be4acbd1442a81daff2")

    assert region_services.check_region_in_config("test-region")
Esempio n. 3
0
 def delete(self, request, region_id):
     try:
         region = region_services.del_by_region_id(region_id)
         serializer = RegionInfoSerializer(data=region)
         serializer.is_valid(raise_exception=True)
         return Response(serializer.data, status.HTTP_200_OK)
     except RegionConfig.DoesNotExist:
         # TODO: raise exception or return Response
         return Response({"msg": "修改的数据中心不存在"}, status=status.HTTP_404_NOT_FOUND)
def test_del_by_region_id_not_found():
    from console.services.region_services import region_services
    from console.models.main import RegionConfig
    with pytest.raises(RegionConfig.DoesNotExist):
        region_services.del_by_region_id("foobar")