Skip to content

Commit 1adf250

Browse files
committed
Updated test suites to support a placeholder for the namespaces
- modified conftest setup for putting the placeholders in place - modified the cassettes to replace explicit namespaces call with placeholders - updated README with usage of the test suites
1 parent 090840d commit 1adf250

File tree

43 files changed

+535
-517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+535
-517
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,36 @@ and then you'll have the executable in `bin`:
133133

134134
% bin/git-repo --help
135135

136+
To run the tests:
137+
138+
% bin/py.test
139+
140+
You can use the following options for py.test to help you debug when tests fail:
141+
142+
* `-v` will show more details upon errors
143+
* `-x` will stop upon the first failure
144+
* `--pdb` will launch the debugger where an exception has been launched
145+
146+
147+
The tests use recordings of exchanged HTTP data, so that we don't need real credentials
148+
and a real connection, when testing the API on minor changes. Those recordings are
149+
called cassettes, thanks to the [betamax](https://github.com/sigmavirus24/betamax) framework
150+
being in use in the test suites.
151+
152+
When running existing tests, based on the provided cassettes, you don't need any
153+
setting. Also, if you've got a configuration in `~/.gitconfig`, the tests will use
154+
them. Anyway, you can use environment variables for those settings (environment
155+
variables will have precedence over the configuration settings):
156+
157+
To use your own credentials, you can setup the following environment variables:
158+
159+
* `GITHUB_NAMESPACE` (which defaults to `not_configured`) is the name of the account to use on github
160+
* `GITLAB_NAMESPACE` (which defaults to `not_configured`) is the name of the account to use on gitlab
161+
* `BITBUCKET_NAMESPACE` (which defaults to `not_configured`) is the name of the account to use on bitbucket
162+
* `PRIVATE_KEY_GITHUB` your private token you've setup on github for your account
163+
* `PRIVATE_KEY_GITLAB` your private token you've setup on gitlab for your account
164+
* `PRIVATE_KEY_BITBUCKET` your private token you've setup on bitbucket for your account
165+
136166
### TODO
137167

138168
* [x] make a `git-repo fork` action
@@ -148,6 +178,8 @@ and then you'll have the executable in `bin`:
148178
* [ ] fetch them as local branches
149179
* [ ] add OAuth support for bitbucket
150180
* [ ] show a nice progress bar, while it's fetching
181+
* partly implemented: the issue looks like that gitpython expects output from git
182+
on stderr, whereas it's outputing on stdout.
151183
* for more features, write an issue or, even better, a PR!
152184

153185
### License

tests/conftest.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
#!/usr/bin/env python
22

3+
import os
4+
35
import betamax
46
from betamax_serializers import pretty_json
57

6-
# tests/conftest.py
7-
import os
8-
9-
api_token_github = os.environ.get('PRIVATE_KEY_GITHUB', 'not_configured')
10-
api_token_gitlab = os.environ.get('PRIVATE_KEY_GITLAB', 'not_configured')
11-
api_token_bitbucket = os.environ.get('PRIVATE_KEY_BITBUCKET', 'not_configured')
8+
record_mode = 'never' if os.environ.get('TRAVIS_GH3') else 'once'
9+
10+
# create default bogus values for tokens and namespaces if missing for pytest
11+
# to run without environment values
12+
# also if an environment variable is not set, then we don't want to record cassettes
13+
for service_name in ('github', 'gitlab', 'bitbucket'):
14+
token_name = 'PRIVATE_KEY_{}'.format(service_name.upper())
15+
namespace_name = '{}_NAMESPACE'.format(service_name.upper())
16+
if token_name not in os.environ:
17+
os.environ[token_name] = 'not_configured:test' # using a : for bitbucket's case
18+
record_mode = 'never'
19+
if namespace_name not in os.environ:
20+
os.environ[namespace_name] = 'not_configured'
21+
record_mode = 'never'
22+
23+
api_token_github = os.environ['PRIVATE_KEY_GITHUB']
24+
api_token_gitlab = os.environ['PRIVATE_KEY_GITLAB']
25+
api_token_bitbucket = os.environ['PRIVATE_KEY_BITBUCKET']
26+
27+
github_namespace = os.environ['GITHUB_NAMESPACE']
28+
gitlab_namespace = os.environ['GITLAB_NAMESPACE']
29+
bitbucket_namespace = os.environ['BITBUCKET_NAMESPACE']
1230

1331
betamax.Betamax.register_serializer(pretty_json.PrettyJSONSerializer)
1432

1533
with betamax.Betamax.configure() as config:
34+
config.default_cassette_options['record_mode'] = record_mode
1635
config.cassette_library_dir = 'tests/integration/cassettes'
1736
config.default_cassette_options['serialize_with'] = 'prettyjson'
1837
config.define_cassette_placeholder('<PRIVATE_KEY_GITHUB>', api_token_github)
1938
config.define_cassette_placeholder('<PRIVATE_KEY_GITLAB>', api_token_gitlab)
2039
config.define_cassette_placeholder('<PRIVATE_KEY_BITBUCKET>', api_token_bitbucket)
40+
config.define_cassette_placeholder('<GITHUB_NAMESPACE>', github_namespace)
41+
config.define_cassette_placeholder('<GITLAB_NAMESPACE>', gitlab_namespace)
42+
config.define_cassette_placeholder('<BITBUCKET_NAMESPACE>', bitbucket_namespace)
2143

2244

2345

tests/integration/cassettes/test_bitbucket_test_00_fork.json

Lines changed: 26 additions & 26 deletions
Large diffs are not rendered by default.

tests/integration/cassettes/test_bitbucket_test_01_create.json

Lines changed: 22 additions & 22 deletions
Large diffs are not rendered by default.

tests/integration/cassettes/test_bitbucket_test_02_delete.json

Lines changed: 17 additions & 17 deletions
Large diffs are not rendered by default.

tests/integration/cassettes/test_bitbucket_test_03_delete_nouser.json

Lines changed: 18 additions & 18 deletions
Large diffs are not rendered by default.

tests/integration/cassettes/test_bitbucket_test_04_clone.json

Lines changed: 11 additions & 11 deletions
Large diffs are not rendered by default.

tests/integration/cassettes/test_bitbucket_test_05_add.json

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

tests/integration/cassettes/test_bitbucket_test_06_add__name.json

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

tests/integration/cassettes/test_bitbucket_test_07_add__alone.json

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)