From 7ae0836f770bda280c075e91fcc357fac9f86be5 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 27 Jul 2012 12:36:30 -0400 Subject: [PATCH] Add some more tests of github_sync --- cms/djangoapps/github_sync/tests/__init__.py | 16 +++++++- .../github_sync/tests/test_views.py | 39 +++++++------------ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/cms/djangoapps/github_sync/tests/__init__.py b/cms/djangoapps/github_sync/tests/__init__.py index ef6a2f349a..39a94abb71 100644 --- a/cms/djangoapps/github_sync/tests/__init__.py +++ b/cms/djangoapps/github_sync/tests/__init__.py @@ -1,13 +1,14 @@ from django.test import TestCase from path import path import shutil -from github_sync import import_from_github, export_to_github, load_repo_settings +from github_sync import import_from_github, export_to_github, load_repo_settings, sync_all_with_github, sync_with_github from git import Repo from django.conf import settings from xmodule.modulestore.django import modulestore from xmodule.modulestore import Location from override_settings import override_settings from github_sync.exceptions import GithubSyncError +from mock import patch, Mock REPO_DIR = settings.GITHUB_REPO_ROOT / 'local_repo' WORKING_DIR = path(settings.TEST_ROOT) @@ -59,6 +60,19 @@ class GithubSyncTestCase(TestCase): [child.location for child in self.import_course.get_children()]) self.assertEquals(1, len(self.import_course.get_children())) + @patch('github_sync.sync_with_github') + def test_sync_all_with_github(self, sync_with_github): + sync_all_with_github() + sync_with_github.assert_called_with(load_repo_settings('local_repo')) + + def test_sync_with_github(self): + with patch('github_sync.import_from_github', Mock(return_value=(Mock(), Mock()))) as import_from_github: + with patch('github_sync.export_to_github') as export_to_github: + settings = load_repo_settings('local_repo') + sync_with_github(settings) + import_from_github.assert_called_with(settings) + export_to_github.assert_called + @override_settings(MITX_FEATURES={'GITHUB_PUSH': False}) def test_export_no_pash(self): """ diff --git a/cms/djangoapps/github_sync/tests/test_views.py b/cms/djangoapps/github_sync/tests/test_views.py index f46e7f7db3..212d707340 100644 --- a/cms/djangoapps/github_sync/tests/test_views.py +++ b/cms/djangoapps/github_sync/tests/test_views.py @@ -1,52 +1,43 @@ import json from django.test.client import Client from django.test import TestCase -from mock import patch, Mock +from mock import patch from override_settings import override_settings -from django.conf import settings +from github_sync import load_repo_settings -@override_settings(REPOS={'repo': {'path': 'path', 'branch': 'branch'}}) +@override_settings(REPOS={'repo': {'branch': 'branch', 'origin': 'origin'}}) class PostReceiveTestCase(TestCase): def setUp(self): self.client = Client() - @patch('github_sync.views.export_to_github') - @patch('github_sync.views.import_from_github') - def test_non_branch(self, import_from_github, export_to_github): + @patch('github_sync.views.sync_with_github') + def test_non_branch(self, sync_with_github): self.client.post('/github_service_hook', {'payload': json.dumps({ 'ref': 'refs/tags/foo'}) }) - self.assertFalse(import_from_github.called) - self.assertFalse(export_to_github.called) + self.assertFalse(sync_with_github.called) - @patch('github_sync.views.export_to_github') - @patch('github_sync.views.import_from_github') - def test_non_watched_repo(self, import_from_github, export_to_github): + @patch('github_sync.views.sync_with_github') + def test_non_watched_repo(self, sync_with_github): self.client.post('/github_service_hook', {'payload': json.dumps({ 'ref': 'refs/heads/branch', 'repository': {'name': 'bad_repo'}}) }) - self.assertFalse(import_from_github.called) - self.assertFalse(export_to_github.called) + self.assertFalse(sync_with_github.called) - @patch('github_sync.views.export_to_github') - @patch('github_sync.views.import_from_github') - def test_non_tracked_branch(self, import_from_github, export_to_github): + @patch('github_sync.views.sync_with_github') + def test_non_tracked_branch(self, sync_with_github): self.client.post('/github_service_hook', {'payload': json.dumps({ 'ref': 'refs/heads/non_branch', 'repository': {'name': 'repo'}}) }) - self.assertFalse(import_from_github.called) - self.assertFalse(export_to_github.called) + self.assertFalse(sync_with_github.called) - @patch('github_sync.views.export_to_github') - @patch('github_sync.views.import_from_github', return_value=(Mock(), Mock())) - def test_tracked_branch(self, import_from_github, export_to_github): + @patch('github_sync.views.sync_with_github') + def test_tracked_branch(self, sync_with_github): self.client.post('/github_service_hook', {'payload': json.dumps({ 'ref': 'refs/heads/branch', 'repository': {'name': 'repo'}}) }) - import_from_github.assert_called_with(settings.REPOS['repo']) - mock_revision, mock_course = import_from_github.return_value - export_to_github.assert_called_with(mock_course, 'path', "Changes from cms import of revision %s" % mock_revision) + sync_with_github.assert_called_with(load_repo_settings('repo'))