Beispiel #1
0
 def setUp(self):
     super(RevisionTestCase, self).setUp()
     self.revision = Revision(pull=mock.MagicMock(
         issue_nr=1,
         head_ref=generate_verba_branch_name('test title', 'test-owner'),
         title='rev title',
         labels=config.LABELS.ALLOWED + ['another-label'],
         assignees=config.ASSIGNEES.ALLOWED + ['another-user']))
Beispiel #2
0
def add_software(request):
    """
    Show the software form, and capture the information
    """

    if not request.user.is_authenticated():
       return HttpResponseRedirect('/accounts/login?next=%s' % request.path)

    original_id = request.GET.get('oid', None)

    if request.method == 'POST':
        new_data = request.POST.copy()
        new_data.update(request.FILES)
        form = SoftwareForm(new_data)

        if form.is_valid():
            new_software = Software(user=request.user,
                                    title=form.cleaned_data['title'])
            if original_id:
                new_software.original_id = original_id
            new_software.save()

            try:
                new_revision = Revision(software=new_software,
                                        version=form.cleaned_data['version'],
                                        authors=form.cleaned_data['authors'],
                                        contact=form.cleaned_data['contact'],
                                        short_description=form.cleaned_data['short_description'],
                                        description=form.cleaned_data['description'],
                                        changes='Initial Announcement on mloss.org.',
                                        project_url=form.cleaned_data['project_url'],
                                        tags=form.cleaned_data['tags'],
                                        language=form.cleaned_data['language'],
                                        operating_systems = form.cleaned_data['operating_systems'],
                                        dataformats = form.cleaned_data['dataformats'],
                                        os_license=form.cleaned_data['os_license'],
                                        paper_bib = form.cleaned_data['paper_bib'],
                                        download_url=form.cleaned_data['download_url'],
                                        tarball=form.cleaned_data['tarball'],
                                        thumbnail=form.cleaned_data['thumbnail'],
                                        screenshot=form.cleaned_data['screenshot'],
                                        )
                if original_id:
                    new_revision.original_id = original_id

                save_tarball(request, new_revision)
                save_images(request, new_revision, old_revision = None)
                new_revision.save()
                return HttpResponseRedirect(new_revision.get_absolute_url())
            except:
                new_software.delete()
    else:
        form = SoftwareForm(initial={'user':request.user,
            'changes':'Initial Announcement on mloss.org.'})

    return render_to_response('software/software_add.html',
                              { 'form': form },
                              context_instance=RequestContext(request))
Beispiel #3
0
def add(request, customer_id):
    try:
        customer = Customer.objects.get(pk=customer_id)
    except Customer.DoesNotExist:
        raise Http404

    if request.method == "POST":
        form = DomainForm(customer, request.POST)
        if form.is_valid():
            new_domain = form.save(commit=False)
            new_domain.customer_id = customer.id
            new_domain.save()
            form.save_m2m()

            ns_all = new_domain.nameservers.all()

            # create the first revision
            first_revision = Revision(
                domain=new_domain, revisionstate=RevisionState.objects.filter(name="edit"), name="Revision #1"
            )
            first_revision.save()

            # create the first record
            # create SOA
            #            soa = Record(
            #                revision = first_revision,
            #                host = '@',
            #                recordtype = RecordType.objects.filter(label='SOA'),
            #                data = models.CharField(max_length=100, null=True, blank=True)
            #                ttl = 10800)
            #                serial = models.BigIntegerField(null=True, blank=True)
            #                refresh = models.PositiveIntegerField(null=True, blank=True)
            #                retry = models.PositiveIntegerField(null=True, blank=True)
            #                expire = models.PositiveIntegerField(null=True, blank=True)
            #                minimum = models.PositiveIntegerField(null=True, blank=True)
            #                resp_person = new_domain.adminc_id,
            #                primary_ns = ns_all[0]
            #            )
            #            soa.save()

            # create NS
            #            for ns in ns_all
            #                ns = Record(
            #                    revision = first_revision,
            #                    host = '@',
            #                    recordtype = RecordType.objects.filter(label='NS'),
            #                    data = ns.hostname,
            #                    ttl = default=10800,
            #                )
            #                ns.save()

            return HttpResponseRedirect("/domain/%d" % customer.id)
    else:
        form = DomainForm(customer)

    return render(request, "domain/add.html", {"customer": customer, "form": form})
Beispiel #4
0
 def setUp(self):
     super(RevisionTestCase, self).setUp()
     self.revision = Revision(
         pull=mock.MagicMock(
             issue_nr=1,
             head_ref=generate_verba_branch_name('test title', 'test-owner'),
             title='rev title',
             labels=config.LABELS.ALLOWED + ['another-label'],
             assignees=config.ASSIGNEES.ALLOWED + ['another-user']
         )
     )
Beispiel #5
0
def add_software(request):
    """
    Show the software form, and capture the information
    """

    if not request.user.is_authenticated():
        return HttpResponseRedirect('/accounts/login?next=%s' % request.path)

    original_id = request.GET.get('oid', None)

    if request.method == 'POST':
        new_data = request.POST.copy()
        new_data.update(request.FILES)
        form = SoftwareForm(new_data)

        if form.is_valid():
            new_software = Software(user=request.user,
                                    title=form.cleaned_data['title'])
            if original_id:
                new_software.original_id = original_id
            new_software.save()

            try:
                new_revision = Revision(
                    software=new_software,
                    version=form.cleaned_data['version'],
                    authors=form.cleaned_data['authors'],
                    contact=form.cleaned_data['contact'],
                    short_description=form.cleaned_data['short_description'],
                    description=form.cleaned_data['description'],
                    changes='Initial Announcement on mloss.org.',
                    project_url=form.cleaned_data['project_url'],
                    tags=form.cleaned_data['tags'],
                    language=form.cleaned_data['language'],
                    operating_systems=form.cleaned_data['operating_systems'],
                    dataformats=form.cleaned_data['dataformats'],
                    os_license=form.cleaned_data['os_license'],
                    paper_bib=form.cleaned_data['paper_bib'],
                    download_url=form.cleaned_data['download_url'],
                    tarball=form.cleaned_data['tarball'],
                    thumbnail=form.cleaned_data['thumbnail'],
                    screenshot=form.cleaned_data['screenshot'],
                )
                if original_id:
                    new_revision.original_id = original_id

                save_tarball(request, new_revision)
                save_images(request, new_revision, old_revision=None)
                new_revision.save()
                return HttpResponseRedirect(new_revision.get_absolute_url())
            except:
                new_software.delete()
    else:
        form = SoftwareForm(initial={
            'user': request.user,
            'changes': 'Initial Announcement on mloss.org.'
        })

    return render_to_response('software/software_add.html', {'form': form},
                              context_instance=RequestContext(request))
Beispiel #6
0
def edit_software(request, software_id, revision_id=0):
    """
    Show the software form, and capture the information
    """

    if not request.user.is_authenticated():
        return HttpResponseRedirect('/accounts/login?next=%s' % request.path)

    original_id = request.GET.get('oid', None)

    if request.user.is_superuser:
        software = get_object_or_404(Software,
                pk=software_id)
    else:
        software = get_object_or_404(Software,
                pk=software_id,
                user__pk=request.user.id)

    if revision_id:
        revision = get_object_or_404(Revision,
                pk=revision_id, software = software)
        form_class = RevisionForm
    else:
        revision = software.get_latest_revision()
        form_class = UpdateSoftwareForm

    form=form_class(revision)

    if request.method == 'POST':
        new_data = request.POST.copy()
        new_data.update(request.FILES)
        form = form_class(new_data)

        if form.is_valid():
            if form.cleaned_data['title'] != software.title or ( revision_id
                    and form.cleaned_data['version'] != revision.version ):
                return HttpResponseForbidden()

            new_revision = Revision(software=software,
                                    version=form.cleaned_data['version'],
                                    authors=form.cleaned_data['authors'],
                                    contact=form.cleaned_data['contact'],
                                    short_description=form.cleaned_data['short_description'],
                                    description=form.cleaned_data['description'],
                                    changes=form.cleaned_data['changes'],
                                    project_url=form.cleaned_data['project_url'],
                                    tags=form.cleaned_data['tags'],
                                    language=form.cleaned_data['language'],
                                    operating_systems = form.cleaned_data['operating_systems'],
                                    dataformats = form.cleaned_data['dataformats'],
                                    os_license=form.cleaned_data['os_license'],
                                    paper_bib = form.cleaned_data['paper_bib'],
                                    download_url=form.cleaned_data['download_url'],
                                    tarball=form.cleaned_data['tarball'],
                                    thumbnail=form.cleaned_data['thumbnail'],
                                    screenshot=form.cleaned_data['screenshot'],
                                    )
            if original_id:
                new_revision.original_id = original_id

            if new_revision.version != revision.version:
                for field in editables:
                    if not field in dontupdateifempty or form.cleaned_data[field]:
                        setattr(new_revision, field, form.cleaned_data[field])
                new_revision.jmlr_mloss_url = revision.jmlr_mloss_url

                if form.cleaned_data['download_url'] and len(form.cleaned_data['download_url'])>0:
                    new_revision.tarball = None
                else:
                    save_tarball(request, new_revision)

                save_images(request, new_revision, old_revision=revision)
                software.increment_revisions()
                new_revision.save()
                return HttpResponseRedirect(new_revision.get_absolute_url())
            else:
                for field in editables:
                    if not field in dontupdateifempty or form.cleaned_data[field]:
                        setattr(revision, field, form.cleaned_data[field])

                if form.cleaned_data['download_url'] and len(form.cleaned_data['download_url'])>0:
                    revision.tarball = None
                else:
                    save_tarball(request, revision)

                save_images(request, revision, old_revision = revision)
                revision.save(silent_update=True)
                return HttpResponseRedirect(revision.get_absolute_url())
    else:
        form = form_class(revision)

    return render(request, 'software/software_add.html',
                              { 'form': form })
Beispiel #7
0
def edit_software(request, software_id, revision_id=0):
    """
    Show the software form, and capture the information
    """

    if not request.user.is_authenticated():
        return HttpResponseRedirect('/accounts/login?next=%s' % request.path)

    original_id = request.GET.get('oid', None)

    if request.user.is_superuser:
        software = get_object_or_404(Software, pk=software_id)
    else:
        software = get_object_or_404(Software,
                                     pk=software_id,
                                     user__pk=request.user.id)

    if revision_id:
        revision = get_object_or_404(Revision,
                                     pk=revision_id,
                                     software=software)
        form_class = RevisionForm
    else:
        revision = software.get_latest_revision()
        form_class = UpdateSoftwareForm

    if request.method == 'POST':
        new_data = request.POST.copy()
        new_data.update(request.FILES)
        form = form_class(new_data)

        if form.is_valid():
            if form.cleaned_data['title'] != software.title or (
                    revision_id
                    and form.cleaned_data['version'] != revision.version):
                return HttpResponseForbidden()

            new_revision = Revision(
                software=software,
                version=form.cleaned_data['version'],
                authors=form.cleaned_data['authors'],
                contact=form.cleaned_data['contact'],
                short_description=form.cleaned_data['short_description'],
                description=form.cleaned_data['description'],
                changes=form.cleaned_data['changes'],
                project_url=form.cleaned_data['project_url'],
                tags=form.cleaned_data['tags'],
                language=form.cleaned_data['language'],
                operating_systems=form.cleaned_data['operating_systems'],
                dataformats=form.cleaned_data['dataformats'],
                os_license=form.cleaned_data['os_license'],
                paper_bib=form.cleaned_data['paper_bib'],
                download_url=form.cleaned_data['download_url'],
                tarball=form.cleaned_data['tarball'],
                thumbnail=form.cleaned_data['thumbnail'],
                screenshot=form.cleaned_data['screenshot'],
            )
            if original_id:
                new_revision.original_id = original_id

            if new_revision.version != revision.version:
                for field in editables:
                    if not field in dontupdateifempty or form.cleaned_data[
                            field]:
                        setattr(new_revision, field, form.cleaned_data[field])
                new_revision.jmlr_mloss_url = revision.jmlr_mloss_url

                if form.cleaned_data['download_url'] and len(
                        form.cleaned_data['download_url']) > 0:
                    new_revision.tarball = None
                else:
                    save_tarball(request, new_revision)

                save_images(request, new_revision, old_revision=revision)
                software.increment_revisions()
                new_revision.save()
                return HttpResponseRedirect(new_revision.get_absolute_url())
            else:
                for field in editables:
                    if not field in dontupdateifempty or form.cleaned_data[
                            field]:
                        setattr(revision, field, form.cleaned_data[field])

                if form.cleaned_data['download_url'] and len(
                        form.cleaned_data['download_url']) > 0:
                    revision.tarball = None
                else:
                    save_tarball(request, revision)

                save_images(request, revision, old_revision=revision)
                revision.save(silent_update=True)
                return HttpResponseRedirect(revision.get_absolute_url())
    else:
        form = form_class(revision)

    return render_to_response('software/software_add.html', {'form': form},
                              context_instance=RequestContext(request))
Beispiel #8
0
    def insert_into_database(self):
        """
        For a given CRANPackage construct Software object and insert it into database
        """
        try:
            me = User.objects.get(username=settings.R_CRAN_BOT)
        except User.DoesNotExist:
            import string
            from random import Random
            newpasswd = ''.join( Random().sample(string.letters+string.digits, 32) ) 

            user = User.objects.create_user(settings.R_CRAN_BOT, settings.R_CRAN_BOT + '@mloss.org', newpasswd)
            user.save()
            me = User.objects.get(username=settings.R_CRAN_BOT)


        #don't insert crappy items having future date
        if self.date<datetime.datetime.now():
            # check whether the package exists (without prefix)
            dbpkg = Software.objects.filter(title=self.name)
            if dbpkg.count() > 0:
                return

            # check whether the package exists (without prefix)
            dbpkg = Software.objects.filter(user=me, title=self.prefix+self.name)
            if dbpkg.count() == 0:
                # if not create a new Software project
                spkg = Software(user=me, title=self.prefix+self.name)
                spkg.save(silent_update=True)
                try:
                    srev = Revision(software=spkg, version=self.version, short_description=self.short_description,
                                    description=self.description, os_license=self.os_license,
                                    language='R', operating_systems='agnostic',
                                    download_url=self.url, project_url=self.url, tags='r-cran',
                                    pub_date=self.date, updated_date=self.date, authors=self.author,
                                    changes="Initial Announcement on mloss.org by r-cran-robot")
                    srev.save(silent_update=True)
                except:
                    spkg.delete()
            else:
                #print 'Package ' + self.name + ' found, UPDATING...'
                assert(dbpkg.count() == 1)
                spkg = dbpkg[0]

                try:
                    srev = Revision.objects.get(software=spkg, revision=0)
                    # Don't mess around with manual entries.
                    if srev.tags != 'r-cran':
                        return
                except ObjectDoesNotExist:
                    srev = None

                if srev and srev.version == self.version:
                    srev.short_description=self.short_description
                    srev.description=self.description
                    srev.os_license=self.os_license
                    srev.download_url=self.url
                    srev.project_url=self.url
                    srev.updated_date=self.date
                    srev.authors=self.author
                    srev.changes="Fetched by r-cran-robot on %s" % str(datetime.datetime.now())
                else:
                    srev = Revision(software=spkg, version=self.version, short_description=self.short_description,
                                    description=self.description, os_license=self.os_license,
                                    language='R', operating_systems='agnostic',
                                    download_url=self.url, project_url=self.url, tags='r-cran',
                                    pub_date=self.date, updated_date=self.date, authors=self.author,
                                    changes="Fetched by r-cran-robot on %s" % str(datetime.datetime.now()))
                    spkg.increment_revisions()
                srev.save(silent_update=True)
Beispiel #9
0
class RevisionTestCase(SimpleTestCase):
    def setUp(self):
        super(RevisionTestCase, self).setUp()
        self.revision = Revision(pull=mock.MagicMock(
            issue_nr=1,
            head_ref=generate_verba_branch_name('test title', 'test-owner'),
            title='rev title',
            labels=config.LABELS.ALLOWED + ['another-label'],
            assignees=config.ASSIGNEES.ALLOWED + ['another-user']))

    def test_id(self):
        self.assertEqual(self.revision.id, 1)

    def test_title(self):
        self.assertEqual(self.revision.title, 'rev title')

    def test_statuses(self):
        self.assertEqual(sorted(self.revision.statuses),
                         sorted(config.LABELS.ALLOWED))

    def test_is_in_draft_false(self):
        # no labels
        self.revision._pull.labels = []
        self.assertFalse(self.revision.is_in_draft())

        # all labels except the DRAFT one
        labels = list(config.LABELS.ALLOWED)
        labels.remove(config.LABELS.DRAFT)
        self.revision._pull.labels = labels
        self.assertFalse(self.revision.is_in_draft())

    def test_is_in_draft_true(self):
        # labels
        self.revision._pull.labels = config.LABELS.ALLOWED + ['another-label']
        self.assertTrue(self.revision.is_in_draft())

    def test_is_in_2i_false(self):
        # no labels
        self.revision._pull.labels = []
        self.assertFalse(self.revision.is_in_2i())

        # all labels except the DRAFT one
        labels = list(config.LABELS.ALLOWED)
        labels.remove(config.LABELS['2I'])
        self.revision._pull.labels = labels
        self.assertFalse(self.revision.is_in_2i())

    def test_is_in_2i_true(self):
        # labels
        self.revision._pull.labels = config.LABELS.ALLOWED + ['another-label']
        self.assertTrue(self.revision.is_in_2i())

    def test_assignees(self):
        self.assertEqual(sorted(self.revision.assignees),
                         sorted(config.ASSIGNEES.ALLOWED))

    def test_creator(self):
        self.assertEqual(self.revision.creator, 'test-owner')

    def test_move_to_draft(self):
        self.revision.move_to_draft()

        self.assertEqual(self.revision.statuses, [config.LABELS.DRAFT])
        self.assertEqual(sorted(self.revision._pull.labels),
                         sorted(['another-label', config.LABELS.DRAFT]))

        self.assertEqual(self.revision.assignees, ['test-owner'])
        self.assertEqual(sorted(self.revision._pull.assignees),
                         sorted(['another-user', 'test-owner']))

    def test_move_to_2i(self):
        self.revision.move_to_2i()

        self.assertEqual(self.revision.statuses, [config.LABELS['2I']])
        self.assertEqual(sorted(self.revision._pull.labels),
                         sorted(['another-label', config.LABELS['2I']]))

        self.assertEqual(self.revision.assignees, ['test-owner-2'])
        self.assertEqual(sorted(self.revision._pull.assignees),
                         sorted(['another-user', 'test-owner-2']))

    def test_move_to_ready_for_publishing(self):
        self.revision.move_to_ready_for_publishing()

        self.assertEqual(self.revision.statuses,
                         [config.LABELS.READY_FOR_PUBLISHING])
        self.assertEqual(
            sorted(self.revision._pull.labels),
            sorted(['another-label', config.LABELS.READY_FOR_PUBLISHING]))

        self.assertEqual(self.revision.assignees, ['test-developer'])
        self.assertEqual(sorted(self.revision._pull.assignees),
                         sorted(['another-user', 'test-developer']))

    def test_add_comment(self):
        self.revision.add_comment('test comment')
        self.assertEqual(self.revision._pull.add_comment.call_count, 1)

    def test_diff(self):
        self.revision._pull.diff = 'some diff'
        self.assertEqual(self.revision.diff, 'some diff')

    def test_activities(self):
        self.revision._pull.created_at = datetime.datetime.now()
        self.revision._pull.comments = [
            mock.MagicMock(body='test comment1'),
            mock.MagicMock(body='test comment2'),
        ]

        activities = self.revision.activities

        # first activity is 'created'
        created_activity = activities[0]
        self.assertEqual(created_activity.description, 'created this revision')
        self.assertEqual(created_activity.created_at,
                         self.revision._pull.created_at)
        self.assertEqual(created_activity.created_by, 'test-owner')

        # 2nd and 2rd, 'comment'
        self.assertEqual([comment.body for comment in activities[1:]],
                         ['test comment1', 'test comment2'])

    def test_get_files(self):
        git_files = [
            mock.MagicMock(path='{}some-path/test1/{}'.format(
                config.PATHS.CONTENT_FOLDER, CONTENT_FILE_MANIFEST)),
            mock.MagicMock(path='{}test2/manifest.txt'.format(
                config.PATHS.CONTENT_FOLDER)),
            mock.MagicMock(path='{}test3/{}'.format(
                config.PATHS.CONTENT_FOLDER, CONTENT_FILE_MANIFEST))
        ]
        self.revision._pull.branch.get_dir_files.return_value = git_files

        rev_files = self.revision.get_files()
        self.assertEqual(len(rev_files), 2)
        self.assertEqual(sorted([rev_file.path for rev_file in rev_files]),
                         ['some-path/test1', 'test3'])

    def test_get_file(self):
        path = '{}some-path/test1/{}'.format(config.PATHS.CONTENT_FOLDER,
                                             CONTENT_FILE_MANIFEST)
        rev_file = self.revision.get_file(path)

        self.assertEqual(rev_file.revision, self.revision)
Beispiel #10
0
class RevisionTestCase(SimpleTestCase):
    def setUp(self):
        super(RevisionTestCase, self).setUp()
        self.revision = Revision(
            pull=mock.MagicMock(
                issue_nr=1,
                head_ref=generate_verba_branch_name('test title', 'test-owner'),
                title='rev title',
                labels=config.LABELS.ALLOWED + ['another-label'],
                assignees=config.ASSIGNEES.ALLOWED + ['another-user']
            )
        )

    def test_id(self):
        self.assertEqual(
            self.revision.id, 1
        )

    def test_title(self):
        self.assertEqual(
            self.revision.title, 'rev title'
        )

    def test_statuses(self):
        self.assertEqual(
            sorted(self.revision.statuses),
            sorted(config.LABELS.ALLOWED)
        )

    def test_is_in_draft_false(self):
        # no labels
        self.revision._pull.labels = []
        self.assertFalse(
            self.revision.is_in_draft()
        )

        # all labels except the DRAFT one
        labels = list(config.LABELS.ALLOWED)
        labels.remove(config.LABELS.DRAFT)
        self.revision._pull.labels = labels
        self.assertFalse(
            self.revision.is_in_draft()
        )

    def test_is_in_draft_true(self):
        # labels
        self.revision._pull.labels = config.LABELS.ALLOWED + ['another-label']
        self.assertTrue(
            self.revision.is_in_draft()
        )

    def test_is_in_2i_false(self):
        # no labels
        self.revision._pull.labels = []
        self.assertFalse(
            self.revision.is_in_2i()
        )

        # all labels except the DRAFT one
        labels = list(config.LABELS.ALLOWED)
        labels.remove(config.LABELS['2I'])
        self.revision._pull.labels = labels
        self.assertFalse(
            self.revision.is_in_2i()
        )

    def test_is_in_2i_true(self):
        # labels
        self.revision._pull.labels = config.LABELS.ALLOWED + ['another-label']
        self.assertTrue(
            self.revision.is_in_2i()
        )

    def test_assignees(self):
        self.assertEqual(
            sorted(self.revision.assignees),
            sorted(config.ASSIGNEES.ALLOWED)
        )

    def test_creator(self):
        self.assertEqual(
            self.revision.creator,
            'test-owner'
        )

    def test_move_to_draft(self):
        self.revision.move_to_draft()

        self.assertEqual(
            self.revision.statuses,
            [config.LABELS.DRAFT]
        )
        self.assertEqual(
            sorted(self.revision._pull.labels),
            sorted(['another-label', config.LABELS.DRAFT])
        )

        self.assertEqual(
            self.revision.assignees,
            ['test-owner']
        )
        self.assertEqual(
            sorted(self.revision._pull.assignees),
            sorted(['another-user', 'test-owner'])
        )

    def test_move_to_2i(self):
        self.revision.move_to_2i()

        self.assertEqual(
            self.revision.statuses,
            [config.LABELS['2I']]
        )
        self.assertEqual(
            sorted(self.revision._pull.labels),
            sorted(['another-label', config.LABELS['2I']])
        )

        self.assertEqual(
            self.revision.assignees,
            ['test-owner-2']
        )
        self.assertEqual(
            sorted(self.revision._pull.assignees),
            sorted(['another-user', 'test-owner-2'])
        )

    def test_move_to_ready_for_publishing(self):
        self.revision.move_to_ready_for_publishing()

        self.assertEqual(
            self.revision.statuses,
            [config.LABELS.READY_FOR_PUBLISHING]
        )
        self.assertEqual(
            sorted(self.revision._pull.labels),
            sorted(['another-label', config.LABELS.READY_FOR_PUBLISHING])
        )

        self.assertEqual(
            self.revision.assignees,
            ['test-developer']
        )
        self.assertEqual(
            sorted(self.revision._pull.assignees),
            sorted(['another-user', 'test-developer'])
        )

    def test_add_comment(self):
        self.revision.add_comment('test comment')
        self.assertEqual(self.revision._pull.add_comment.call_count, 1)

    def test_diff(self):
        self.revision._pull.diff = 'some diff'
        self.assertEqual(
            self.revision.diff, 'some diff'
        )

    def test_activities(self):
        self.revision._pull.created_at = datetime.datetime.now()
        self.revision._pull.comments = [
            mock.MagicMock(body='test comment1'),
            mock.MagicMock(body='test comment2'),
        ]

        activities = self.revision.activities

        # first activity is 'created'
        created_activity = activities[0]
        self.assertEqual(created_activity.description, 'created this revision')
        self.assertEqual(created_activity.created_at, self.revision._pull.created_at)
        self.assertEqual(created_activity.created_by, 'test-owner')

        # 2nd and 2rd, 'comment'
        self.assertEqual(
            [comment.body for comment in activities[1:]],
            ['test comment1', 'test comment2']
        )

    def test_get_files(self):
        git_files = [
            mock.MagicMock(path='{}some-path/test1/{}'.format(config.PATHS.CONTENT_FOLDER, CONTENT_FILE_MANIFEST)),
            mock.MagicMock(path='{}test2/manifest.txt'.format(config.PATHS.CONTENT_FOLDER)),
            mock.MagicMock(path='{}test3/{}'.format(config.PATHS.CONTENT_FOLDER, CONTENT_FILE_MANIFEST))
        ]
        self.revision._pull.branch.get_dir_files.return_value = git_files

        rev_files = self.revision.get_files()
        self.assertEqual(len(rev_files), 2)
        self.assertEqual(
            sorted([rev_file.path for rev_file in rev_files]),
            ['some-path/test1', 'test3']
        )

    def test_get_file(self):
        path = '{}some-path/test1/{}'.format(config.PATHS.CONTENT_FOLDER, CONTENT_FILE_MANIFEST)
        rev_file = self.revision.get_file(path)

        self.assertEqual(rev_file.revision, self.revision)