allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [15/25] git commit: [#4213] ticket:345 import from trac: set milestone options
Date Mon, 08 Jul 2013 19:28:27 GMT
[#4213]  ticket:345 import from trac: set milestone options


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/0efd308a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/0efd308a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/0efd308a

Branch: refs/heads/cj/4656
Commit: 0efd308af702c9b0f0b39511a0db093d8aa9060c
Parents: d8ed95c
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Mon May 27 10:55:43 2013 +0400
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Sun Jul 7 06:08:00 2013 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/import_support.py     | 30 ++++++++++++++++
 .../forgetracker/tests/functional/data/sf.json  |  3 +-
 .../tests/functional/test_import.py             | 37 ++++++++++++++++++++
 3 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0efd308a/ForgeTracker/forgetracker/import_support.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/import_support.py b/ForgeTracker/forgetracker/import_support.py
index 6970004..56c6947 100644
--- a/ForgeTracker/forgetracker/import_support.py
+++ b/ForgeTracker/forgetracker/import_support.py
@@ -18,11 +18,13 @@
 #-*- python -*-
 import logging
 import json
+import shlex
 from datetime import datetime
 from cStringIO import StringIO
 
 # Non-stdlib imports
 from pylons import tmpl_context as c
+from allura.lib import helpers as h
 
 from ming.orm.ormsession import ThreadLocalORMSession
 
@@ -140,6 +142,33 @@ class ImportSupport(object):
             return u._id
         return None
 
+    def check_suctom_field(self, field, value):
+        field = c.app.globals.get_custom_field(field)
+        if (field['type'] == 'select') and (value != ''):
+            field_options = h.really_unicode(field['options'])
+            try:
+                field_options = shlex.split(field_options.encode('utf-8'))
+                field_options = map(h.really_unicode, field_options)
+            except ValueError:
+                field_options = field_options.split()
+            field_options = [o.replace('"', '') for o in field_options]
+            if value not in field_options:
+                field['options'] = ' '.join([field['options'], value])
+        elif (field['type'] == 'milestone') and (value != ''):
+            milestones = field['milestones']
+            is_exists = False
+            for milestone in milestones:
+                if milestone['name'] == value:
+                    is_exists = True
+            if not is_exists:
+                milestone = {'due_date': '',
+                             'complete': False,
+                             'description': '',
+                             'name': value,
+                             'old_name': value}
+                field['milestones'].append(milestone)
+        ThreadLocalORMSession.flush_all()
+
     def custom(self, ticket, field, value):
         field = '_' + field
         if not c.app.has_custom_field(field):
@@ -148,6 +177,7 @@ class ImportSupport(object):
             ThreadLocalORMSession.flush_all()
         if 'custom_fields' not in ticket:
             ticket['custom_fields'] = {}
+        self.check_suctom_field(field, value)
         ticket['custom_fields'][field] = value
 
     #

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0efd308a/ForgeTracker/forgetracker/tests/functional/data/sf.json
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/data/sf.json b/ForgeTracker/forgetracker/tests/functional/data/sf.json
index 93632fd..58e322c 100644
--- a/ForgeTracker/forgetracker/tests/functional/data/sf.json
+++ b/ForgeTracker/forgetracker/tests/functional/data/sf.json
@@ -47,7 +47,8 @@
           "date_updated": "2009-07-20T15:44:32Z", 
           "description": "This problem occurs with IE 7, Windows Vista:\r\nOn the project's
public info page (for example:\r\nhttps://sourceforge.net/project/admin/public_info.php?group_id=258655),
the text boxes next to \"Descriptive Name\" and \"Project Description\" are not aligned properly;
see the screenshot attached. ", 
           "id": 204, 
-          "keywords": "ENGR", 
+          "keywords": "ENGR",
+          "milestone": "test_milestone",
           "private": false, 
           "resolution": "fixed", 
           "status": "open", 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0efd308a/ForgeTracker/forgetracker/tests/functional/test_import.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_import.py b/ForgeTracker/forgetracker/tests/functional/test_import.py
index 7df19f7..06fde25 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_import.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_import.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -17,6 +18,7 @@
 
 import os
 import json
+from formencode.variabledecode import variable_encode
 from datetime import datetime, timedelta
 from nose.tools import assert_equal
 
@@ -89,6 +91,39 @@ class TestImportController(TestRestApiBase):
         assert not r.json['errors']
 
     @td.with_tracker
+    def test_import_custom_field(self):
+        params = dict(
+            custom_fields=[
+                dict(name='_resolution', label='Resolution', type='select',
+                     options='oné "one and á half" two'),
+               ],
+            open_status_names='aa bb',
+            closed_status_names='cc',
+            )
+        self.app.post(
+            '/admin/bugs/set_custom_fields',
+            params=variable_encode(params))
+        here_dir = os.path.dirname(__file__)
+        api_ticket = M.ApiTicket(user_id=self.user._id, capabilities={'import': ['Projects','test']},
+                                 expires=datetime.utcnow() + timedelta(days=1))
+        ming.orm.session(api_ticket).flush()
+        self.set_api_token(api_ticket)
+
+        doc_text = open(here_dir + '/data/sf.json').read()
+        doc_json = json.loads(doc_text)
+        ticket_json = doc_json['trackers']['default']['artifacts'][0]
+        self.api_post('/rest/p/test/bugs/perform_import',
+            doc=doc_text, options='{"user_map": {"hinojosa4": "test-admin", "ma_boehm": "test-user"}}')
+
+        ming.orm.ThreadLocalORMSession.flush_all()
+        M.MonQTask.run_ready()
+        ming.orm.ThreadLocalORMSession.flush_all()
+
+        r = self.app.get('/p/test/bugs/204/')
+        assert '<option selected value="fixed">fixed</option>' in r
+        assert '<option value="one and á half">one and á half</option>' in
r
+
+    @td.with_tracker
     def test_import(self):
         here_dir = os.path.dirname(__file__)
         api_ticket = M.ApiTicket(user_id=self.user._id, capabilities={'import': ['Projects','test']},
@@ -124,6 +159,8 @@ class TestImportController(TestRestApiBase):
         assert_equal(r.json['tickets'][0]['summary'], ticket_json['summary'])
 
         r = self.app.get('/p/test/bugs/204/')
+        assert '<option value="2.0">2.0</option>' in r
+        assert '<option selected value="test_milestone">test_milestone</option>'
in r
         assert ticket_json['summary'] in r
         r = self.app.get('/p/test/bugs/')
         assert ticket_json['summary'] in r


Mime
View raw message