You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.0KB

  1. # Copyright 2020-2021 Tecnativa - Víctor Martínez
  2. # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
  3. from .common import TestGithubConnectorCommon
  4. class TestGithubConnectorAnalysisRule(TestGithubConnectorCommon):
  5. @classmethod
  6. def setUpClass(cls):
  7. super().setUpClass()
  8. cls.rule_group = cls.env.ref(
  9. "github_connector.github_analysis_rule_group_1_demo"
  10. )
  11. cls.rule_python = cls.env.ref("github_connector.github_analysis_rule_python")
  12. cls.rule_xml = cls.env.ref("github_connector.github_analysis_rule_xml")
  13. cls.rule_js = cls.env.ref("github_connector.github_analysis_rule_js")
  14. cls.rule_test = cls.env.ref("github_connector.github_analysis_rule_test")
  15. cls.rule_ocb = cls.env["github.analysis.rule"].create(
  16. {
  17. "name": "OCB files (.py + .xml)",
  18. "group_id": cls.rule_group.id,
  19. "paths": """
  20. *.py
  21. *.xml
  22. !/.*/
  23. """,
  24. }
  25. )
  26. cls.rule_custom = cls.env["github.analysis.rule"].create(
  27. {
  28. "name": "Custom",
  29. "group_id": cls.rule_group.id,
  30. "paths": """/custom/*.py""",
  31. }
  32. )
  33. cls.oca.write(
  34. {
  35. "analysis_rule_ids": [
  36. (6, 0, [cls.rule_python.id, cls.rule_xml.id, cls.rule_js.id])
  37. ]
  38. }
  39. )
  40. cls.repository_ocb.write({"analysis_rule_ids": [(6, 0, cls.rule_ocb.ids)]})
  41. cls.repository_interface_github_13.write(
  42. {"analysis_rule_ids": [(6, 0, cls.rule_custom.ids)]}
  43. )
  44. cls.repo_branch_item = cls.repository_interface_github_13
  45. # analyze_code again
  46. cls._download_and_analyze(cls, cls.repo_branch_item)
  47. def test_analysis_rule_info(self):
  48. self.assertEqual(len(self.oca.analysis_rule_ids), 3)
  49. self.assertEqual(len(self.repository_ocb.analysis_rule_ids), 1)
  50. self.assertEqual(len(self.repo_branch_item.analysis_rule_info_ids), 4)
  51. def test_analysis_rule_info_python(self):
  52. rule_info = self.repo_branch_item.analysis_rule_info_ids.filtered(
  53. lambda x: x.analysis_rule_id.id == self.rule_python.id
  54. )
  55. for info_key in self.info_keys:
  56. self.assertGreater(rule_info[info_key], 0)
  57. def test_analysis_rule_info_xml(self):
  58. rule_info = self.repo_branch_item.analysis_rule_info_ids.filtered(
  59. lambda x: x.analysis_rule_id.id == self.rule_xml.id
  60. )
  61. for info_key in self.info_keys:
  62. if info_key in ("empty_count", "string_count"):
  63. self.assertEqual(rule_info[info_key], 0)
  64. else:
  65. self.assertGreater(rule_info[info_key], 0)
  66. def test_analysis_rule_info_js(self):
  67. rule_info = self.repo_branch_item.analysis_rule_info_ids.filtered(
  68. lambda x: x.analysis_rule_id.id == self.rule_js.id
  69. )
  70. for info_key in self.info_keys:
  71. self.assertEqual(rule_info[info_key], 0)
上海开阖软件有限公司 沪ICP备12045867号-1