From 37b63a83f2241d30b02ebaf237775794a54991e0 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 16 Feb 2019 21:17:52 +0000 Subject: [PATCH] Add some tests --- Pipfile | 1 + Pipfile.lock | 53 ++++++++++++++++- actioner/scheduler/todoist_assigned_issues.py | 2 +- scripts/test-fix.sh | 2 +- scripts/test.sh | 9 ++- tests/__init__.py | 5 ++ .../test_todoist_assigned_issues.py | 59 +++++++++++++++++++ 7 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_scheduler/test_todoist_assigned_issues.py diff --git a/Pipfile b/Pipfile index 7d8a0a7..fab6592 100644 --- a/Pipfile +++ b/Pipfile @@ -7,6 +7,7 @@ verify_ssl = true flake8 = "*" mypy = "*" isort = "*" +nose2 = "*" [requires] python_version = "3.5" diff --git a/Pipfile.lock b/Pipfile.lock index 421bd4c..159016f 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "4595ba894a228bb4151c2ae9934e8d02f1812f1ac0a683220e07e003641ce112" + "sha256": "fa3fe95ec35b39216f89501e1f35ce5aa0bf033ad39a57682da8d4de9fb9edf3" }, "pipfile-spec": 6, "requires": { @@ -209,7 +209,8 @@ }, "wrapt": { "hashes": [ - "sha256:4aea003270831cceb8a90ff27c4031da6ead7ec1886023b80ce0dfe0adf61533" + "sha256:4aea003270831cceb8a90ff27c4031da6ead7ec1886023b80ce0dfe0adf61533", + "sha256:c8bb077d34cce12c1cab899a95fc9d323d0d6a086f8028774a602da119f589ae" ], "version": "==1.11.1" }, @@ -231,6 +232,40 @@ } }, "develop": { + "coverage": { + "hashes": [ + "sha256:029c69deaeeeae1b15bc6c59f0ffa28aa8473721c614a23f2c2976dec245cd12", + "sha256:02abbbebc6e9d5abe13cd28b5e963dedb6ffb51c146c916d17b18f141acd9947", + "sha256:1bbfe5b82a3921d285e999c6d256c1e16b31c554c29da62d326f86c173d30337", + "sha256:210c02f923df33a8d0e461c86fdcbbb17228ff4f6d92609fc06370a98d283c2d", + "sha256:2d0807ba935f540d20b49d5bf1c0237b90ce81e133402feda906e540003f2f7a", + "sha256:35d7a013874a7c927ce997350d314144ffc5465faf787bb4e46e6c4f381ef562", + "sha256:3636f9d0dcb01aed4180ef2e57a4e34bb4cac3ecd203c2a23db8526d86ab2fb4", + "sha256:42f4be770af2455a75e4640f033a82c62f3fb0d7a074123266e143269d7010ef", + "sha256:48440b25ba6cda72d4c638f3a9efa827b5b87b489c96ab5f4ff597d976413156", + "sha256:4dac8dfd1acf6a3ac657475dfdc66c621f291b1b7422a939cc33c13ac5356473", + "sha256:4e8474771c69c2991d5eab65764289a7dd450bbea050bc0ebb42b678d8222b42", + "sha256:551f10ddfeff56a1325e5a34eff304c5892aa981fd810babb98bfee77ee2fb17", + "sha256:5b104982f1809c1577912519eb249f17d9d7e66304ad026666cb60a5ef73309c", + "sha256:5c62aef73dfc87bfcca32cee149a1a7a602bc74bac72223236b0023543511c88", + "sha256:633151f8d1ad9467b9f7e90854a7f46ed8f2919e8bc7d98d737833e8938fc081", + "sha256:772207b9e2d5bf3f9d283b88915723e4e92d9a62c83f44ec92b9bd0cd685541b", + "sha256:7d5e02f647cd727afc2659ec14d4d1cc0508c47e6cfb07aea33d7aa9ca94d288", + "sha256:a9798a4111abb0f94584000ba2a2c74841f2cfe5f9254709756367aabbae0541", + "sha256:b38ea741ab9e35bfa7015c93c93bbd6a1623428f97a67083fc8ebd366238b91f", + "sha256:b6a5478c904236543c0347db8a05fac6fc0bd574c870e7970faa88e1d9890044", + "sha256:c6248bfc1de36a3844685a2e10ba17c18119ba6252547f921062a323fb31bff1", + "sha256:c705ab445936457359b1424ef25ccc0098b0491b26064677c39f1d14a539f056", + "sha256:d95a363d663ceee647291131dbd213af258df24f41350246842481ec3709bd33", + "sha256:e27265eb80cdc5dab55a40ef6f890e04ecc618649ad3da5265f128b141f93f78", + "sha256:ebc276c9cb5d917bd2ae959f84ffc279acafa9c9b50b0fa436ebb70bbe2166ea", + "sha256:f4d229866d030863d0fe3bf297d6d11e6133ca15bbb41ed2534a8b9a3d6bd061", + "sha256:f95675bd88b51474d4fe5165f3266f419ce754ffadfb97f10323931fa9ac95e5", + "sha256:f95bc54fb6d61b9f9ff09c4ae8ff6a3f5edc937cda3ca36fc937302a7c152bf1", + "sha256:fd0f6be53de40683584e5331c341e65a679dbe5ec489a0697cec7c2ef1a48cda" + ], + "version": "==5.0a4" + }, "entrypoints": { "hashes": [ "sha256:589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e58ecbb8dbe56d19", @@ -277,6 +312,13 @@ ], "version": "==0.4.1" }, + "nose2": { + "hashes": [ + "sha256:9052f2b46807b63d9bdf68e0768da1f8386368889b50043fd5d0889c470258f3" + ], + "index": "pypi", + "version": "==0.8.0" + }, "pycodestyle": { "hashes": [ "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56", @@ -291,6 +333,13 @@ ], "version": "==2.1.0" }, + "six": { + "hashes": [ + "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", + "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" + ], + "version": "==1.12.0" + }, "typed-ast": { "hashes": [ "sha256:035a54ede6ce1380599b2ce57844c6554666522e376bd111eb940fbc7c3dad23", diff --git a/actioner/scheduler/todoist_assigned_issues.py b/actioner/scheduler/todoist_assigned_issues.py index 37c9b0c..a9c292c 100644 --- a/actioner/scheduler/todoist_assigned_issues.py +++ b/actioner/scheduler/todoist_assigned_issues.py @@ -24,7 +24,7 @@ def issue_to_task_name(issue: Issue) -> str: def get_existing_task(tasks: Dict[int, str], issue: Issue): issue_link = get_issue_link(issue) for task_id, task_title in tasks.items(): - if issue_link in task_title: + if task_title.startswith(issue_link): return task_id return None diff --git a/scripts/test-fix.sh b/scripts/test-fix.sh index 36f9e54..4c555f0 100755 --- a/scripts/test-fix.sh +++ b/scripts/test-fix.sh @@ -2,4 +2,4 @@ set -e -isort -rc actioner/ +isort -rc actioner/ tests/ diff --git a/scripts/test.sh b/scripts/test.sh index dba6711..233c1fe 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -2,11 +2,14 @@ set -e +echo "> Running tests..." +nose2 $@ -C --coverage actioner --verbose --coverage-report term --coverage-report html + echo "> Running isort" -isort -rc -c actioner/ +isort -rc -c actioner/ tests/ echo "> Running mypy" -mypy actioner/ +mypy actioner/ tests/ echo "> Running flake8" -flake8 actioner +flake8 actioner tests diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..056c322 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,5 @@ +from unittest import TestCase + + +class BaseTestCase(TestCase): + pass diff --git a/tests/test_scheduler/test_todoist_assigned_issues.py b/tests/test_scheduler/test_todoist_assigned_issues.py new file mode 100644 index 0000000..74f8ad8 --- /dev/null +++ b/tests/test_scheduler/test_todoist_assigned_issues.py @@ -0,0 +1,59 @@ +from collections import namedtuple + +from actioner.clients import github, todoist +from actioner.scheduler.todoist_assigned_issues import (REPOS, + get_existing_task, + get_issue_link, + issue_to_task_name) +from tests import BaseTestCase + +FakeIssue = namedtuple('FakeIssue', ['number', 'html_url', 'title']) + + +class IssueTaskNameTestCase(BaseTestCase): + def setUp(self): + super().setUp() + self.issue = FakeIssue(123, 'https://github.com/repo/thing', 'issue title') + + def test_creates_link(self): + self.assertEqual(get_issue_link(self.issue), "[#123](https://github.com/repo/thing)") + self.assertIn(self.issue.html_url, get_issue_link(self.issue)) + + def test_task_name_contains_title(self): + self.assertIn(self.issue.title, issue_to_task_name(self.issue)) + + def test_task_name_contains_link(self): + self.assertIn(get_issue_link(self.issue), issue_to_task_name(self.issue)) + + +class ConfigurationTestCase(BaseTestCase): + def test_repos_exist(self): + for repo in REPOS.keys(): + github.get_repo(repo) + + def test_projects_exist(self): + todoist.projects.sync() + project_ids = {project['id'] for project in todoist.state['projects']} + for project_id in REPOS.values(): + self.assertIn(project_id, project_ids) + + +class ExistingTaskTestCase(BaseTestCase): + def setUp(self): + super().setUp() + self.tasks = { + 123: '[#1](url): title', + 456: '[#2](url/2): title 2', + 789: '[#3](url/3): title 3', + } + + def test_finds_existing_repos(self): + self.assertEqual( + get_existing_task(self.tasks, FakeIssue(1, 'url', 'title')), + 123 + ) + + def test_not_existing_repo(self): + self.assertIsNone( + get_existing_task(self.tasks, FakeIssue(123, 'url', 'title')) + )