Ejemplo n.º 1
0
    def test_update(self):
        """
        Test if the update_fields and not default fields are used in a get.
        """

        get_fields = dict(name="foo")

        default_fields = dict(is_active=True, description="A description", path="/bar/foo")

        update_fields = dict(is_active=False, path="foo/bar")

        repo = django.update_or_create(
            models.ExperimentRepository,
            get_fields=get_fields,
            default_fields=default_fields,
            update_fields=update_fields,
        )

        # Now, we update repo.
        repo = django.update_or_create(
            models.ExperimentRepository,
            get_fields=get_fields,
            default_fields=default_fields,
            update_fields=update_fields,
        )

        # It should have the attributes in updates fields.
        for attr in update_fields:
            self.assertEqual(getattr(repo, attr), update_fields[attr])
Ejemplo n.º 2
0
    def test_default(self):
        """
        Test the default fields and not update fields are used in the creation
        of the object.
        """

        get_fields = dict(name="foo")

        default_fields = dict(is_active=True, description="A description", path="/bar/foo")

        update_fields = dict(is_active=False, path="foo/bar")

        repo = django.update_or_create(
            models.ExperimentRepository,
            get_fields=get_fields,
            default_fields=default_fields,
            update_fields=update_fields,
        )

        # Make a union of both dictionaries.
        get_and_default_fields = {}
        get_and_default_fields.update(get_fields)
        get_and_default_fields.update(default_fields)

        # It should have the attributes in get_fields and default_fields.
        for attr in get_and_default_fields:
            self.assertEqual(getattr(repo, attr), get_and_default_fields[attr])

        # It should not have the attributes in updates.
        for attr in update_fields:
            self.assertNotEqual(getattr(repo, attr), update_fields[attr])
    def handle(self, *args, **options):

        for arg in args:

            C = configobj.ConfigObj(arg)

            try:

                for repository_name, repository_details in C['repository'].items():

                    path, since, until, include, exclude\
                        = parse_repository(repository_details)

                    repository = update_or_create(
                        ExperimentRepository,
                        get_fields = {'name':repository_name},
                        update_fields = {'path':path,
                                         'since':since,
                                         'until':until}
                                     )

                    if include:
                        repository.set_included_commits(include)
                    
                    if exclude:
                        repository.set_excluded_commits(exclude)



            except KeyError:

                self.stderr.write('The cfg file should contain a [repository] entry.')
                raise
Ejemplo n.º 4
0
    def test_retrieve(self):
        """
        Create an object with update_or_create.
        Check if subsequent call to update_or_create will retrieve it.
        """
        get_fields = dict(name="foo", description="A description", path="/foo/bar")

        repo = django.update_or_create(models.ExperimentRepository, get_fields=get_fields)

        # We should *retrieve* the above object here.
        alt_repo = django.update_or_create(models.ExperimentRepository, get_fields=get_fields)

        self.assertEqual(alt_repo, repo)

        # Clean up.
        repo.delete()
        alt_repo.delete()
Ejemplo n.º 5
0
    def test_create(self):
        """
        Create an object with update_or_create.
        Check its attributes are correct.
        """

        get_fields = dict(name="foo", description="A description", path="/foo/bar")

        repo = django.update_or_create(models.ExperimentRepository, get_fields=get_fields)

        # It should have the attributes in get_fields.
        for attr in get_fields:
            self.assertEqual(getattr(repo, attr), get_fields[attr])

        # Clean up.
        repo.delete()