Skip to content

Commit 6821987

Browse files
committed
Update test_models.py
1 parent d59078c commit 6821987

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: python
2+
python:
3+
- "3.7"
4+
install:
5+
- pipenv install --dev
6+
script:
7+
- pipenv run pytest

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ verify_ssl = true
55

66
[dev-packages]
77
pytest = "*"
8+
requests-mock = "*"
89

910
[packages]
1011
requests = "*"
1112
structlog = "*"
13+
attr = "*"
1214

1315
[requires]
1416
python_version = "3.7"

Pipfile.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_models.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import attr
12
import pytest
23
import requests_mock
34

@@ -6,13 +7,25 @@
67

78
@pytest.fixture
89
def client():
9-
pass
10+
with requests_mock.Mocker() as m:
11+
uri1 = 'mock://example.com/rest/login'
12+
uri2 = 'mock://example.com/rest/status'
13+
cookies = {'JSESSIONID': '11111111'}
14+
json_object = {'fullname': 'User Name'}
15+
m.post(uri1, cookies=cookies)
16+
m.get(uri2, json=json_object)
17+
client = models.Client('mock://example.com', 'test', 'test')
18+
return client
1019

1120

12-
# def test_get_record(client):
13-
# """Test get_record function."""
14-
# rec_obj = client.get_record(uuid, rec_type)
15-
# assert False
21+
def test_get_record(client):
22+
"""Test get_record function."""
23+
with requests_mock.Mocker() as m:
24+
uri = '/rest/items/123?expand=all'
25+
json_object = {'metadata': {'title': 'Sample title'}, 'type': 'item'}
26+
m.get(uri, json=json_object)
27+
rec_obj = client.get_record('123', 'items')
28+
assert attr.asdict(rec_obj)['metadata'] == json_object['metadata']
1629

1730

1831
# def test_filtered_item_search(client):

0 commit comments

Comments
 (0)