Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing coverage #5109

Merged
merged 2 commits into from
Nov 21, 2018
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
40 changes: 40 additions & 0 deletions tests/unit/test_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,46 @@ def test_creates(self, monkeypatch):
pretend.call("/manifest.json", "/static/")
]

def test_whitenoise_serve_static(self):
config = pretend.stub(
action=pretend.call_recorder(lambda t, f: f()),
registry=pretend.stub(settings={}),
)
kwargs = {"foo": "bar"}

static.whitenoise_serve_static(config, **kwargs)

assert config.registry.settings["whitenoise"] == kwargs
assert len(config.action.calls) == 1

def test_whitenoise_add_files(self):
config = pretend.stub(
action=pretend.call_recorder(lambda t, f: f()),
registry=pretend.stub(settings={}),
)
path = pretend.stub()
prefix = pretend.stub()

static.whitenoise_add_files(config, path, prefix)

assert config.registry.settings["whitenoise.files"] == [
(path, {"prefix": prefix})
]
assert len(config.action.calls) == 1

def test_whitenoise_add_manifest(self):
config = pretend.stub(
action=pretend.call_recorder(lambda t, f: f()),
registry=pretend.stub(settings={}),
)
manifest = pretend.stub()
prefix = pretend.stub()

static.whitenoise_add_manifest(config, manifest, prefix)

assert config.registry.settings["whitenoise.manifests"] == [(manifest, prefix)]
assert len(config.action.calls) == 1


def test_includeme():
config = pretend.stub(
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,36 @@ def test_without_a_query(self, monkeypatch, db_request, metrics, page):
pretend.call("warehouse.views.search.results", 1000)
]

@pytest.mark.parametrize(
"created,expected",
[
(
"2018-11-21T12:42:47.490593",
datetime.datetime(2018, 11, 21, 12, 42, 47, 490593),
),
("2018-11-21T12:42:47", datetime.datetime(2018, 11, 21, 12, 42, 47)),
],
)
def test_item_created_casting(self, db_request, created, expected, monkeypatch):
es_query = pretend.stub()
db_request.es = pretend.stub(query=lambda *a, **kw: es_query)
db_request.params = MultiDict()

page_obj = pretend.stub(
page_count=1, item_count=1, items=[pretend.stub(created=created)]
)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)

assert search(db_request) == {
"page": page_obj,
"term": "",
"order": "",
"applied_filters": [],
"available_filters": [],
}
assert page_obj.items[0].created == expected

def test_returns_404_with_pagenum_too_high(self, monkeypatch, db_request, metrics):
params = MultiDict({"page": 15})
db_request.params = params
Expand Down