Skip to content

Commit d9ed82c

Browse files
Merge pull request #334 from julienbourdeau/feat/build-community-PRs
Build community PRs
2 parents a5d4780 + edfafc0 commit d9ed82c

File tree

8 files changed

+73
-20
lines changed

8 files changed

+73
-20
lines changed

.travis.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1+
language: python
2+
13
branches:
24
only:
35
- master
46

57
sudo: false
68

9+
python:
10+
- "2.7"
11+
- "3.4"
12+
- "3.5"
13+
- "3.6"
14+
715
before_script:
816
- wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.27.zip
917
- unzip -q google_appengine_1.9.27.zip
18+
- wget https://alg.li/algolia-keys && chmod +x algolia-keys
1019

1120
install:
1221
- pip install --upgrade pip
1322
- if [[ $TOXENV == 'py32' ]]; then pip install -I 'virtualenv<14.0'; fi
1423
- pip install tox-travis
1524

1625
script:
17-
- tox
18-
19-
language: python
20-
21-
python:
22-
- "2.7"
23-
- "3.4"
24-
- "3.5"
25-
- "3.6"
26+
- if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [[ ! "$TRAVIS_PULL_REQUEST_SLUG" =~ ^algolia\/ ]]; then eval $(./algolia-keys export) tox; else tox; fi

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@pytest.fixture
88
def mcm_client():
9-
return create_client('ALGOLIA_APPLICATION_ID_MCM', 'ALGOLIA_API_KEY_MCM')
9+
return create_client('ALGOLIA_APP_ID_MCM', 'ALGOLIA_API_KEY_MCM')
1010

1111

1212
@pytest.fixture

tests/helpers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ def check_credentials():
1010
credentials = [
1111
'ALGOLIA_APPLICATION_ID',
1212
'ALGOLIA_API_KEY',
13-
'ALGOLIA_API_KEY_SEARCH',
14-
'ALGOLIA_APPLICATION_ID_MCM',
13+
'ALGOLIA_SEARCH_API_KEY',
14+
'ALGOLIA_APP_ID_MCM',
1515
'ALGOLIA_API_KEY_MCM'
1616
]
1717

1818
for credential in credentials:
1919
if credential not in os.environ:
20-
print('environement variable {} not defined'.format(credential))
20+
print('environment variable {} not defined'.format(credential))
2121
assert False
2222

2323

24+
is_community = 'IS_COMMUNITY' in os.environ
25+
26+
2427
def index_name():
2528
name = 'algolia-python{}'.format(randint(1, 100000))
2629

2730
if 'TRAVIS' in os.environ:
28-
name = '{}_travis-{}'.format(name, os.environ['TRAVIS_JOB_NUMBER'])
31+
name = 'TRAVIS_PYTHON_{}_id-{}'.format(name, os.environ['TRAVIS_JOB_NUMBER'])
2932

3033
return name
3134

tests/test_MCM.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
from __future__ import unicode_literals
22
import os
33
import time
4+
import pytest
45
from algoliasearch.helpers import PY2
6+
from .helpers import is_community
57

68
STR_TYPE = unicode if PY2 else str
79

810

11+
@pytest.mark.skipif(is_community,
12+
reason='MCM methods cannot be tested by the community')
913
def uniq_user_id():
1014
name = 'python-client'
1115
if 'TRAVIS' not in os.environ:
@@ -14,6 +18,8 @@ def uniq_user_id():
1418
return '{}-travis-{}'.format(name, job)
1519

1620

21+
@pytest.mark.skipif(is_community,
22+
reason='MCM methods cannot be tested by the community')
1723
def test_1_list_clusters(mcm_client):
1824
answer = mcm_client.list_clusters()
1925

@@ -26,6 +32,8 @@ def test_1_list_clusters(mcm_client):
2632
assert isinstance(answer['clusters'][0]['dataSize'], int)
2733

2834

35+
@pytest.mark.skipif(is_community,
36+
reason='MCM methods cannot be tested by the community')
2937
def test_2_assign_user_id(mcm_client):
3038
name = mcm_client.list_clusters()['clusters'][0]['clusterName']
3139
answer = mcm_client.assign_user_id(uniq_user_id(), name)
@@ -36,6 +44,8 @@ def test_2_assign_user_id(mcm_client):
3644
time.sleep(2) # Sleep to let the cluster publish the change
3745

3846

47+
@pytest.mark.skipif(is_community,
48+
reason='MCM methods cannot be tested by the community')
3949
def test_3_list_user_ids(mcm_client):
4050
answer = mcm_client.list_user_ids()
4151

@@ -48,6 +58,8 @@ def test_3_list_user_ids(mcm_client):
4858
assert isinstance(answer['userIDs'][0]['dataSize'], int)
4959

5060

61+
@pytest.mark.skipif(is_community,
62+
reason='MCM methods cannot be tested by the community')
5163
def test_4_get_top_user_id(mcm_client):
5264
cluster_name = mcm_client.list_clusters()['clusters'][0]['clusterName']
5365
answer = mcm_client.get_top_user_id()
@@ -60,6 +72,9 @@ def test_4_get_top_user_id(mcm_client):
6072
assert isinstance(answer['topUsers'][cluster_name][0]['nbRecords'], int)
6173
assert isinstance(answer['topUsers'][cluster_name][0]['dataSize'], int)
6274

75+
76+
@pytest.mark.skipif(is_community,
77+
reason='MCM methods cannot be tested by the community')
6378
def test_5_get_user_id(mcm_client):
6479
answer = mcm_client.get_user_id(uniq_user_id())
6580

@@ -69,6 +84,9 @@ def test_5_get_user_id(mcm_client):
6984
assert isinstance(answer['nbRecords'], int)
7085
assert isinstance(answer['dataSize'], int)
7186

87+
88+
@pytest.mark.skipif(is_community,
89+
reason='MCM methods cannot be tested by the community')
7290
def test_6_search_user_ids(mcm_client):
7391
clusterName = mcm_client.list_clusters()['clusters'][0]['clusterName']
7492
answer = mcm_client.search_user_ids(uniq_user_id(), clusterName, 0, 1000)
@@ -85,6 +103,9 @@ def test_6_search_user_ids(mcm_client):
85103
assert isinstance(answer['hits'][0]['nbRecords'], int)
86104
assert isinstance(answer['hits'][0]['dataSize'], int)
87105

106+
107+
@pytest.mark.skipif(is_community,
108+
reason='MCM methods cannot be tested by the community')
88109
def test_7_remove_user_id(mcm_client):
89110
answer = mcm_client.remove_user_id(uniq_user_id())
90111

tests/test_compat.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from .helpers import wait_key, wait_missing_key
1+
from .helpers import wait_key, wait_missing_key, is_community
2+
import pytest
3+
24

35
def test_addObject(index):
46
task = index.addObject({'name': 'Paris'}, 'a')
@@ -131,6 +133,8 @@ def test_deleteByQuery(rw_index):
131133
assert res['nbHits'] < 5
132134

133135

136+
@pytest.mark.skipif(is_community,
137+
reason='API keys methods cannot be tested by the community')
134138
def test_user_key(rw_index):
135139
new_key = rw_index.addUserKey(['search'])
136140
wait_key(rw_index, new_key['key'])

tests/test_index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ def test_search_with_short_secured_api_key(ro_index):
436436

437437
try:
438438
secured_api_key = ro_index.client.generate_secured_api_key(
439-
os.environ['ALGOLIA_API_KEY_SEARCH'],
439+
os.environ['ALGOLIA_SEARCH_API_KEY'],
440440
dict(filters=''),
441441
)
442442
except:
443-
raise RuntimeError("ALGOLIA_API_KEY_SEARCH must be set")
443+
raise RuntimeError("ALGOLIA_SEARCH_API_KEY must be set")
444444

445445
assert len(secured_api_key) < MAX_API_KEY_LENGTH
446446

@@ -456,11 +456,11 @@ def test_search_with_long_secured_api_key(ro_index):
456456
tags = set('x{0}'.format(100000 + i) for i in range(1000))
457457
try:
458458
secured_api_key = ro_index.client.generate_secured_api_key(
459-
os.environ['ALGOLIA_API_KEY_SEARCH'],
459+
os.environ['ALGOLIA_SEARCH_API_KEY'],
460460
dict(filters=' OR '.join(tags)),
461461
)
462462
except:
463-
raise RuntimeError("ALGOLIA_API_KEY_SEARCH must be set")
463+
raise RuntimeError("ALGOLIA_SEARCH_API_KEY must be set")
464464

465465
assert len(secured_api_key) > MAX_API_KEY_LENGTH
466466
ro_index.client.api_key = secured_api_key

tests/test_keys.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
from .helpers import is_community
2+
import pytest
13
from .helpers import wait_key, wait_missing_key
24

35

6+
@pytest.mark.skipif(is_community,
7+
reason='API keys methods cannot be tested by the community')
48
def test_list_user_keys(client):
59
res = client.list_user_keys()
610
assert 'keys' in res
711

812

13+
@pytest.mark.skipif(is_community,
14+
reason='API keys methods cannot be tested by the community')
915
def test_add_user_keys(client):
1016
keys = []
1117

@@ -28,6 +34,8 @@ def test_add_user_keys(client):
2834
client.delete_user_key(key)
2935

3036

37+
@pytest.mark.skipif(is_community,
38+
reason='API keys methods cannot be tested by the community')
3139
def test_get_user_key(client):
3240
res = client.add_user_key(['search'])
3341
key = res['key']
@@ -40,6 +48,8 @@ def test_get_user_key(client):
4048
client.delete_user_key(key)
4149

4250

51+
@pytest.mark.skipif(is_community,
52+
reason='API keys methods cannot be tested by the community')
4353
def test_update_user_keys(client):
4454
keys = []
4555

@@ -81,6 +91,8 @@ def test_update_user_keys(client):
8191
for key in keys:
8292
client.delete_user_key(key)
8393

94+
@pytest.mark.skipif(is_community,
95+
reason='API keys methods cannot be tested by the community')
8496
def test_delete_user_keys(client):
8597
res = client.add_user_key(['search'])
8698
key = res['key']
@@ -94,11 +106,15 @@ def test_delete_user_keys(client):
94106
assert key not in res_keys
95107

96108

109+
@pytest.mark.skipif(is_community,
110+
reason='API keys methods cannot be tested by the community')
97111
def test_index_list_user_keys(ro_index):
98112
res = ro_index.list_user_keys()
99113
assert 'keys' in res
100114

101115

116+
@pytest.mark.skipif(is_community,
117+
reason='API keys methods cannot be tested by the community')
102118
def test_index_add_user_keys(index):
103119
keys = []
104120

@@ -121,6 +137,8 @@ def test_index_add_user_keys(index):
121137
index.delete_user_key(key)
122138

123139

140+
@pytest.mark.skipif(is_community,
141+
reason='API keys methods cannot be tested by the community')
124142
def test_index_get_user_key(index):
125143
res = index.add_user_key(['search'])
126144
key = res['key']
@@ -133,6 +151,8 @@ def test_index_get_user_key(index):
133151
index.delete_user_key(key)
134152

135153

154+
@pytest.mark.skipif(is_community,
155+
reason='API keys methods cannot be tested by the community')
136156
def test_index_update_user_keys(index):
137157
keys = []
138158

@@ -175,6 +195,8 @@ def test_index_update_user_keys(index):
175195
index.delete_user_key(key)
176196

177197

198+
@pytest.mark.skipif(is_community,
199+
reason='API keys methods cannot be tested by the community')
178200
def test_index_delete_user_keys(index):
179201
res = index.add_user_key(['search'])
180202
key = res['key']

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ passenv =
1919
ALGOLIA*
2020
APPENGINE*
2121
TRAVIS*
22-
22+
IS_COMMUNITY
2323
commands = pytest tests
2424

2525
# Appengine settings.
@@ -40,6 +40,7 @@ deps =
4040
passenv =
4141
ALGOLIA*
4242
TRAVIS*
43+
IS_COMMUNITY
4344
commands =
4445
coverage run --branch --source=algoliasearch -m pytest tests
4546
coverage report
@@ -56,6 +57,7 @@ deps =
5657
passenv =
5758
ALGOLIA*
5859
TRAVIS*
60+
IS_COMMUNITY
5961
commands =
6062
coverage run --branch --source=algoliasearch -m pytest tests
6163
coverage report

0 commit comments

Comments
 (0)