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 PDCClient tests #137

Merged
merged 1 commit into from
Nov 14, 2017
Merged

Conversation

hluk
Copy link
Contributor

@hluk hluk commented Oct 25, 2017

No description provided.

@hluk hluk requested review from simozhan and xiangge October 25, 2017 14:39
@hluk hluk force-pushed the api_tests branch 3 times, most recently from 7f5ff35 to ee581f1 Compare October 25, 2017 15:14
@hluk
Copy link
Contributor Author

hluk commented Oct 25, 2017

Keeping compatibility with Python 2.6 sucks - still have to fix some tests.

@xiangge
Copy link
Contributor

xiangge commented Oct 26, 2017

Yes, I think we can consider to remove the 2.6 test in the future and add update the 3.3 to 3.5.

  1. And also I think in the case we should include the attr "_" to add a "/" in the end of the uri.
  2. And we should also add the getitem way in each of the test function, like client["cpes"].

@hluk hluk force-pushed the api_tests branch 2 times, most recently from cc0b57c to 7522947 Compare October 26, 2017 12:32
@hluk
Copy link
Contributor Author

hluk commented Oct 26, 2017

While adding tests for rest of the API I found few issues. Fixes are included.

  1. And also I think in the case we should include the attr "_" to add a "/" in the end of the uri.

Added.

  1. And we should also add the getitem way in each of the test function, like client["cpes"].

This is already tested on few places. I want to have simple and small test methods for testing just specific part of API.

@hugovk
Copy link

hugovk commented Oct 26, 2017

Here's the pip installs for pdc-client from PyPI for the last month -- a single 2.6 and no 3.3 (both are EOL):

$ pypinfo --percent --pip pdc-client pyversion
python_version percent download_count
-------------- ------- --------------
2.7              63.9%            991
3.6              20.6%            319
3.5              12.5%            194
3.4               2.9%             45
2.6               0.1%              1

By the way, you could add both 3.5 and 3.6 to Travis etc. More reasons for dropping old ones:

2.6

3.2

  • (Already dropped! :)

3.3

"description": "RHEL 7 Workstation",
"id": 1
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the cpe returned data in our product something like below one?
[
{
"id": 1,
"cpe": "cpe:test",
"description": "1234"
}
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mocked server returns paged response when making GET HTTP request to rest_api/v1/cpe/.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the data is like the data in db, got that, thx.

def test_set_comment(self):
self.client.set_comment('TEST')
self.client.cpes[1] += {'description': 'TEST'}
self.assertEqual(_MockPDCServerRequestHandler.last_comment, 'TEST')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we should also add the getitem way in each of the test function, like client["cpes"].

This is already tested on few places. I want to have simple and small test methods for testing just specific part of API.

I think we can add codes here to test patch as item, not mean add more test functions.

 self.client['cpes'][1] += {'description': 'TEST1'}
 self.assertEqual(_MockPDCServerRequestHandler.last_comment, 'TEST1')

Maybe you mean self.client.cpes[1] is the case that gets resource by item "[1]"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll add that. Also patching using += for attribute would be nice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

@xiangge
Copy link
Contributor

xiangge commented Nov 9, 2017

I just found I keep the comment there for several days, but not submit it,sorry about that...
Why github always let me submit again after I give comment ...

Copy link
Contributor

@simozhan simozhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice patch. Just one minor thing related to the test case

ssl_verify=False,
)

def test_request_response(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand this case. Is this testing the Mock server setup correctly? I think other cases already cover this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll remove it. It was the first test just to verify the server is running.

@hluk
Copy link
Contributor Author

hluk commented Nov 13, 2017

I simplified the server code a lot (no regexps and should be easier to modify).

I also added few more tests for PUT and PATCH.

@hluk
Copy link
Contributor Author

hluk commented Nov 13, 2017

@@ -361,17 +369,14 @@ def worker():
response = self.client(*args, **kwargs)
if isinstance(response, list):
yield response
else:
elif _is_page(response):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change like this, it seems that when the response is a list, the "while true" seems not break?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Fixed and added test for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

"description": "RHEL 7 Workstation",
"id": 1
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the data is like the data in db, got that, thx.

@simozhan
Copy link
Contributor

Reivewed again. LGTM

Fixes strigifying PDCClient.

Fixes throwing NoResultsError.
@hluk hluk merged commit ae7a04f into product-definition-center:master Nov 14, 2017
@hluk hluk deleted the api_tests branch November 14, 2017 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants