Example #1
0
    def test_handlePushes_cause_repoerror(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file:///does/not/exist')
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
            'date': timestamp,
            'changesets': [rev0],
            'user': '******',
        })
        self.assertRaises(RepoError, handlePushes, repo.pk, [pushjs0])
Example #2
0
File: tests.py Project: gerv/elmo
    def test_file_only_copied(self):
        """Change by copying a file with no content editing"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)

        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        hgcommands.copy(ui, hgrepo, hgrepo.pathto("file.dtd"), hgrepo.pathto("newnamefile.dtd"))
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("copied from file.dtd" in re.sub("<.*?>", "", html_diff))
        ok_(re.findall(">\s*newnamefile\.dtd\s*<", html_diff))
        ok_(not re.findall(">\s*Hello\s*<", html_diff))
        ok_(not re.findall(">\s*Cruel\s*<", html_diff))
Example #3
0
    def test_handlePushes_space_files(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file:///' + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd '), 'w')  # deliberate trailing space
         .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
            'date': timestamp,
            'changesets': [rev0],
            'user': '******',
        })
        handlePushes(repo.pk, [pushjs0])

        file_, = File.objects.all()
        self.assertEqual(file_.path, 'file.dtd ')
Example #4
0
File: tests.py Project: gerv/elmo
    def test_handlePushes_space_files(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd "), "w").write(  # deliberate trailing space
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0], "user": "******"})
        handlePushes(repo.pk, [pushjs0])

        file_, = File.objects.all()
        self.assertEqual(file_.path, "file.dtd ")
Example #5
0
File: tests.py Project: gerv/elmo
    def test_error_handling(self):
        """Test various bad request parameters to the diff_app
        and assure that it responds with the right error codes."""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {})
        eq_(response.status_code, 400)
        response = self.client.get(url, {"repo": "junk"})
        eq_(response.status_code, 404)

        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        # missing 'from' and 'to'
        response = self.client.get(url, {"repo": self.repo_name})
        eq_(response.status_code, 400)

        # missing 'to'
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0})
        eq_(response.status_code, 400)
Example #6
0
File: tests.py Project: gerv/elmo
    def test_remove_file_no_parser(self):
        """Change by removing a file, without parser"""
        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto("file.txt"), "w").write("line 1\nline 2\n"))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        hgcommands.remove(ui, hgrepo, "path:file.txt")
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        repo_url = "http://localhost:8001/%s/" % self.repo_name
        Repository.objects.create(name=self.repo_name, url=repo_url)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_(re.findall(">\s*file\.txt\s*<", html_diff))
        # 1 removed file
        eq_(html_diff.count('<div class="diff file-removed">'), 1)
        # also, expect a link to the old revision of the file
        change_ref = 'href="%sfile/%s/file.txt"' % (repo_url, rev0)
        ok_(change_ref in html_diff)
        ok_(not re.findall(">\s*line 1\s*<", html_diff))
        ok_(not re.findall(">\s*line 2\s*<", html_diff))
Example #7
0
File: tests.py Project: gerv/elmo
    def test_handlePushes_repeated(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0], "user": "******"})
        # first time
        pushes_initial = Push.objects.all().count()
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after = Push.objects.all().count()
        self.assertEqual(pushes_initial, pushes_after - 1)

        # a second time should be harmless
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after_after = Push.objects.all().count()
        self.assertEqual(pushes_after, pushes_after_after)
Example #8
0
File: tests.py Project: gerv/elmo
    def test_remove_file(self):
        """Change by removing a file, with parser"""
        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        hgcommands.remove(ui, hgrepo, "path:file.dtd")
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_(re.findall(">\s*file\.dtd\s*<", html_diff))
        # 2 entities with 2 rows each
        eq_(html_diff.count('<tr class="line-removed">'), 4)
        ok_(re.findall(">\s*key1\s*<", html_diff))
        ok_(re.findall(">\s*Hello\s*<", html_diff))
        ok_(re.findall(">\s*key2\s*<", html_diff))
        ok_(re.findall(">\s*Cruel\s*<", html_diff))
Example #9
0
    def test_handlePushes_space_files(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file:///' + self.repo
        )
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd '), 'w')  # deliberate trailing space
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
          'date': timestamp,
          'changesets': [rev0],
          'user': '******',
        })
        handlePushes(repo.pk, [pushjs0])

        file_, = File.objects.all()
        self.assertEqual(file_.path, 'file.dtd ')
Example #10
0
    def test_handlePushes_cause_repoerror(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file:///does/not/exist'
        )
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
          'date': timestamp,
          'changesets': [rev0],
          'user': '******',
        })
        self.assertRaises(RepoError, handlePushes,
                          repo.pk, [pushjs0])
Example #11
0
File: tests.py Project: gerv/elmo
    def test_file_edited_broken_encoding(self):
        """Change by editing a good with a broken edit"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)

        (open(hgrepo.pathto("file.dtd"), "w").write(u'<!ENTITY key1 "Hello">\n'))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        # do this to trigger an exception on Mozilla.Parser.readContents
        _content = u'<!ENTITY key1 "Hell\xe3">\n'
        (codecs.open(hgrepo.pathto("file.dtd"), "w", "latin1").write(_content))

        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        repo_url = "http://localhost:8001/" + self.repo_name + "/"
        Repository.objects.create(name=self.repo_name, url=repo_url)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("Cannot parse file" in html_diff)
        # also, expect a link to this file
        change_url = repo_url + "file/%s/file.dtd" % rev1
        ok_('href="%s"' % change_url in html_diff)
Example #12
0
    def test_handlePushes_twice(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file://' + self.repo
        )

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
          'date': timestamp,
          'changesets': [rev0],
          'user': '******',
        })
        result = handlePushes(repo.pk, [pushjs0])

        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             <!ENTITY key3 "World">
             '''))
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="Second commit")
        rev1 = hgrepo[1].hex()

        # a second time
        timestamp = int(time.time())
        pushjs0 = PushJS(101, {
          'date': timestamp,
          'changesets': [rev1],
          'user': '******',
        })

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 2)

        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 3)
Example #13
0
    def test_handlePushes_twice(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file://' + self.repo)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
            'date': timestamp,
            'changesets': [rev0],
            'user': '******',
        })
        result = handlePushes(repo.pk, [pushjs0])

        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             <!ENTITY key3 "World">
             '''))
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="Second commit")
        rev1 = hgrepo[1].hex()

        # a second time
        timestamp = int(time.time())
        pushjs0 = PushJS(101, {
            'date': timestamp,
            'changesets': [rev1],
            'user': '******',
        })

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 2)

        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 3)
Example #14
0
File: tests.py Project: gerv/elmo
    def test_diff_base_against_clone(self):
        """Test that the right error is raised on trying to do a diff across
        a different divergant clone"""
        ui = mock_ui()
        orig = os.path.join(settings.REPOSITORY_BASE, "orig")
        clone = os.path.join(settings.REPOSITORY_BASE, "clone")
        hgcommands.init(ui, orig)
        hgorig = repository(ui, orig)
        (
            open(hgorig.pathto("file.dtd"), "w").write(
                """
          <!ENTITY old "content we will delete">
          <!ENTITY mod "this has stuff to keep and delete">
        """
            )
        )
        hgcommands.addremove(ui, hgorig)
        hgcommands.commit(ui, hgorig, user="******", message="initial commit")
        assert len(hgorig) == 1  # 1 commit

        # set up a second repo called 'clone'
        hgcommands.clone(ui, orig, clone)
        hgclone = repository(ui, clone)

        # new commit on base
        (
            open(hgorig.pathto("file.dtd"), "w").write(
                """
         <!ENTITY mod "this has stuff to keep and add">
         <!ENTITY new "this has stuff that is new">
         """
            )
        )
        hgcommands.commit(ui, hgorig, user="******", message="second commit on base")
        assert len(hgorig) == 2  # 2 commits
        rev_from = hgorig[1].hex()

        # different commit on clone
        (
            open(hgclone.pathto("file.dtd"), "w").write(
                """
         <!ENTITY mod "this has stuff to keep and change">
         <!ENTITY new_in_clone "this has stuff that is different from base">
         """
            )
        )
        hgcommands.commit(ui, hgclone, user="******", message="a different commit on clone")
        rev_to = hgclone[1].hex()

        Repository.objects.create(name="orig", url="http://localhost:8001/orig/")
        Repository.objects.create(name="clone", url="http://localhost:8001/clone/")

        url = reverse("pushes.views.diff")
        # right now, we can't diff between repos, this might change!
        self.assertRaises(RepoError, self.client.get, url, {"repo": "clone", "from": rev_from[:12], "to": rev_to[:12]})
Example #15
0
 def commit(self, message='',stdout=None):
     """
     Commit all changes into hg repository
     Note that local repo must be setup for access without key,
     and commit must not create new head, because push is not forced
     """
     u, r = self._hg(stdout)
     commands.addremove(u, r)
     commands.commit(u, r, message=message)
     commands.push(u, r)
     del u, r
Example #16
0
    def test_handlePushes(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file:///' + self.repo
        )
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        push_id = 100
        username = '******'
        pushjs0 = PushJS(push_id, {
          'date': timestamp,
          'changesets': [rev0],
          'user': username,
        })
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # expect all of these to have been created
        push, = Push.objects.all()
        branch, = Branch.objects.all()
        changeset, = push.changesets.all()

        self.assertEqual(push.repository, repo)
        self.assertEqual(push.push_id, push_id)
        self.assertEqual(push.user, username)
        self.assertEqual(push.push_date.strftime('%Y%m%d%H%M'),
                         datetime.datetime.utcnow().strftime('%Y%m%d%H%M'))

        self.assertEqual(changeset.description, 'initial commit')
        self.assertEqual(changeset.user, 'Jane Doe <*****@*****.**>')
        self.assertEqual(changeset.revision, rev0)
        self.assertEqual(changeset.branch, branch)

        self.assertEqual(branch.name, 'default')
Example #17
0
File: tests.py Project: gerv/elmo
    def test_handlePushes_twice(self):
        repo = Repository.objects.create(name="mozilla-central", url="file://" + self.repo)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0], "user": "******"})
        result = handlePushes(repo.pk, [pushjs0])

        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             <!ENTITY key3 "World">
             """
            )
        )
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        # a second time
        timestamp = int(time.time())
        pushjs0 = PushJS(101, {"date": timestamp, "changesets": [rev1], "user": "******"})

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 2)

        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 3)
Example #18
0
    def test_handlePushes(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file:///' + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        push_id = 100
        username = '******'
        pushjs0 = PushJS(push_id, {
            'date': timestamp,
            'changesets': [rev0],
            'user': username,
        })
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # expect all of these to have been created
        push, = Push.objects.all()
        branch, = Branch.objects.all()
        changeset, = push.changesets.all()

        self.assertEqual(push.repository, repo)
        self.assertEqual(push.push_id, push_id)
        self.assertEqual(push.user, username)
        self.assertEqual(push.push_date.strftime('%Y%m%d%H%M'),
                         datetime.datetime.utcnow().strftime('%Y%m%d%H%M'))

        self.assertEqual(changeset.description, 'initial commit')
        self.assertEqual(changeset.user, 'Jane Doe <*****@*****.**>')
        self.assertEqual(changeset.revision, rev0)
        self.assertEqual(changeset.branch, branch)

        self.assertEqual(branch.name, 'default')
Example #19
0
File: tests.py Project: gerv/elmo
    def test_handlePushes(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        push_id = 100
        username = "******"
        pushjs0 = PushJS(push_id, {"date": timestamp, "changesets": [rev0], "user": username})
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # expect all of these to have been created
        push, = Push.objects.all()
        branch, = Branch.objects.all()
        changeset, = push.changesets.all()

        self.assertEqual(push.repository, repo)
        self.assertEqual(push.push_id, push_id)
        self.assertEqual(push.user, username)
        self.assertEqual(push.push_date.strftime("%Y%m%d%H%M"), datetime.datetime.utcnow().strftime("%Y%m%d%H%M"))

        self.assertEqual(changeset.description, "initial commit")
        self.assertEqual(changeset.user, "Jane Doe <*****@*****.**>")
        self.assertEqual(changeset.revision, rev0)
        self.assertEqual(changeset.branch, branch)

        self.assertEqual(branch.name, "default")
Example #20
0
File: tests.py Project: gerv/elmo
    def test_file_entity_addition(self):
        """Change one file by adding a new line to it"""
        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             <!ENTITY key3 "World">
             """
            )
        )
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_(re.findall(">\s*file\.dtd\s*<", html_diff))
        ok_('<tr class="line-added">' in html_diff)
        ok_(re.findall(">\s*key3\s*<", html_diff))
        ok_(re.findall(">\s*World\s*<", html_diff))
        ok_(not re.findall(">\s*Cruel\s*<", html_diff))
Example #21
0
File: tests.py Project: gerv/elmo
    def test_file_renamed_and_edited_original_broken(self):
        """Change by doing a rename on a previously broken file"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)

        hgrepo = repository(ui, self.repo)
        (
            codecs.open(hgrepo.pathto("file.dtd"), "w", "latin1").write(
                u"""
             <!ENTITY key1 "Hell\xe3">
             <!ENTITY key2 "Cruel">
             """
            )
        )
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        hgcommands.rename(ui, hgrepo, hgrepo.pathto("file.dtd"), hgrepo.pathto("newnamefile.dtd"))
        (
            open(hgrepo.pathto("newnamefile.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "World">
             """
            )
        )
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1].split("page_footer")[0]
        html_diff = unicode(html_diff, "utf-8")
        ok_(re.findall(">\s*newnamefile\.dtd\s*<", html_diff))
        ok_("Cannot parse file" in html_diff)
        eq_(html_diff.count("Cannot parse file"), 1)
        ok_("renamed from file.dtd" in re.sub("<.*?>", "", html_diff))
Example #22
0
    def test_handlePushes_repeated(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file:///' + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
            'date': timestamp,
            'changesets': [rev0],
            'user': '******',
        })
        # first time
        pushes_initial = Push.objects.all().count()
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after = Push.objects.all().count()
        self.assertEqual(pushes_initial, pushes_after - 1)

        # a second time should be harmless
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after_after = Push.objects.all().count()
        self.assertEqual(pushes_after, pushes_after_after)
Example #23
0
File: tests.py Project: gerv/elmo
    def test_binary_file_edited(self):
        """Modify a binary file"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.png"), "wb").write(
                base64.b64decode(
                    "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklE" "QVR4nGNoAAAAggCBd81ytgAAAABJRU5ErkJggg=="
                )
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        # a bit unfair of a change but works for the tests
        (
            open(hgrepo.pathto("file.png"), "wb").write(
                base64.b64decode(
                    "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklE" "QVR4nGNgAAAAAgABSK+kcQAAAABJRU5ErkJggg=="
                )
            )
        )

        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        repo_url = "http://localhost:8001/" + self.repo_name + "/"
        Repository.objects.create(name=self.repo_name, url=repo_url)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("Cannot parse file" in html_diff)
        # also, expect a link to this file
        change_ref = 'href="%sfile/%s/file.png"' % (repo_url, rev1)
        ok_(change_ref in html_diff)
Example #24
0
File: tests.py Project: gerv/elmo
    def test_file_only_renamed_no_parser(self):
        """Change by doing a rename of a file without parser"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto("file.txt"), "w").write("line 1\nline 2\n"))
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        hgcommands.rename(ui, hgrepo, hgrepo.pathto("file.txt"), hgrepo.pathto("newnamefile.txt"))
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("renamed from file.txt" in re.sub("<.*?>", "", html_diff))
        ok_(re.findall(">\s*newnamefile\.txt\s*<", html_diff))
        ok_(not re.findall(">\s*line 1\s*<", html_diff))
Example #25
0
File: tests.py Project: gerv/elmo
    def test_handlePushes_messedup_revisions(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0[::-1]], "user": "******"})
        self.assertRaises(RepoLookupError, handlePushes, repo.pk, [pushjs0])