Changeset 232274 in webkit


Ignore:
Timestamp:
May 29, 2018 2:29:57 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Export changes to web-platform-test as part of the webkit-patch upload workflow
https://bugs.webkit.org/show_bug.cgi?id=184914

Patch by Brendan McLoughlin <brendan@bocoup.com> on 2018-05-29
Reviewed by Youenn Fablet.

  • Scripts/webkitpy/tool/commands/upload.py:

(Upload):
(CreateBug.execute):
(WPTChangeExport):

  • Scripts/webkitpy/tool/steps/init.py:
  • Scripts/webkitpy/tool/steps/wptchangeexport.py: Added.

(WPTChangeExport):
(WPTChangeExport.options):
(WPTChangeExport.run):

  • Scripts/webkitpy/w3c/common.py:
  • Scripts/webkitpy/w3c/test_exporter.py:

(WebPlatformTestExporter):
(WebPlatformTestExporter.init):
(WebPlatformTestExporter.username):
(WebPlatformTestExporter.token):
(WebPlatformTestExporter._github):
(WebPlatformTestExporter._wpt_fork_branch_github_url):
(WebPlatformTestExporter._wpt_fork_remote):
(WebPlatformTestExporter._wpt_fork_push_url):
(WebPlatformTestExporter._git):
(WebPlatformTestExporter._branch_name):
(WebPlatformTestExporter._public_branch_name):
(WebPlatformTestExporter._wpt_patch):
(WebPlatformTestExporter.has_wpt_changes):
(WebPlatformTestExporter._find_filename):
(WebPlatformTestExporter._is_ignored_file):
(WebPlatformTestExporter._strip_ignored_files_from_diff):
(WebPlatformTestExporter.write_git_patch_file):
(WebPlatformTestExporter._prompt_for_token):
(WebPlatformTestExporter._prompt_for_username):
(WebPlatformTestExporter._ensure_username_and_token):
(WebPlatformTestExporter._validate_and_save_token):
(WebPlatformTestExporter.create_branch_with_patch):
(WebPlatformTestExporter.push_to_wpt_fork):
(WebPlatformTestExporter.make_pull_request):
(WebPlatformTestExporter.delete_local_branch):
(WebPlatformTestExporter.create_upload_remote_if_needed):
(WebPlatformTestExporter.do_export):
(parse_args):
(TestExporter): Deleted.
(TestExporter.init): Deleted.
(TestExporter._ensure_wpt_repository): Deleted.
(TestExporter._fetch_wpt_repository): Deleted.
(TestExporter._ensure_new_branch_name): Deleted.
(TestExporter.download_and_commit_patch): Deleted.
(TestExporter.clean): Deleted.
(TestExporter.create_branch_with_patch): Deleted.
(TestExporter.push_to_wpt_fork): Deleted.
(TestExporter.make_pull_request): Deleted.
(TestExporter.create_wpt_pull_request): Deleted.
(TestExporter.delete_local_branch): Deleted.
(TestExporter.create_git_patch): Deleted.
(TestExporter.create_upload_remote): Deleted.
(TestExporter.do_export): Deleted.

  • Scripts/webkitpy/w3c/test_exporter_unittest.py:

(TestExporterTest.MockGit):
(TestExporterTest.MockGit.create_patch):
(TestExporterTest.test_export):
(TestExporterTest.test_export_with_specific_branch):
(TestExporterTest):
(TestExporterTest.test_export_interactive_mode):
(TestExporterTest.test_export_invalid_token):
(TestExporterTest.test_export_wrong_token):
(TestExporterTest.test_has_wpt_changes):
(TestExporterTest.test_has_no_wpt_changes_for_no_diff):
(TestExporterTest.test_ignore_changes_to_expected_file):

Location:
trunk/Tools
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r232270 r232274  
     12018-05-29  Brendan McLoughlin  <brendan@bocoup.com>
     2
     3        Export changes to web-platform-test as part of the webkit-patch upload workflow
     4        https://bugs.webkit.org/show_bug.cgi?id=184914
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * Scripts/webkitpy/tool/commands/upload.py:
     9        (Upload):
     10        (CreateBug.execute):
     11        (WPTChangeExport):
     12        * Scripts/webkitpy/tool/steps/__init__.py:
     13        * Scripts/webkitpy/tool/steps/wptchangeexport.py: Added.
     14        (WPTChangeExport):
     15        (WPTChangeExport.options):
     16        (WPTChangeExport.run):
     17        * Scripts/webkitpy/w3c/common.py:
     18        * Scripts/webkitpy/w3c/test_exporter.py:
     19        (WebPlatformTestExporter):
     20        (WebPlatformTestExporter.__init__):
     21        (WebPlatformTestExporter.username):
     22        (WebPlatformTestExporter.token):
     23        (WebPlatformTestExporter._github):
     24        (WebPlatformTestExporter._wpt_fork_branch_github_url):
     25        (WebPlatformTestExporter._wpt_fork_remote):
     26        (WebPlatformTestExporter._wpt_fork_push_url):
     27        (WebPlatformTestExporter._git):
     28        (WebPlatformTestExporter._branch_name):
     29        (WebPlatformTestExporter._public_branch_name):
     30        (WebPlatformTestExporter._wpt_patch):
     31        (WebPlatformTestExporter.has_wpt_changes):
     32        (WebPlatformTestExporter._find_filename):
     33        (WebPlatformTestExporter._is_ignored_file):
     34        (WebPlatformTestExporter._strip_ignored_files_from_diff):
     35        (WebPlatformTestExporter.write_git_patch_file):
     36        (WebPlatformTestExporter._prompt_for_token):
     37        (WebPlatformTestExporter._prompt_for_username):
     38        (WebPlatformTestExporter._ensure_username_and_token):
     39        (WebPlatformTestExporter._validate_and_save_token):
     40        (WebPlatformTestExporter.create_branch_with_patch):
     41        (WebPlatformTestExporter.push_to_wpt_fork):
     42        (WebPlatformTestExporter.make_pull_request):
     43        (WebPlatformTestExporter.delete_local_branch):
     44        (WebPlatformTestExporter.create_upload_remote_if_needed):
     45        (WebPlatformTestExporter.do_export):
     46        (parse_args):
     47        (TestExporter): Deleted.
     48        (TestExporter.__init__): Deleted.
     49        (TestExporter._ensure_wpt_repository): Deleted.
     50        (TestExporter._fetch_wpt_repository): Deleted.
     51        (TestExporter._ensure_new_branch_name): Deleted.
     52        (TestExporter.download_and_commit_patch): Deleted.
     53        (TestExporter.clean): Deleted.
     54        (TestExporter.create_branch_with_patch): Deleted.
     55        (TestExporter.push_to_wpt_fork): Deleted.
     56        (TestExporter.make_pull_request): Deleted.
     57        (TestExporter.create_wpt_pull_request): Deleted.
     58        (TestExporter.delete_local_branch): Deleted.
     59        (TestExporter.create_git_patch): Deleted.
     60        (TestExporter.create_upload_remote): Deleted.
     61        (TestExporter.do_export): Deleted.
     62        * Scripts/webkitpy/w3c/test_exporter_unittest.py:
     63        (TestExporterTest.MockGit):
     64        (TestExporterTest.MockGit.create_patch):
     65        (TestExporterTest.test_export):
     66        (TestExporterTest.test_export_with_specific_branch):
     67        (TestExporterTest):
     68        (TestExporterTest.test_export_interactive_mode):
     69        (TestExporterTest.test_export_invalid_token):
     70        (TestExporterTest.test_export_wrong_token):
     71        (TestExporterTest.test_has_wpt_changes):
     72        (TestExporterTest.test_has_no_wpt_changes_for_no_diff):
     73        (TestExporterTest.test_ignore_changes_to_expected_file):
     74
    1752018-05-29  Fujii Hironori  <Hironori.Fujii@sony.com>
    276
  • trunk/Tools/Scripts/webkitpy/tool/commands/upload.py

    r231925 r232274  
    287287        steps.PostDiff,
    288288        steps.SubmitToEWS,
     289        steps.WPTChangeExport,
    289290    ]
    290291    long_help = """upload uploads the current diff to bugs.webkit.org.
     
    532533        else:
    533534            self.create_bug_from_patch(options, args, tool)
     535
     536
     537class WPTChangeExport(AbstractPatchUploadingCommand):
     538    name = "wpt-change-export"
     539    help_text = "Opens a pull request to synchronize any changes in the LayoutTests/imported/w3c/web-platform-tests directory"
     540    argument_names = "[BUGID]"
     541    steps = [
     542        steps.WPTChangeExport,
     543    ]
     544
     545    long_help = """Opens a pull request to the w3c/web-platform-tests
     546    github repo for any changes in the
     547    LayoutTests/imported/w3c/web-platform-tests directory. This step
     548    will noop if there are no changes in the web-platform-tests directory.
     549    The user will be prompted to provide a github username and OAuth token
     550    the first time this is run.
     551    """
     552
     553    def _prepare_state(self, options, args, tool):
     554        state = {}
     555        state["bug_id"] = self._bug_id(options, args, tool, state)
     556        return state
  • trunk/Tools/Scripts/webkitpy/tool/steps/__init__.py

    r231925 r232274  
    6767from webkitpy.tool.steps.validatechangelogs import ValidateChangeLogs
    6868from webkitpy.tool.steps.validatereviewer import ValidateReviewer
     69from webkitpy.tool.steps.wptchangeexport import WPTChangeExport
  • trunk/Tools/Scripts/webkitpy/w3c/common.py

    r231925 r232274  
    3131import json
    3232import logging
     33import os
    3334
    3435
    35 WPT_GH_ORG = 'w3c'
    36 WPT_GH_REPO_NAME = 'web-platform-tests'
     36WPT_GH_ORG = os.environ.get('WPT_GH_ORG', 'w3c')
     37WPT_GH_REPO_NAME = os.environ.get('WPT_GH_REPO_NAME', 'web-platform-tests')
    3738WPT_GH_URL = 'https://github.com/%s/%s/' % (WPT_GH_ORG, WPT_GH_REPO_NAME)
    3839WPT_MIRROR_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-tests.git'
  • trunk/Tools/Scripts/webkitpy/w3c/test_exporter.py

    r232195 r232274  
    2929import os
    3030import time
     31import json
     32from urllib2 import HTTPError
    3133
    3234from webkitpy.common.checkout.scm.git import Git
     
    3638from webkitpy.w3c.wpt_github import WPTGitHub
    3739from webkitpy.w3c.wpt_linter import WPTLinter
     40from webkitpy.w3c.common import WPT_GH_ORG
     41from webkitpy.common.memoized import memoized
    3842
    3943_log = logging.getLogger(__name__)
    4044
    4145WEBKIT_WPT_DIR = 'LayoutTests/imported/w3c/web-platform-tests'
    42 WPT_PR_URL = "https://github.com/w3c/web-platform-tests/pull/"
     46WPT_PR_URL = "https://github.com/%s/web-platform-tests/pull/" % WPT_GH_ORG
    4347WEBKIT_EXPORT_PR_LABEL = 'webkit-export'
    4448
    45 
    46 class TestExporter(object):
    47 
     49EXCLUDED_FILE_SUFFIXES = ['-expected.txt', '.worker.html', '.any.html', '.any.worker.html']
     50
     51
     52class WebPlatformTestExporter(object):
    4853    def __init__(self, host, options, gitClass=Git, bugzillaClass=Bugzilla, WPTGitHubClass=WPTGitHub, WPTLinterClass=WPTLinter):
    4954        self._host = host
     
    5358        self._host.initialize_scm()
    5459
     60        self._WPTGitHubClass = WPTGitHubClass
     61        self._gitClass = gitClass
    5562        self._bugzilla = bugzillaClass()
    5663        self._bug_id = options.bug_id
     
    6572            self._options.repository_directory = webkit_finder.path_from_webkit_base('WebKitBuild', 'w3c-tests', 'web-platform-tests')
    6673
    67         self._git = self._ensure_wpt_repository("https://github.com/w3c/web-platform-tests.git", self._options.repository_directory, gitClass)
    6874        self._linter = WPTLinterClass(self._options.repository_directory, host.filesystem)
    6975
     76        self._bugzilla_url = "https://bugs.webkit.org/show_bug.cgi?id=" + str(self._bug_id)
     77        self._commit_message = options.message
     78        if not self._commit_message:
     79            self._commit_message = 'WebKit export of ' + self._bugzilla_url if self._bug_id else 'Export made from a WebKit repository'
     80
     81    @property
     82    def username(self):
     83        if hasattr(self, '_username'):
     84            return self._username
     85
     86        self._ensure_username_and_token(self._options)
     87        return self._username
     88
     89    @property
     90    def token(self):
     91        if hasattr(self, '_token'):
     92            return self._token
     93
     94        self._ensure_username_and_token(self._options)
     95        return self._token
     96
     97    @property
     98    @memoized
     99    def _github(self):
     100        return self._WPTGitHubClass(self._host, self.username, self.token) if self.username and self.token else None
     101
     102    @property
     103    @memoized
     104    def _wpt_fork_branch_github_url(self):
     105        return "https://github.com/" + self.username + "/web-platform-tests/tree/" + self._public_branch_name
     106
     107    @property
     108    @memoized
     109    def _wpt_fork_remote(self):
     110        wpt_fork_remote = self._options.repository_remote
     111        if not wpt_fork_remote:
     112            wpt_fork_remote = self.username
     113
     114        return wpt_fork_remote
     115
     116    @property
     117    @memoized
     118    def _wpt_fork_push_url(self):
     119        wpt_fork_push_url = self._options.repository_remote_url
     120        if not wpt_fork_push_url:
     121            wpt_fork_push_url = "https://" + self.username + "@github.com/" + self.username + "/web-platform-tests.git"
     122
     123        return wpt_fork_push_url
     124
     125    @property
     126    @memoized
     127    def _git(self):
     128        return self._ensure_wpt_repository("https://github.com/w3c/web-platform-tests.git", self._options.repository_directory, self._gitClass)
     129
     130    @property
     131    @memoized
     132    def _branch_name(self):
     133        return self._ensure_new_branch_name()
     134
     135    @property
     136    @memoized
     137    def _public_branch_name(self):
     138        options = self._options
     139        return options.public_branch_name if options.public_branch_name else self._branch_name
     140
     141    @property
     142    @memoized
     143    def _wpt_patch(self):
     144        patch_data = self._host.scm().create_patch(self._options.git_commit, [WEBKIT_WPT_DIR]) or ''
     145        patch_data = self._strip_ignored_files_from_diff(patch_data)
     146        if not 'diff' in patch_data:
     147            return ''
     148        return patch_data
     149
     150    def has_wpt_changes(self):
     151        return bool(self._wpt_patch)
     152
     153    def _find_filename(self, line):
     154        return line.split(' ')[-1]
     155
     156    def _is_ignored_file(self, filename):
     157        for suffix in EXCLUDED_FILE_SUFFIXES:
     158            if filename.endswith(suffix):
     159                return True
     160        return False
     161
     162    def _strip_ignored_files_from_diff(self, diff):
     163        lines = diff.split('\n')
     164        include_file = True
     165        new_lines = []
     166        for line in lines:
     167            if line.startswith('diff'):
     168                include_file = True
     169                filename = self._find_filename(line)
     170                if self._is_ignored_file(filename):
     171                    include_file = False
     172            if include_file:
     173                new_lines.append(line)
     174
     175        return '\n'.join(new_lines)
     176
     177    def write_git_patch_file(self):
     178        _, patch_file = self._filesystem.open_binary_tempfile('wpt_export_patch')
     179        patch_data = self._wpt_patch
     180        if not 'diff' in patch_data:
     181            _log.info('No changes to upstream, patch data is: "%s"' % (patch_data))
     182            return ''
     183        # FIXME: We can probably try to use --relative git parameter to not do that replacement.
     184        patch_data = patch_data.replace(WEBKIT_WPT_DIR + '/', '')
     185        self._filesystem.write_text_file(patch_file, patch_data)
     186        return patch_file
     187
     188    def _prompt_for_token(self, options):
     189        if options.non_interactive:
     190            return None
     191        return self._host.user.prompt_password('Enter GitHub OAuth token (or empty string to skip creating a pull request): ')
     192
     193    def _prompt_for_username(self, options):
     194        if options.non_interactive:
     195            return None
     196        return self._host.user.prompt('Enter your GitHub username: ')
     197
     198    def _ensure_username_and_token(self, options):
    70199        self._username = options.username
    71200        if not self._username:
     201            # FIXME: Use the keychain to store username and oauth token instead of .git/config
    72202            self._username = self._git.local_config('github.username').rstrip()
    73203            if not self._username:
    74204                self._username = os.environ.get('GITHUB_USERNAME')
    75205            if not self._username:
     206                self._username = self._prompt_for_username(options)
     207            if not self._username:
    76208                raise ValueError("Missing GitHub username, please provide it as a command argument (see help for the command).")
    77         elif not self._git.local_config('github.username'):
    78             self._git.set_local_config('github.username', self._username)
    79209
    80210        self._token = options.token
     
    84214                self._token = os.environ.get('GITHUB_TOKEN')
    85215            if not self._token:
     216                self._token = self._prompt_for_token(options)
     217            if not self._token:
    86218                _log.info("Missing GitHub token, the script will not be able to create a pull request to W3C web-platform-tests repository.")
    87         elif not self._git.local_config('github.token'):
    88             self._git.set_local_config('github.token', self._token)
    89 
    90         self._github = WPTGitHubClass(self._host, self._username, self._token) if self._username and self._token else None
    91 
    92         self._branch_name = self._ensure_new_branch_name()
    93         self._public_branch_name = options.public_branch_name if options.public_branch_name else self._branch_name
    94         self._bugzilla_url = "https://bugs.webkit.org/show_bug.cgi?id=" + str(self._bug_id)
    95         self._commit_message = options.message
    96         if not self._commit_message:
    97             self._commit_message = 'WebKit export of ' + self._bugzilla_url if self._bug_id else 'Export made from a WebKit repository'
    98 
    99         self._wpt_fork_remote = options.repository_remote
    100         if not self._wpt_fork_remote:
    101             self._wpt_fork_remote = self._username
    102 
    103         self._wpt_fork_push_url = options.repository_remote_url
    104         if not self._wpt_fork_push_url:
    105             self._wpt_fork_push_url = "https://" + self._username + "@github.com/" + self._username + "/web-platform-tests.git"
     219
     220        if self._token:
     221            self._validate_and_save_token(self._username, self._token)
     222
     223    def _validate_and_save_token(self, username, token):
     224        url = 'https://api.github.com/user?access_token=%s' % (token,)
     225        try:
     226            response = self._host.web.request(method='GET', url=url, data=None)
     227        except HTTPError as e:
     228            raise Exception("OAuth token is not valid")
     229        data = json.load(response)
     230        login = data.get('login', None)
     231        if login != username:
     232            raise Exception("OAuth token does not match the provided username. Provided user: %s, github login: %s" % (username, login))
     233        else:
     234            # Username and token are valid. Save them in the git config so we
     235            # do not need to ask for them again
     236            if not self._git.local_config('github.token'):
     237                self._git.set_local_config('github.token', token)
     238            if not self._git.local_config('github.username'):
     239                self._git.set_local_config('github.username', username)
    106240
    107241    def _ensure_wpt_repository(self, url, wpt_repository_directory, gitClass):
     
    157291            self._git.checkout_new_branch(self._branch_name)
    158292        try:
    159             self._git.apply_mail_patch([patch, '--exclude', '*-expected.txt', '--exclude', '*.worker.html', '--exclude', '*.any.html', '--exclude', '*.any.worker.html'])
     293            self._git.apply_mail_patch([patch])
    160294        except Exception as e:
    161295            _log.warning(e)
     
    166300
    167301    def push_to_wpt_fork(self):
    168         self.create_upload_remote()
    169         wpt_fork_branch_github_url = "https://github.com/" + self._username + "/web-platform-tests/tree/" + self._public_branch_name
     302        self.create_upload_remote_if_needed()
    170303        _log.info('Pushing branch ' + self._branch_name + " to " + self._git.remote(["get-url", self._wpt_fork_remote]).rstrip())
    171304        _log.info('This may take some time')
    172305        self._git.push([self._wpt_fork_remote, self._branch_name + ":" + self._public_branch_name, '-f'])
    173         _log.info('Branch available at ' + wpt_fork_branch_github_url)
     306        _log.info('Branch available at ' + self._wpt_fork_branch_github_url)
    174307        return True
    175308
    176309    def make_pull_request(self):
    177310        if not self._github:
    178             _log.info('Missing information to create a pull request')
     311            _log.info('Skipping pull request because OAuth token was not provided. You can open the pull request manually using the branch ' + self._wpt_fork_branch_github_url)
    179312            return
    180313
     
    190323            except Exception as e:
    191324                _log.warning(e)
    192                 _log.info('Could not add label "%s" to pr #%s. User "%s" may not have permission to update labels in the w3c/web-platform-test repo.' % (WEBKIT_EXPORT_PR_LABEL, pr_number, self._username))
     325                _log.info('Could not add label "%s" to pr #%s. User "%s" may not have permission to update labels in the w3c/web-platform-test repo.' % (WEBKIT_EXPORT_PR_LABEL, pr_number, self.username))
    193326        if self._bug_id and pr_number:
    194327            self._bugzilla.post_comment_to_bug(self._bug_id, "Submitted web-platform-tests pull request: " + WPT_PR_URL + str(pr_number))
     
    207340
    208341    def delete_local_branch(self):
    209         _log.info('Removing branch ' + self._branch_name)
     342        _log.info('Removing local branch ' + self._branch_name)
    210343        self._git.checkout('master')
    211344        self._git.delete_branch(self._branch_name)
    212345
    213     def create_git_patch(self):
    214         patch_file = './patch.temp.' + str(time.clock())
    215         git_commit = "HEAD...." if not self._options.git_commit else self._options.git_commit + "~1.." + self._options.git_commit
    216         patch_data = self._host.scm().create_patch(git_commit, [WEBKIT_WPT_DIR])
    217         if not patch_data or not 'diff' in patch_data:
    218             _log.info('No changes to upstream, patch data is: "%s"' % (patch_data))
    219             return ''
    220         # FIXME: We can probably try to use --relative git parameter to not do that replacement.
    221         patch_data = patch_data.replace(WEBKIT_WPT_DIR + '/', '')
    222         patch_file = self._filesystem.abspath(patch_file)
    223         self._filesystem.write_text_file(patch_file, patch_data)
    224         return patch_file
    225 
    226     def create_upload_remote(self):
    227         if self._wpt_fork_remote in self._git.remote([]).splitlines():
    228             self._git.remote(["remove", self._wpt_fork_remote])
    229         self._git.remote(["add", self._wpt_fork_remote, self._wpt_fork_push_url])
     346    def create_upload_remote_if_needed(self):
     347        if not self._wpt_fork_remote in self._git.remote([]):
     348            self._git.remote(["add", self._wpt_fork_remote, self._wpt_fork_push_url])
    230349
    231350    def do_export(self):
    232         git_patch_file = self.create_git_patch()
     351        git_patch_file = self.write_git_patch_file()
    233352
    234353        if not git_patch_file:
     
    295414    parser.add_argument('-d', '--repository', dest='repository_directory', default=None, help='repository directory')
    296415    parser.add_argument('-c', '--create-pr', dest='create_pull_request', action='store_true', default=False, help='create pull request to w3c web-platform-tests')
     416    parser.add_argument('--non-interactive', action='store_true', dest='non_interactive', default=False, help='Never prompt the user, fail as fast as possible.')
    297417
    298418    options, args = parser.parse_known_args(args)
     
    310430
    311431    logger = logging.getLogger('webkitpy.w3c.test_exporter')
     432    logger.propagate = False
    312433    logger.setLevel(logging.INFO)
    313434    handler = LogHandler()
     
    321442
    322443    configure_logging()
    323 
    324     test_exporter = TestExporter(Host(), options)
     444    test_exporter = WebPlatformTestExporter(Host(), options)
     445
     446    if not test_exporter.has_wpt_changes():
     447        _log.info('No changes to upstream. Exiting...')
     448        return
    325449
    326450    test_exporter.do_export()
  • trunk/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py

    r231925 r232274  
    2626from webkitpy.common.system.filesystem_mock import MockFileSystem
    2727from webkitpy.common.system.executive_mock import MockExecutive2
    28 from webkitpy.w3c.test_exporter import TestExporter, parse_args
     28from webkitpy.w3c.test_exporter import WebPlatformTestExporter, parse_args
    2929from webkitpy.w3c.wpt_github_mock import MockWPTGitHub
    3030
     
    4747
    4848    class MockGit(object):
     49        mock_format_patch_result = 'my patch containing some diffs'
     50
    4951        @classmethod
    5052        def clone(cls, url, directory, executive=None):
     
    9597        def create_patch(self, commit, arguments):
    9698            self.calls.append('create_patch ' + commit + ' ' + str(arguments))
    97             return 'my patch containing some diffs'
     99            return self.mock_format_patch_result
    98100
    99101    class MyMockHost(MockHost):
     
    123125    def test_export(self):
    124126        host = TestExporterTest.MyMockHost()
    125         options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN'])
    126         exporter = TestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
     127        host.web.responses.append({'status_code': 200, 'body': '{"login": "USER"}'})
     128        options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN'])
     129        exporter = WebPlatformTestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
    127130        exporter.do_export()
    128131        self.assertEquals(exporter._github.calls, ['create_pr', 'add_label "webkit-export"'])
     
    134137            'reset hard origin/master',
    135138            'checkout new branch wpt-export-for-webkit-1234',
    136             'apply_mail_patch patch.temp --exclude *-expected.txt --exclude *.worker.html --exclude *.any.html --exclude *.any.worker.html',
     139            'apply_mail_patch patch.temp ',
    137140            'commit -a -m WebKit export of https://bugs.webkit.org/show_bug.cgi?id=1234',
    138141            'remote ',
     
    151154    def test_export_with_specific_branch(self):
    152155        host = TestExporterTest.MyMockHost()
     156        host.web.responses.append({'status_code': 200, 'body': '{"login": "USER"}'})
    153157        options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN', '-bn', 'wpt-export-branch'])
    154         exporter = TestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
     158        exporter = WebPlatformTestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
    155159        exporter.do_export()
    156160        self.assertEquals(exporter._git.calls, [
     
    160164            'reset hard origin/master',
    161165            'checkout new branch wpt-export-for-webkit-1234',
    162             'apply_mail_patch patch.temp --exclude *-expected.txt --exclude *.worker.html --exclude *.any.html --exclude *.any.worker.html',
     166            'apply_mail_patch patch.temp ',
    163167            'commit -a -m WebKit export of https://bugs.webkit.org/show_bug.cgi?id=1234',
    164168            'remote ',
     
    170174            'checkout master',
    171175            'reset hard origin/master'])
     176
     177    def test_export_interactive_mode(self):
     178        host = TestExporterTest.MyMockHost()
     179        host.web.responses.append({'status_code': 200, 'body': '{"login": "USER"}'})
     180        options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN', '--interactive'])
     181        exporter = WebPlatformTestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
     182        exporter.do_export()
     183
     184    def test_export_invalid_token(self):
     185        host = TestExporterTest.MyMockHost()
     186        host.web.responses.append({'status_code': 401})
     187        options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN'])
     188        exporter = WebPlatformTestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
     189        with self.assertRaises(Exception) as context:
     190            exporter.do_export()
     191        self.assertIn('OAuth token is not valid', str(context.exception))
     192
     193    def test_export_wrong_token(self):
     194        host = TestExporterTest.MyMockHost()
     195        host.web.responses.append({'status_code': 200, 'body': '{"login": "DIFF_USER"}'})
     196        options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN'])
     197        exporter = WebPlatformTestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
     198        with self.assertRaises(Exception) as context:
     199            exporter.do_export()
     200        self.assertIn('OAuth token does not match the provided username', str(context.exception))
     201
     202    def test_has_wpt_changes(self):
     203        host = TestExporterTest.MyMockHost()
     204        options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN'])
     205        exporter = WebPlatformTestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
     206        self.assertTrue(exporter.has_wpt_changes())
     207
     208    def test_has_no_wpt_changes_for_no_diff(self):
     209        host = TestExporterTest.MyMockHost()
     210        host._mockSCM.mock_format_patch_result = None
     211        options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN'])
     212        exporter = WebPlatformTestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
     213        self.assertFalse(exporter.has_wpt_changes())
     214
     215    def test_ignore_changes_to_expected_file(self):
     216        host = TestExporterTest.MyMockHost()
     217        host._mockSCM.mock_format_patch_result = """
     218Subversion Revision: 231920
     219diff --git a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/header-values-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/header-values-expected.txt
     220
     221+change to expected
     222"""
     223        options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN'])
     224        exporter = WebPlatformTestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
     225        self.assertFalse(exporter.has_wpt_changes())
Note: See TracChangeset for help on using the changeset viewer.