Example #1
0
    def handle(self, *args, **options):
        if settings.RELEASE_ENV != "dev" and not settings.TUTORIAL_MODE:
            self.stdout.write(
                "Command can only be run on dev instances and instances "
                "with tutorial mode enabled")
            return

        if not options.get("commit"):
            self.stdout.write(
                "This will sync data from {url} to this instance, and will take "
                "roughly 20 minutes to complete on a fresh db. "
                "Run the command with `--commit` if you are sure you want "
                "to do this.".format(**options))
            return

        # settings.USE_TZ = True
        db_settings = settings.DATABASES.get("default")

        config = {
            "sync": {
                "url": options.get("url")
            },
            "orm": {
                "secret_key": settings.SECRET_KEY,
                "backend": "peeringdb_server",
                "migrate": False,
                "database": {k.lower(): v
                             for k, v in db_settings.items()},
            },
        }

        apply_defaults(ClientSchema(), config)

        pre_save.disconnect(signals.addressmodel_save,
                            sender=pdb_models.Facility)

        djpdb_models.all_models = [
            pdb_models.Organization,
            pdb_models.Facility,
            pdb_models.Network,
            pdb_models.InternetExchange,
            pdb_models.InternetExchangeFacility,
            pdb_models.IXLan,
            pdb_models.IXLanPrefix,
            pdb_models.NetworkContact,
            pdb_models.NetworkFacility,
            pdb_models.NetworkIXLan,
        ]

        SUPPORTED_BACKENDS[
            "peeringdb_server"] = "peeringdb_server.client_adaptor"

        client = Client(config)
        client.update_all(resource.all_resources(), since=None)
Example #2
0
def validate_data(model, data, strict=True):
    schema.apply_defaults(model, data)
    success, errors, warnings = schema.validate(model, data, log=print)
    # TODO make this throw actual errors, etc
    return True

    if errors:
        raise NetomValidationError("validation has errors")

    if strict and warnings:
        raise NetomValidationError("validation has warnings")

    return True
Example #3
0
def test_apply_defaults(SchemaClass, config, expected):
    if not isinstance(config, dict):
        with open(
                os.path.join(os.path.dirname(__file__), "data", "defaults",
                             config)) as fh:
            config = json.load(fh)
    if not isinstance(expected, dict):
        with open(
                os.path.join(os.path.dirname(__file__), "data", "defaults",
                             expected)) as fh:
            expected = json.load(fh)
    apply_defaults(SchemaClass(), config)
    print(json.dumps(config, indent=2))
    assert expected == config
Example #4
0
def test_apply_defaults_error():
    with pytest.raises(ApplyDefaultError):
        apply_defaults(Schema_04(), {"nested": 123})