Skip to content

Commit 262b080

Browse files
authored
Merge pull request pyapi-gitlab#240 from pyapi-gitlab/issues/231
Issues/231 Adds docker-compose and unittests on travis-ci.
2 parents c75dc46 + 0352def commit 262b080

File tree

17 files changed

+101
-223
lines changed

17 files changed

+101
-223
lines changed

.travis.yml

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
env:
2-
- gitlab_user=root gitlab_password=5iveL!fe gitlab_host=http://localhost:8080
3-
services:
4-
- redis-server
51
language: python
2+
63
python:
74
- "2.7"
8-
- "3.2"
95
- "3.3"
106
- "3.4"
11-
rvm:
12-
- 2.1.0
13-
# install local gitlab
14-
before_install:
15-
- gem install bundler --no-ri --no-rdoc
16-
- scripts/prepare_test_env.sh
17-
- scripts/install_gitlab.sh
18-
# command to install dependencies
7+
- "3.5"
8+
- "3.5-dev"
9+
- "3.6"
10+
- "3.6-dev"
11+
- "3.7-dev"
12+
- "nightly"
13+
1914
install:
20-
- pip install -r test-requirements.txt
21-
- pip install coveralls
22-
# command to run tests
23-
script: coverage run --source=gitlab setup.py test
24-
after_success:
25-
coveralls
15+
- pip install -Ur test-requirements.txt
16+
17+
script: bash cov

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3
2+
3+
ADD . /code
4+
WORKDIR /code
5+
6+
RUN pip install --no-cache-dir -r test-requirements.txt
7+
CMD ["/bin/bash", "integration_cov"]

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
# Looking for contributors
22

3-
If you are interested in contributing to this wrapper we ask that all pull requests have an open issue that and they be referenced. We also ask that you submit unit tests for your changes to make sure there are no regressions.
3+
If you are interested in contributing to this wrapper we ask that all pull requests have an open issue that and they
4+
be referenced. We also ask that you submit unit tests for your changes to make sure there are no regressions.
5+
6+
## Pull Requests
7+
8+
We are currently working on getting pyapi-gitlab to 100% coverage in both unittests and integration tests. Well the
9+
integration testing is not fully flushed out yet the unittests are so we ask that all new pull requests have unittests
10+
with them.
11+
12+
## Setting up for development
13+
14+
If you wish to setup your system for development you will need to install the test requirements and we ask that you
15+
consider docker and docker-compose for integration testing.
16+
17+
To install the test requirements you will need to run the following command `pip install -Ur test-requirements.txt`.
18+
This will install both the `requirements.txt` and the `test-requirements.txt`.
19+
20+
To run the test simply run `./cov` from the project root directory.
21+
22+
To review the cover open the `index.html` file in the `coverage_html_report`.
23+
24+
To run the integration test run the commands below. This will build the docker containers and then start them. The
25+
containers will shutdown after the tests finish.
26+
27+
```
28+
docker-compose -f docker/v93/docker-compose.yml build
29+
docker-compose -f docker/v93/docker-compose.yml up --abort-on-container-exit
30+
```
431

532
# pyapi-gitlab
633

@@ -15,23 +42,23 @@ pyapi-gitlab is a python wrapper for the [Gitlab API](https://github.com/gitlabh
1542
[![Docs](https://readthedocs.org/projects/pyapi-gitlab/badge/?version=latest)](http://pyapi-gitlab.readthedocs.org/)
1643

1744

18-
1945
## Requirements
2046

2147
- requests
2248

2349

2450
## Naming convention
2551

26-
pyapi-gitlab has its own versioning in which the 2 first numbers indicates the Gitlab version that its supported for that library. a 7.5 version means that its compatible with the Gitlab 7.5 and lower API versions.
52+
pyapi-gitlab has its own versioning in which the 2 first numbers indicates the Gitlab version that its supported for
53+
that library. a 7.5 version means that its compatible with the Gitlab 7.5 and lower API versions.
2754

2855
## Installation
2956

3057
```bash
3158
pip install pyapi-gitlab
3259
```
3360

34-
pyapi-gitlab supports python version 2.6, 2.7, 3.3 and 3.4
61+
pyapi-gitlab supports python version 2.7, 3.3, 3.4, 3.5, 3.5-dev, 3.6, 3.6-dev, 3.7-dev, and the nightly build
3562

3663

3764
# Versions tested

docker/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
3+
from gitlab import Gitlab
4+
5+
host = os.environ.get('gitlab_host', 'http://gitlab:80')
6+
user = os.environ.get('gitlab_user', 'root')
7+
password = os.environ.get('gitlab_password', '5iveL!fe')
8+
9+
gitlab = Gitlab(host=host, verify_ssl=False)
10+
11+
gitlab_responding = False
12+
while not gitlab_responding:
13+
try:
14+
response = gitlab.login(user=user, password=password)
15+
gitlab_responding = True
16+
except:
17+
pass
18+
19+
exit(0)

docker/gitlab_v91/docker-compose.yml

Lines changed: 0 additions & 150 deletions
This file was deleted.

docker/v93/docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "2"
2+
3+
services:
4+
sut:
5+
build: ../../.
6+
links:
7+
- gitlab
8+
depends_on:
9+
- "gitlab"
10+
11+
gitlab:
12+
image: gitlab/gitlab-ce
13+
expose:
14+
- "80"
15+
environment:
16+
GITLAB_OMNIBUS_CONFIG: gitlab_rails['initial_root_password'] = "5iveL!fe"
17+
logging:
18+
driver: none

gitlab/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
by Itxaka Serrano Garcia <itxakaserrano@gmail.com>
55
Check the license on the LICENSE file
66
"""
7-
from json import JSONDecodeError
8-
97
import requests
108

119
from . import exceptions
@@ -158,7 +156,7 @@ def success_or_raise(self, response, default_response=None):
158156

159157
try:
160158
response_json = response.json()
161-
except JSONDecodeError:
159+
except ValueError:
162160
pass
163161

164162
return response_json

gitlab_tests/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class BaseTest(unittest.TestCase):
1010
@responses.activate
1111
def setUp(self):
1212
self.user = os.environ.get('gitlab_user', 'root')
13-
self.password = os.environ.get('gitlab_password', '1WmA1a3ONs9F')
13+
self.password = os.environ.get('gitlab_password', '5iveL!fe')
1414
self.host = os.environ.get('gitlab_host', 'http://localhost:10080')
1515
self.gitlab = Gitlab(host=self.host, verify_ssl=False)
1616
self.gitlab.host = self.host

gitlab_tests/test_v91/test_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from unittest import mock
1+
from mock import Mock
22

33
import requests
44
import responses
@@ -12,7 +12,7 @@
1212

1313
class TestSuccessOrRaise(BaseTest):
1414
def test_success_or_raise_without_error(self):
15-
response = mock.MagicMock()
15+
response = Mock()
1616
response_config = {
1717
'status_code': 200,
1818
'json.return_value': post_users_error

gitlab_tests/test_v91/test_users.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import os
2-
from unittest import TestCase
3-
41
import responses
52
from requests.exceptions import HTTPError
63

integration_cov

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/usr/bin/env bash
2-
coverage run -m unittest discover -s integration_tests.tests_$1 && coverage html
2+
/usr/local/bin/python -m docker
3+
coverage run -m unittest discover -s integration_tests.tests_v93 && coverage html

integration_tests/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77

88
def log_to_term(var_name, response):
9-
print('\r\r{}: {}\r\r'.format(var_name, response))
9+
print('\r\r', var_name, ':', response, '\r\r')
1010

1111

1212
class BaseTest(TestCase):
1313
def setUp(self):
1414
self.user = os.environ.get('gitlab_user', 'root')
15-
self.password = os.environ.get('gitlab_password', '1WmA1a3ONs9F')
16-
self.host = os.environ.get('gitlab_host', 'http://localhost:10080')
15+
self.password = os.environ.get('gitlab_password', '5iveL!fe')
16+
self.host = os.environ.get('gitlab_host', 'http://gitlab:80')
17+
1718
self.gitlab = Gitlab(host=self.host, verify_ssl=False)
1819

1920
self.gitlab.login(user=self.user, password=self.password)

0 commit comments

Comments
 (0)