#5272 Improve tests
Merged 2 years ago by ngompa. Opened 2 years ago by zlopez.
zlopez/pagure tests  into  master

file modified
+39 -2
@@ -122,8 +122,8 @@ 

  show the pagure output. The verbosity can be configured in the pagure config file

  with the ``LOGGING`` parameter.

  

- Running the unit-tests

- **********************

+ Running the unit-tests in container

+ ***********************************

  

  To run the unit-tests, there is container available with all the dependencies needed.

  
@@ -160,6 +160,43 @@ 

  

      $ ./dev/run-tests-container.py --help

  

+ Run the tests on your own development branch in your fork ::

+ 

+     $ ./dev/run-tests-container.py --repo https://pagure.io/forks/<username>/pagure.git --branch <name of branch to test>

+ 

+   .. note:: This run could take pretty long to finish and there isn't any useful summary.

+             So it's better to redirect the output to some file. You can use `tee` for this.

+ 

+  

+ Running the unit-tests in tox

+ *****************************

+ 

+ You can run the tests using tox. This allows you to run the tests on local version of the code.

+ 

+   .. note:: This way of running tests could help you test your local changes,

+             but the output could be different then from the containerized tests.

+             Always check your branch after push with containerized tests as well.

+ 

+ * Install the needed system libraries::

+ 

+      sudo dnf install libgit2-devel redis gcc tox python-alembic

+ 

+ 

+   .. note:: You can also install any missing python interpreter.

+             For example `sudo dnf install python35`

+ 

+ * Run the whole test suite::

+ 

+      tox

+ 

+ * Or just single environment::

+ 

+      tox -e py39

+ 

+ * Or single module::

+ 

+      tox tests/test_style.py

+ 

  Manually

  ^^^^^^^^

  

@@ -1,4 +1,4 @@ 

- FROM quay.io/fedora/fedora:33-x86_64

+ FROM quay.io/fedora/fedora:35-x86_64

  

  ARG repo=https://pagure.io/pagure.git

  ARG branch=master

@@ -1,4 +1,4 @@ 

- FROM quay.io/fedora/fedora:32-x86_64

+ FROM quay.io/fedora/fedora:35-x86_64

  

  ARG repo=https://pagure.io/pagure.git

  ARG branch=master

file modified
+8 -2
@@ -512,7 +512,10 @@ 

          )

      else:

          request.title = form.title.data.strip()

-         request.initial_comment = form.initial_comment.data.strip()

+         request.initial_comment = ""

+         # This value is optional, check first if it's filled

+         if form.initial_comment.data:

+             request.initial_comment = form.initial_comment.data.strip()

          flask.g.session.add(request)

          if not request.private and not request.project.private:

              pagure.lib.notify.log(
@@ -1535,7 +1538,10 @@ 

      if orig_commit:

          orig_commit = orig_commit.oid.hex

  

-     initial_comment = form.initial_comment.data.strip() or None

+     initial_comment = None

+     # This value is optional, check first if it's filled

+     if form.initial_comment.data:

+         initial_comment = form.initial_comment.data.strip()

  

      commit_start = commit_stop = None

      if diff_commits:

file modified
+3 -1
@@ -1745,7 +1745,9 @@ 

      if form.validate_on_submit():

          repo = form.repo.data

          username = form.username.data or None

-         namespace = form.namespace.data.strip() or None

+         namespace = None

+         if form.namespace.data:

+             namespace = form.namespace.data.strip()

  

          repo = get_authorized_api_project(

              flask.g.session, repo, user=username, namespace=namespace

file modified
+2 -2
@@ -634,10 +634,10 @@ 

              # aim for noon on the desired date.

              try:

  

-                 return arrow.get(d, tz).replace(hour=12).timestamp

+                 return int(arrow.get(d, tz).replace(hour=12).float_timestamp)

              except (arrow.parser.ParserError, ValueError):

                  # if tz is invalid for some reason, just go with UTC

-                 return arrow.get(d).replace(hour=12).timestamp

+                 return int(arrow.get(d).replace(hour=12).float_timestamp)

          else:

              d = d.isoformat()

          return d

file modified
+2 -2
@@ -335,7 +335,7 @@ 

  

      branch_to = wtforms.SelectField(

          "Target branch",

-         [wtforms.validators.Required()],

+         [wtforms.validators.DataRequired()],

          choices=[],

          coerce=convert_value,

      )
@@ -964,7 +964,7 @@ 

          self.comment.choices = choices

  

      comment = wtforms.SelectField(

-         "comment", [wtforms.validators.Required()], choices=[]

+         "comment", [wtforms.validators.DataRequired()], choices=[]

      )

  

  

file modified
+6 -2
@@ -1135,7 +1135,7 @@ 

  

      prev = flask.request.args.get("prev")

      if not is_safe_url(prev):

-         prev = flask.url_for("index")

+         prev = flask.url_for("ui_ns.index")

  

      count = flask.request.args.get("count", 0)

      try:
@@ -1543,10 +1543,14 @@ 

  

      if form.validate_on_submit():

          try:

+             description = None

+             # Check if the optional value is filled

+             if form.description.data:

+                 description = form.description.data.strip()

              pagure.lib.query.add_token_to_user(

                  flask.g.session,

                  project=None,

-                 description=form.description.data.strip() or None,

+                 description=description,

                  acls=form.acls.data,

                  username=user.username,

                  expiration_date=form.expiration_date.data,

file modified
+5
@@ -74,6 +74,11 @@ 

      # always use UTC timezone, and we don't use localized forms like

      # %b or %d because they will be 'localized' for the *server*.

      # This format should be pretty 'locale-neutral'.

+ 

+     # Return empty string if timestamp is None

+     # This will prevent any formatting error in arrow

+     if string is None:

+         return ""

      arr = arrow.get(string)

      return arr.strftime("%Y-%m-%d %H:%M:%S %Z")

  

file modified
+25 -15
@@ -185,22 +185,29 @@ 

  

          comment = form.comment.data

          depends = []

-         for depend in form.depending.data.split(","):

-             if depend.strip():

-                 try:

-                     depends.append(int(depend.strip()))

-                 except ValueError:

-                     pass

+         # This field is optional, check if it's filled first

+         if form.depending.data:

+             for depend in form.depending.data.split(","):

+                 if depend.strip():

+                     try:

+                         depends.append(int(depend.strip()))

+                     except ValueError:

+                         pass

  

          blocks = []

-         for block in form.blocking.data.split(","):

-             if block.strip():

-                 try:

-                     blocks.append(int(block.strip()))

-                 except ValueError:

-                     pass

- 

-         assignee = form.assignee.data.strip() or None

+         # Check if the optional field is filled

+         if form.blocking.data:

+             for block in form.blocking.data.split(","):

+                 if block.strip():

+                     try:

+                         blocks.append(int(block.strip()))

+                     except ValueError:

+                         pass

+ 

+         assignee = None

+         # Check if the optional field is filled

+         if form.assignee.data:

+             assignee = form.assignee.data.strip()

          new_status = form.status.data.strip() or None

          close_status = form.close_status.data or None

          if close_status not in repo.close_status:
@@ -211,7 +218,10 @@ 

              new_priority = int(form.priority.data)

          except (ValueError, TypeError):

              pass

-         tags = [tag.strip() for tag in form.tag.data.split(",") if tag.strip()]

+         tags = []

+         # Check if the optional field is filled

+         if form.tag.data:

+             tags = [tag.strip() for tag in form.tag.data.split(",")]

  

          new_milestone = None

          try:

file modified
+14 -8
@@ -1406,18 +1406,24 @@ 

  

          try:

              repo.description = form.description.data

-             repo.avatar_email = form.avatar_email.data.strip()

-             repo.url = form.url.data.strip()

+             # Check if the optional value is filled

+             if form.avatar_email.data is not None:

+                 repo.avatar_email = form.avatar_email.data.strip()

+             # Check if the optional value is filled

+             if form.url.data:

+                 repo.url = form.url.data.strip()

              if repo.private:

                  repo.private = form.private.data

              if repo.mirrored_from:

                  repo.mirrored_from = form.mirrored_from.data

-             pagure.lib.query.update_tags(

-                 flask.g.session,

-                 repo,

-                 tags=[t.strip() for t in form.tags.data.split(",")],

-                 username=flask.g.fas_user.username,

-             )

+             # Check if the optional value is filled

+             if form.tags.data:

+                 pagure.lib.query.update_tags(

+                     flask.g.session,

+                     repo,

+                     tags=[t.strip() for t in form.tags.data.split(",")],

+                     username=flask.g.fas_user.username,

+                 )

              flask.g.session.add(repo)

              flask.g.session.commit()

              flask.flash("Project updated")

file modified
+2 -1
@@ -160,7 +160,8 @@ 

      ref_url = urlparse(flask.request.host_url)

      test_url = urlparse(urljoin(flask.request.host_url, target))

      return (

-         test_url.scheme in ("http", "https")

+         target is not None

+         and test_url.scheme in ("http", "https")

          and ref_url.netloc == test_url.netloc

      )

  

@@ -2460,7 +2460,7 @@ 

          repo = pagure.lib.query.get_authorized_project(self.session, "test")

  

          # Create 1st tickets

-         start = arrow.utcnow().timestamp

+         start = int(arrow.utcnow().float_timestamp)

          issue = pagure.lib.model.Issue(

              id=pagure.lib.query.get_next_id(self.session, repo.id),

              project_id=repo.id,
@@ -2474,7 +2474,7 @@ 

          self.session.commit()

  

          time.sleep(1)

-         middle = arrow.utcnow().timestamp

+         middle = int(arrow.utcnow().float_timestamp)

  

          # Create 2nd tickets

          issue = pagure.lib.model.Issue(
@@ -2490,7 +2490,7 @@ 

          self.session.commit()

  

          time.sleep(1)

-         final = arrow.utcnow().timestamp

+         final = int(arrow.utcnow().float_timestamp)

  

          # Create private issue

          issue = pagure.lib.model.Issue(
@@ -2553,7 +2553,6 @@ 

          )

  

          time.sleep(1)

-         late = arrow.utcnow().timestamp

  

          # List all opened issues from the start

          output = self.app.get("/api/0/test/issues?since=%s" % start)

@@ -378,7 +378,7 @@ 

                  "error": "Could not match input '2016asd' to any of the following formats: "

                  "YYYY-MM-DD, YYYY-M-DD, YYYY-M-D, YYYY/MM/DD, YYYY/M/DD, YYYY/M/D, "

                  "YYYY.MM.DD, YYYY.M.DD, YYYY.M.D, YYYYMMDD, YYYY-DDDD, YYYYDDDD, "

-                 "YYYY-MM, YYYY/MM, YYYY.MM, YYYY, W",

+                 "YYYY-MM, YYYY/MM, YYYY.MM, YYYY, W.",

                  "error_code": "ENOCODE",

              }

              self.assertEqual(json.loads(output.get_data(as_text=True)), exp)

@@ -6382,7 +6382,7 @@ 

              self.assertIn(

                  "<p>fork/foo/test is not part of fork/ralph/test2's "

                  "family</p>",

-                 output.get_data(as_text=True),

+                 output.get_data(as_text=True).replace("&#x27;", "'"),

              )

  

      @patch("pagure.lib.notify.send_email")

This PR is trying to improve the tests by various ways:

  • Update README.md with information how to run the tests on your fork and branch using containers
  • Update README.md with information about how to run tox tests locally
  • All the tests on CentOS 8 Stream CI container are passing
  • Update Fedora CI containers to F35
    • 7 tests are still failing for rpms container with following reasons:
      • tests/test_pagure_flask_ui_repo.py::PagureFlaskRepotests (2 tests) - Fork of the fork is recognized as project
      • tests/test_pagure_lib_git_auth.py::PagureLibGitAuthtests (2 tests) - The string is split by SQLAlchemy warnings about relationship. Should we ignore them?
      • tests/test_pagure_flask_api.py::PagureFlaskApitests::test_api_get_request_data - Need to have flask 2.0.2 to work properly, this isn't available in F35 yet, but it's in F36
      • tests/test_pagure_flask_dump_load_ticket.py::PagureFlaskDumpLoadTicketTests::test_dumping_reloading_ticket - Pygit 2 doesn't support latest arrow library. See https://github.com/libgit2/pygit2/issues/1122
      • Black formatting is different
    • 40 tests failing for pip CI container

I will try to work on the tests a little more. But this is ready to be merged.

Pull-Request has been merged by ngompa

2 years ago