Skip to content

Commit cff72b2

Browse files
authored
Merge pull request #52 from dynata/dev
Release 1.0.3
2 parents ba337d6 + 4cdfe28 commit cff72b2

File tree

13 files changed

+107
-46
lines changed

13 files changed

+107
-46
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[flake8]
2-
exclude=.git,.pytest_cache,venv
2+
exclude=.git,.pytest_cache,.venv,venv

.github/workflows/pythonpackage.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ jobs:
2020
- name: Install dependencies
2121
run: |
2222
python -m pip install --upgrade pip
23-
pip install -r requirements.txt
23+
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py > get-poetry.py
24+
python get-poetry.py --version 1.0.2 -y
25+
$HOME/.poetry/bin/poetry install
26+
rm get-poetry.py
2427
- name: Lint with flake8
2528
run: |
26-
pip install flake8
29+
# activate the virtualenv created by poetry
30+
source .venv/bin/activate
2731
# stop the build if there are Python syntax errors or undefined names
2832
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
2933
# the GitHub editor is 127 chars wide
3034
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
3135
- name: Test with pytest
3236
run: |
33-
pip install pytest
37+
source .venv/bin/activate
3438
pytest

.github/workflows/release.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ jobs:
2020
- name: Install Poetry
2121
run: |
2222
python -m pip install --upgrade pip
23-
pip install poetry
24-
poetry install
23+
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py > get-poetry.py
24+
python get-poetry.py --version 1.0.2 -y
25+
$HOME/.poetry/bin/poetry install
26+
rm get-poetry.py
2527
- name: Poetry - Set Version & Build
2628
run: |
27-
poetry version ${{ steps.get_version.outputs.VERSION }}
28-
poetry build
29+
$HOME/.poetry/bin/poetry version ${{ steps.get_version.outputs.VERSION }}
30+
$HOME/.poetry/bin/poetry build
2931
- name: Push to PyPI
3032
run: |
31-
poetry publish --build --username "${{ secrets.PYPI_USERNAME }}" --password "${{ secrets.PYPI_PASSWORD }}" --no-interaction
33+
$HOME/.poetry/bin/poetry publish --build --username "${{ secrets.PYPI_USERNAME }}" --password "${{ secrets.PYPI_PASSWORD }}" --no-interaction
3234
- name: Create Release
3335
id: create_release
3436
uses: actions/create-release@v1

dynatademand/api.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,33 @@ def get_sources(self):
424424
'get_sources',
425425
)
426426
return self._api_get('/sources')
427+
428+
def reconcile_project(self, project_id, file, message):
429+
'''
430+
Sends a reconciliation request
431+
'''
432+
"""
433+
# Awaiting valid body & path schemas
434+
self.validator.validate_request(
435+
'update_line_item',
436+
path_data={
437+
'extProjectId': '{}'.format(project_id),
438+
},
439+
request_body={
440+
'file': file,
441+
'message': message,
442+
},
443+
)
444+
"""
445+
self._check_authentication()
446+
url = '{}{}'.format(self.base_url, '/projects/{}/reconcile'.format(project_id))
447+
request_headers = {
448+
'Authorization': 'Bearer {}'.format(self._access_token),
449+
'Content-Type': "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
450+
}
451+
response = requests.post(url=url, data=file, headers=request_headers)
452+
if response.status_code > 399:
453+
raise DemandAPIError('Demand API request to {} failed with status {}. Response: {}'.format(
454+
url, response.status_code, response.content
455+
))
456+
return response.json()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"file": {
5+
"type": "file"
6+
},
7+
"message": {
8+
"type": "string"
9+
}
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"extProjectId": {
5+
"type": "string",
6+
"required": true
7+
}
8+
},
9+
"required": [
10+
"extProjectId"
11+
]
12+
}

dynatademand/validator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'update_project': ['path', 'body', ],
1717
'buy_project': ['path', 'body', ],
1818
'get_project_detailed_report': ['path', ],
19+
'reconcile_project': ['path', ],
1920

2021
# Invoices
2122
'get_invoice': ['path', ],

poetry.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[virtualenvs]
2+
create = true
3+
in-project = true

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ name = "dynatademand"
33
version = "1.0.2"
44
description = "A Python client library for the Dynata Demand API"
55
authors = ["Ridley Larsen <Ridley.Larsen@dynata.com>", "Bradley Wogsland <Bradley.Wogsland@dynata.com>", "Nathan Workman <Nathan.Workman@dynata.com>"]
6+
readme = "README.md"
7+
repository = "https://github.com/dynata/python-demandapi-client"
68

79
[tool.poetry.dependencies]
810
python = "^2.7 || ^3.5 || ^3.6 || ^3.7"
11+
requests = "2.22.0"
12+
jsonschema = "3.2.0"
13+
14+
[tool.poetry.dev-dependencies]
915
responses = "0.10.6"
1016
requests = "2.22.0"
1117
pytest = "4.6.6"
1218
jsonschema = "3.2.0"
1319
pytest-runner = "5.2"
14-
15-
[tool.poetry.dev-dependencies]
20+
flake8 = "^3.7.9"
1621

1722
[build-system]
1823
requires = ["poetry>=0.12"]

requirements.txt

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

setup.py

Lines changed: 0 additions & 29 deletions
This file was deleted.
Binary file not shown.

tests/test_projects.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_close_project(self):
108108

109109
@responses.activate
110110
def test_update_project(self):
111-
# Tests creating a project. This also tests validating the project data as part of `api.create_project`.
111+
# Tests updating a project.
112112
with open('./tests/test_files/update_project.json', 'r') as update_project_file:
113113
update_project_data = json.load(update_project_file)
114114

@@ -133,3 +133,30 @@ def test_update_project(self):
133133
with self.assertRaises(DemandAPIError):
134134
self.api.update_project(24, update_project_data)
135135
self.assertEqual(len(responses.calls), 2)
136+
137+
@responses.activate
138+
def test_reconcile_project(self):
139+
# Tests reconciling a project.
140+
message = 'testing reconciliation'
141+
with open('./tests/test_files/Data+Quality+Request+Template.xlsx', 'rb') as file:
142+
# Success response
143+
responses.add(
144+
responses.POST,
145+
'{}/sample/v1/projects/24/reconcile'.format(BASE_HOST),
146+
json={'status': {'message': 'success'}},
147+
status=200)
148+
# Error message included
149+
responses.add(
150+
responses.POST,
151+
'{}/sample/v1/projects/24/reconcile'.format(BASE_HOST),
152+
json={'status': {'message': 'error'}},
153+
status=400)
154+
155+
# Test successful response.
156+
self.api.reconcile_project(24, file, message)
157+
self.assertEqual(len(responses.calls), 1)
158+
159+
# Test response with error included.
160+
with self.assertRaises(DemandAPIError):
161+
self.api.reconcile_project(24, file, message)
162+
self.assertEqual(len(responses.calls), 2)

0 commit comments

Comments
 (0)