Usable SVN activities
This commit is contained in:
@@ -15,7 +15,11 @@ class AbstractAttractTest(AbstractPillarTest):
|
||||
pillar_server_class = AttractTestServer
|
||||
|
||||
def tearDown(self):
|
||||
from attract import subversion
|
||||
|
||||
subversion.task_logged._clear_state()
|
||||
self.unload_modules('attract')
|
||||
|
||||
AbstractPillarTest.tearDown(self)
|
||||
|
||||
def ensure_project_exists(self, project_overrides=None):
|
||||
|
@@ -1,7 +1,7 @@
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'formatters': {
|
||||
'default': {'format': '%(asctime)-15s %(levelname)8s %(name)s %(message)s'}
|
||||
'default': {'format': '%(asctime)-15s %(levelname)8s %(name)36s %(message)s'}
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
@@ -12,7 +12,7 @@ LOGGING = {
|
||||
},
|
||||
'loggers': {
|
||||
'pillar': {'level': 'DEBUG'},
|
||||
'attract_server': {'level': 'DEBUG'},
|
||||
'attract': {'level': 'DEBUG'},
|
||||
'werkzeug': {'level': 'INFO'},
|
||||
'eve': {'level': 'WARNING'},
|
||||
# 'requests': {'level': 'DEBUG'},
|
||||
|
41
tests/test_shortcode.py
Normal file
41
tests/test_shortcode.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# -*- coding=utf-8 -*-
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import collections
|
||||
import datetime
|
||||
import logging.config
|
||||
import unittest
|
||||
|
||||
from dateutil.tz import tzutc
|
||||
import mock
|
||||
import svn.common
|
||||
|
||||
from pillar.tests import common_test_data as ctd
|
||||
|
||||
import logging_config
|
||||
from attract import subversion
|
||||
from abstract_attract_test import AbstractAttractTest
|
||||
|
||||
SVN_SERVER_URL = 'svn://biserver/agent327'
|
||||
|
||||
|
||||
class ShortcodeTest(AbstractAttractTest):
|
||||
def setUp(self, **kwargs):
|
||||
AbstractAttractTest.setUp(self, **kwargs)
|
||||
|
||||
self.mngr = self.app.pillar_extensions['attract'].task_manager
|
||||
self.proj_id, self.project = self.ensure_project_exists()
|
||||
|
||||
def test_increment_simple(self):
|
||||
|
||||
from attract import shortcodes
|
||||
|
||||
with self.app.test_request_context():
|
||||
code = shortcodes.generate_shortcode(self.proj_id, u'jemoeder', u'ø')
|
||||
self.assertEqual(u'ø1', code)
|
||||
|
||||
with self.app.test_request_context():
|
||||
code = shortcodes.generate_shortcode(self.proj_id, u'jemoeder', u'č')
|
||||
self.assertEqual(u'č2', code)
|
@@ -13,10 +13,7 @@ from dateutil.tz import tzutc
|
||||
import mock
|
||||
import svn.common
|
||||
|
||||
from pillar.tests import common_test_data as ctd
|
||||
|
||||
import logging_config
|
||||
from attract import subversion
|
||||
from abstract_attract_test import AbstractAttractTest
|
||||
|
||||
SVN_SERVER_URL = 'svn://biserver/agent327'
|
||||
@@ -66,6 +63,8 @@ SVN_LOG_BATCH_WITH_TASK_MARKERS = [
|
||||
|
||||
class TestCommitLogObserver(unittest.TestCase):
|
||||
def setUp(self):
|
||||
from attract import subversion
|
||||
|
||||
self.client = subversion.obtain(SVN_SERVER_URL)
|
||||
# Passing in a real client to Mock() will ensure that isinstance() checks return True.
|
||||
self.mock_client = mock.Mock(self.client, name='svn_client')
|
||||
@@ -77,6 +76,8 @@ class TestCommitLogObserver(unittest.TestCase):
|
||||
Keep the underscore in the name when committing, and don't call it from
|
||||
anywhere. Unit tests shouldn't be dependent on network connections.
|
||||
"""
|
||||
from attract import subversion
|
||||
|
||||
observer = subversion.CommitLogObserver(self.client)
|
||||
observer.fetch_and_observe()
|
||||
|
||||
@@ -110,6 +111,8 @@ class TestCommitLogObserver(unittest.TestCase):
|
||||
self.assertEqual(self.observer.last_seen_revision, 51)
|
||||
|
||||
def test_task_markers(self):
|
||||
from attract import subversion
|
||||
|
||||
self.mock_client.log_default = mock.Mock(name='log_default',
|
||||
return_value=SVN_LOG_BATCH_WITH_TASK_MARKERS)
|
||||
blinks = []
|
||||
@@ -123,15 +126,16 @@ class TestCommitLogObserver(unittest.TestCase):
|
||||
self.observer.fetch_and_observe()
|
||||
|
||||
self.assertEqual(3, len(blinks))
|
||||
self.assertEqual({'log_entry': SVN_LOG_BATCH_WITH_TASK_MARKERS[1], 'shortcode': '1234'},
|
||||
self.assertEqual({'log_entry': SVN_LOG_BATCH_WITH_TASK_MARKERS[1], 'shortcode': 'T1234'},
|
||||
blinks[0])
|
||||
self.assertEqual({'log_entry': SVN_LOG_BATCH_WITH_TASK_MARKERS[2], 'shortcode': '4415'},
|
||||
self.assertEqual({'log_entry': SVN_LOG_BATCH_WITH_TASK_MARKERS[2], 'shortcode': 'T4415'},
|
||||
blinks[1])
|
||||
self.assertEqual({'log_entry': SVN_LOG_BATCH_WITH_TASK_MARKERS[2], 'shortcode': '4433'},
|
||||
self.assertEqual({'log_entry': SVN_LOG_BATCH_WITH_TASK_MARKERS[2], 'shortcode': 'T4433'},
|
||||
blinks[2])
|
||||
|
||||
def test_svn_error(self):
|
||||
"""SVN errors should not crash the observer."""
|
||||
from attract import subversion
|
||||
|
||||
self.mock_client.log_default = mock.Mock(name='log_default',
|
||||
side_effect=svn.common.SvnException('unittest'))
|
||||
@@ -146,6 +150,8 @@ class TestCommitLogObserver(unittest.TestCase):
|
||||
self.mock_client.log_default.assert_called_once()
|
||||
|
||||
def test_create_log_entry(self):
|
||||
from attract import subversion
|
||||
|
||||
entry = subversion.create_log_entry(date_text=u'2016-10-21 17:40:17 +0200',
|
||||
msg=u'Ünicøde is good',
|
||||
revision='123',
|
||||
@@ -200,7 +206,7 @@ class PushCommitTest(AbstractAttractTest):
|
||||
self.proj_id, self.project = self.ensure_project_exists()
|
||||
|
||||
def test_push_happy(self):
|
||||
from attract import cli
|
||||
from attract import cli, subversion
|
||||
|
||||
with self.app.test_request_context():
|
||||
_, token = cli.create_svner_account('svner@example.com', self.project['url'])
|
||||
@@ -225,6 +231,7 @@ class PushCommitTest(AbstractAttractTest):
|
||||
auth_token=token['token'])
|
||||
|
||||
self.assertEqual(1, len(blinks))
|
||||
self.assertEqual(u'T431134', blinks[0]['shortcode'])
|
||||
self.assertEqual(u'မြန်မာဘာသာ is beautiful.\n\nThis solves task [T431134]',
|
||||
blinks[0]['log_entry'].msg)
|
||||
self.assertEqual(datetime.datetime(2016, 10, 21, 15, 40, 17, 0, tzinfo=tzutc()),
|
||||
|
Reference in New Issue
Block a user