Example #1
0
def create_helper_repo(name="foobaz", provides=None):
    """
    Create a backup and/or intended repo to test helper functions.
    """
    content_provides = f"nautobot_golden_config.{provides}"
    git_repo = GitRepository(
        name=name,
        slug=slugify(name),
        remote_url=f"http://www.remote-repo.com/{name}.git",
        branch="main",
        username="******",
        provided_contents=[
            entry.content_identifier
            for entry in get_datasource_contents("extras.gitrepository")
            if entry.content_identifier == content_provides
        ],
    )
    git_repo.save(trigger_resync=False)
Example #2
0
    def setUp(self):
        self.user = User.objects.create_user(username="******")
        self.factory = RequestFactory()
        self.dummy_request = self.factory.get("/no-op/")
        self.dummy_request.user = self.user
        # Needed for use with the change_logging decorator
        self.dummy_request.id = uuid.uuid4()

        self.site = Site.objects.create(name="Test Site", slug="test-site")
        self.manufacturer = Manufacturer.objects.create(name="Acme",
                                                        slug="acme")
        self.device_type = DeviceType.objects.create(
            manufacturer=self.manufacturer,
            model="Frobozz 1000",
            slug="frobozz1000")
        self.role = DeviceRole.objects.create(name="router", slug="router")
        self.device_status = Status.objects.get_for_model(Device).get(
            slug="active")
        self.device = Device.objects.create(
            name="test-device",
            device_role=self.role,
            device_type=self.device_type,
            site=self.site,
            status=self.device_status,
        )

        self.repo = GitRepository(
            name="Test Git Repository",
            slug="test_git_repo",
            remote_url="http://localhost/git.git",
            # Provide everything we know we can provide
            provided_contents=[
                entry.content_identifier
                for entry in get_datasource_contents("extras.gitrepository")
            ],
        )
        self.repo.save(trigger_resync=False)

        self.job_result = JobResult(
            name=self.repo.name,
            obj_type=ContentType.objects.get_for_model(GitRepository),
            job_id=uuid.uuid4(),
        )
Example #3
0
def create_git_repos() -> None:
    """Create five instances of Git Repos.

    Two GitRepository objects provide Backups.
    Two GitRepository objects provide Intended.
    One GitRepository objects provide Jinja Templates.
    The provided content is matched through a loop, in order to prevent any errors if object ID's change.
    """
    name = "test-backup-repo-1"
    provides = "nautobot_golden_config.backupconfigs"
    git_repo_1 = GitRepository(
        name=name,
        slug=slugify(name),
        remote_url=f"http://www.remote-repo.com/{name}.git",
        branch="main",
        username="******",
        provided_contents=[
            entry.content_identifier
            for entry in get_datasource_contents("extras.gitrepository")
            if entry.content_identifier == provides
        ],
    )
    git_repo_1.save(trigger_resync=False)

    name = "test-backup-repo-2"
    provides = "nautobot_golden_config.backupconfigs"
    git_repo_2 = GitRepository(
        name=name,
        slug=slugify(name),
        remote_url=f"http://www.remote-repo.com/{name}.git",
        branch="main",
        username="******",
        provided_contents=[
            entry.content_identifier
            for entry in get_datasource_contents("extras.gitrepository")
            if entry.content_identifier == provides
        ],
    )
    git_repo_2.save(trigger_resync=False)

    name = "test-intended-repo-1"
    provides = "nautobot_golden_config.intendedconfigs"
    git_repo_3 = GitRepository(
        name=name,
        slug=slugify(name),
        remote_url=f"http://www.remote-repo.com/{name}.git",
        branch="main",
        username="******",
        provided_contents=[
            entry.content_identifier
            for entry in get_datasource_contents("extras.gitrepository")
            if entry.content_identifier == provides
        ],
    )
    git_repo_3.save(trigger_resync=False)

    name = "test-intended-repo-2"
    provides = "nautobot_golden_config.intendedconfigs"
    git_repo_4 = GitRepository(
        name=name,
        slug=slugify(name),
        remote_url=f"http://www.remote-repo.com/{name}.git",
        branch="main",
        username="******",
        provided_contents=[
            entry.content_identifier
            for entry in get_datasource_contents("extras.gitrepository")
            if entry.content_identifier == provides
        ],
    )
    git_repo_4.save(trigger_resync=False)

    name = "test-jinja-repo-1"
    provides = "nautobot_golden_config.jinjatemplate"
    git_repo_5 = GitRepository(
        name=name,
        slug=slugify(name),
        remote_url=f"http://www.remote-repo.com/{name}.git",
        branch="main",
        username="******",
        provided_contents=[
            entry.content_identifier
            for entry in get_datasource_contents("extras.gitrepository")
            if entry.content_identifier == provides
        ],
    )
    git_repo_5.save(trigger_resync=False)
Example #4
0
    def setUp(self):
        # Repopulate custom statuses between test cases, as TransactionTestCase deletes them during cleanup
        create_custom_statuses(None, verbosity=0)

        self.user = User.objects.create_user(username="******")
        self.factory = RequestFactory()
        self.mock_request = self.factory.get("/no-op/")
        self.mock_request.user = self.user
        # Needed for use with the change_logging decorator
        self.mock_request.id = uuid.uuid4()

        self.site = Site.objects.create(name="Test Site", slug="test-site")
        self.manufacturer = Manufacturer.objects.create(name="Acme", slug="acme")
        self.device_type = DeviceType.objects.create(
            manufacturer=self.manufacturer, model="Frobozz 1000", slug="frobozz1000"
        )
        self.role = DeviceRole.objects.create(name="router", slug="router")
        self.device_status = Status.objects.get_for_model(Device).get(slug="active")
        self.device = Device.objects.create(
            name="test-device",
            device_role=self.role,
            device_type=self.device_type,
            site=self.site,
            status=self.device_status,
        )

        self.repo = GitRepository(
            name="Test Git Repository",
            slug="test_git_repo",
            remote_url="http://localhost/git.git",
            # Provide everything we know we can provide
            provided_contents=[entry.content_identifier for entry in get_datasource_contents("extras.gitrepository")],
        )
        self.repo.save(trigger_resync=False)

        self.job_result = JobResult.objects.create(
            name=self.repo.name,
            obj_type=ContentType.objects.get_for_model(GitRepository),
            job_id=uuid.uuid4(),
        )

        self.config_context_schema = {
            "_metadata": {
                "name": "Config Context Schema 1",
                "description": "Schema for defining first names, last names and ages.",
            },
            "data_schema": {
                "title": "Person",
                "type": "object",
                "properties": {
                    "firstName": {
                        "type": "string",
                        "description": "The person's first name.",
                    },
                    "lastName": {
                        "type": "string",
                        "description": "The person's last name.",
                    },
                    "age": {
                        "description": "Age in years which must be equal to or greater than zero.",
                        "type": "integer",
                        "minimum": 0,
                    },
                },
            },
        }