1#!/usr/bin/env python
2#
3#  dav_tests.py:  testing connections to HTTP and DAV servers.
4#
5#  Subversion is a tool for revision control.
6#  See http://subversion.apache.org for more information.
7#
8# ====================================================================
9#    Licensed to the Apache Software Foundation (ASF) under one
10#    or more contributor license agreements.  See the NOTICE file
11#    distributed with this work for additional information
12#    regarding copyright ownership.  The ASF licenses this file
13#    to you under the Apache License, Version 2.0 (the
14#    "License"); you may not use this file except in compliance
15#    with the License.  You may obtain a copy of the License at
16#
17#      http://www.apache.org/licenses/LICENSE-2.0
18#
19#    Unless required by applicable law or agreed to in writing,
20#    software distributed under the License is distributed on an
21#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22#    KIND, either express or implied.  See the License for the
23#    specific language governing permissions and limitations
24#    under the License.
25######################################################################
26
27# General modules
28import os, sys
29import re
30import socket
31import traceback
32
33# Our testing module
34import svntest
35
36# (abbreviation)
37Skip = svntest.testcase.Skip_deco
38SkipUnless = svntest.testcase.SkipUnless_deco
39XFail = svntest.testcase.XFail_deco
40Issues = svntest.testcase.Issues_deco
41Issue = svntest.testcase.Issue_deco
42Wimp = svntest.testcase.Wimp_deco
43Item = svntest.wc.StateItem
44
45
46######################################################################
47# Tests
48#
49#   Each test must return on success or raise on failure.
50
51
52#----------------------------------------------------------------------
53
54@SkipUnless(svntest.main.is_ra_type_dav)
55def connect_plain_http_server(sbox):
56  "connect to a non-DAV HTTP server"
57  expected_errors = svntest.verify.RegexListOutput([
58    "^svn: E170013: Unable to connect to a repository at URL '[^']+'",
59    "^svn: E175003: The server at '[^']+' does not support the HTTP/DAV protocol"
60  ], False)
61  svntest.actions.run_and_verify_svn([], expected_errors,
62                                     'info', svntest.main.non_dav_root_url)
63
64@SkipUnless(svntest.main.is_ra_type_dav)
65def connect_other_dav_server(sbox):
66  "connect to a DAV server which is not an SVN server"
67  svntest.actions.run_and_verify_svn([], svntest.verify.AnyOutput,
68                                     'info', svntest.main.other_dav_root_url)
69
70#----------------------------------------------------------------------
71
72@SkipUnless(svntest.main.is_remote_http_connection_allowed)
73def connect_to_github_server(sbox):
74  "connect to GitHub's SVN bridge"
75
76  #github_mirror_url = 'https://github.com/apache/subversion/trunk'
77  # FIXME: Subversion's mirror on GitHub seems to randomly return gateway
78  #        errors (status 504), so use this more stable one instead.
79  github_mirror_url = 'https://github.com/apache/serf/trunk'
80
81  # Skip this test if we can't connect to the GitHub server.
82  # We check this here instead of in a SkipUnless() predicate decorator,
83  # because the decorator's condition function is called seeveral times
84  # during test execution.
85  try:
86    s = socket.create_connection(('github.com', 443), 2)  # 2-second timeout
87    s.close()
88  except:
89    etype, value, _ = sys.exc_info()
90    reason = ''.join(traceback.format_exception_only(etype, value)).rstrip()
91    svntest.main.logger.warn('Connection to github.com failed: ' + reason)
92    raise svntest.Skip
93
94  svntest.actions.run_and_verify_svn(None, [], 'info', github_mirror_url)
95
96
97########################################################################
98# Run the tests
99
100
101# list all tests here, starting with None:
102test_list = [ None,
103              connect_plain_http_server,
104              connect_other_dav_server,
105              connect_to_github_server,
106             ]
107
108if __name__ == '__main__':
109  svntest.main.run_tests(test_list)
110  # NOTREACHED
111
112
113### End of file.
114