Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ language: python
python:
- '2.7'
- '3.4'
- '3.5'

install:
- pip install -r dev-requirements.txt
- pip install coveralls
- pip install .

before_script: flake8 .

Expand All @@ -22,5 +24,5 @@ deploy:
secure: BCZHAzhDczjcyvLuCu5PnooHIgiIl72VChERUVfkNCvyD3MePIx/+ZVvaoOAyy4NkidDc472+OnqPKlxcU/xiEfUXCfs9eFo1XqWM09XfFH10fMB1zbJ2VtHPa3plpZLIQBBH1fwaEBlvhEMnVPfbCPce+g4VqZlJbijDYk4avElK2jqORPtN8qgDviVSniq6RRb9eqf6NXDbwdtvxuDvj7pl5+uPw14Dmnig19vzDGPQxDPXhPjeDi+cnQ19EautJqXfC4tuyEMEKZ6k6AWlSKAou+btAQyh84I68ah73to7RcFiMIWbEk1fyxHMI+hBrpsK9xP3GWLgxqXXr7c7TYkp7YlaHQqYrTM0xbD4M34C8B7xgTe45siHTSbgDFncO5l25CVTjjr59tBtax8PhzOcsn58S6ETekQKtz2prAiXg1QMrFFmjrE7pvYzdcXGenNxP4Ka+4Q3ifZtmmMWNfsZpFuxu6m6C4kI0FiPRhG5ti3+5GnkLxljtb1g95zXYmx1q6x4sHml8dTZLBdCufjjJK/khHF4NHw9uRsLgT3Nbr+Qh+21hGBL0V8U51Z+eKHyT6ecvwpxBxWDUMjuIsW3+RjWfseoemoSHyyNs3V3dzeOZ0+ftyLUa5yOl7CsmmkVCa4+igdJP8Mjt1siQyGSvt2+SENJtJ8iNIY4Oc=
on:
tags: true
repo: fabianvf/sharepa
repo: CenterForOpenScience/sharepa
branch: master
3 changes: 1 addition & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
ipython==3.1.0
ipdb==0.8.1
pytest==2.7.1
pytest==2.9.2
pytest-cov==1.8.1
mock==1.0.1
vcrpy==1.5.2
flake8==2.4.1
-r requirements.txt
9 changes: 9 additions & 0 deletions tests/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
import sys

PY2 = int(sys.version_info[0]) == 2

if PY2:
text_type = unicode
else:
text_type = str
3 changes: 2 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import vcr
import pandas
import pytest
import numpy

from sharepa.search import ShareSearch
from sharepa.helpers import pretty_print
Expand All @@ -22,4 +23,4 @@ def test_pretty_print():
def test_source_counts():
all_counts = source_counts()
assert isinstance(all_counts, pandas.core.frame.DataFrame)
assert all_counts.count().values[0] == 42
assert type(all_counts.count().values[0]) is numpy.int64
17 changes: 8 additions & 9 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from sharepa.search import ShareSearch
from sharepa.search import basic_search
from .compat import text_type


@vcr.use_cassette('tests/vcr/basic_search_one.yaml')
Expand All @@ -23,7 +24,7 @@ def test_no_title_search():
)
results = my_search.execute()
for result in results:
assert not result.get('title')
assert result.title is None


@vcr.use_cassette('tests/vcr/simple_execute.yaml')
Expand All @@ -33,15 +34,14 @@ def test_execute():
first_result = result.hits[0].to_dict()

assert len(result.hits) == 10
assert isinstance(result, elasticsearch_dsl.result.Response)
assert first_result['title'] == 'Avian community structure and incidence of human West Nile infection'
assert type(result) is elasticsearch_dsl.result.Response
assert type(first_result['title']) is text_type


@vcr.use_cassette('tests/vcr/basic_search.yaml')
def test_count():
count = basic_search.count()
assert isinstance(count, int)
assert count == 1048895
assert type(count) is int


def test_query():
Expand All @@ -53,9 +53,8 @@ def test_scan():
my_search = ShareSearch()
my_search = my_search.query(
'query_string',
query='squared AND circle'
query='squared'
)
scan = my_search.scan()
scan_list = [item for item in scan]
assert len(scan_list) == 3
assert scan_list[0].title == '<p>The ellipsoids in the figure are isolines of constant density of bivariate Gaussian distributions.</p>'
scan_list = list(scan)
assert type(scan_list[0].title) is text_type
29 changes: 19 additions & 10 deletions tests/vcr/basic_search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@ interactions:
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['28']
User-Agent: [python-requests/2.7.0 CPython/2.7.9 Darwin/13.4.0]
User-Agent: [python-requests/2.10.0]
content-type: [application/json]
method: POST
uri: https://osf.io/api/v1/share/search/?count=True
uri: https://staging-share.osf.io/api/search/abstractcreativework/_search?size=0
response:
body: {string: !!python/unicode '{"count": 1048895, "results": [], "time": 0.02}'}
body:
string: !!binary |
H4sIAAAAAAAAAzzLwQqDMBCE4XeZcygBtYd9lSJhSTYYGgm4GxDEd2+t0NPM4fsPBF14Swo6oD1G
Uc29giYHa8b3y1yqJJA/HZZiP3zva/678Tl57x1W3oPGtsnXP67CyioptG6gzFXlKtobNJwfAAAA
//8DAFjAxGV+AAAA
headers:
connection: [close]
content-length: ['47']
content-type: [application/json; charset=utf-8]
date: ['Wed, 17 Jun 2015 19:37:47 GMT']
server: [nginx/1.4.6 (Ubuntu)]
set-cookie: [NB_SRVID=srv25533; path=/]
x-sentry-id: [None]
Allow: ['GET, POST, HEAD, OPTIONS']
Cache-Control: ['no-cache, no-store, max-age=0, must-revalidate']
Connection: [keep-alive]
Content-Encoding: [gzip]
Content-Type: [application/json]
Date: ['Mon, 11 Jul 2016 19:10:30 GMT']
Expires: ['Mon, 01 Jan 1990 00:00:00 GMT']
Pragma: [no-cache]
Server: [nginx/1.11.1]
Strict-Transport-Security: [max-age=15724800; includeSubDomains; preload]
Vary: ['Accept, Cookie']
X-Frame-Options: [SAMEORIGIN]
status: {code: 200, message: OK}
version: 1
Loading