-
Notifications
You must be signed in to change notification settings - Fork 50
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
Live tests, added missing features #54
Conversation
Updated docs are going to be added here as well. |
@@ -244,3 +259,376 @@ def validate_capacity(self, servers): | |||
def get_spot_market_prices(self, params={}): | |||
data = self.call_api("/market/spot/prices", params=params) | |||
return data["spot_market_prices"] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of new functionality that works only in theory. An API SDK should contain Integration tests, at least for the most common use-cases. I mean tests that call the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/TheAntColony/packet-python/blob/master/test/test_device.py#L40-L47
We tried to test where it was possible. BGP Configs were not tested, so we can either leave them or remove them.
@t0mk The README still needs some work to be done. So we are going to revisit it again. |
@jasmingacic alright. I know that the original README has not been updated for a long time, and most of my comments address issues from the original format. Feel free to give feedback on my code comments. I will test some of the code today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to run the tests, but they were creating resources in my project and organization. Project and Org for test should be created and destroyed after test. See comments.
test/test_device.py
Outdated
@classmethod | ||
def setUpClass(self): | ||
self.manager = packet.Manager(auth_token=os.environ['PACKET_AUTH_TOKEN']) | ||
self.projectId = self.manager.list_projects()[0].id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking first project for tests will not do. You should create a temporary project and create test resources in it. In this case, the project should have BGP enabled.
This goes for all the resource tests which create project-owned resource.
The test project then should be destroyed at test tearDown, no matter if test succeeds or not.
You canb use setUp and tearDown() from python unittest:
https://docs.python.org/2/library/unittest.html#unittest.TestCase.setUp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests have been updated. Each test that requires a project resources creates a new project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, it looks good. One more nitpick, could you please remove
datetime.utcnow().timestamp()
..from the test scripts? It doesn't work in Python2.7. The rest of the library works OK in both 2.7 and 3.x. Maybe replace it with something like:
datetime.utcnow().strftime("%Y%m%dT%H%M%S")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved
def setUpClass(self): | ||
self.manager = packet.Manager(auth_token=os.environ['PACKET_AUTH_TOKEN']) | ||
orgs = self.manager.list_organizations() | ||
self.org_id = orgs[0].id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think tests should not taint existing resoruce. Don't just use user's first organization. Rather create one in setUp and remove it in tearDown. Create test projects under the test organization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, the tests should use dedicated resources, including the organization. However, POST /organizations
, as well as the integration test, are not implemented due to inability to provide a valid payment method. We can see the following message in the UI when creating a new organization:
We will temporarily place an authorization request on your credit card for $1.
The charge will be removed within 5 business days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
6f91aa0
to
304ea48
Compare
test/test_ips.py
Outdated
def test_create_device_ip(self): | ||
ip = None | ||
params = { | ||
"include": ["facility"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include
param should be a comma-separated string: https://www.packet.com/developers/api/#common-parameters
If you pass it like this, it will go to the GET as
GET /projects/cc99d24b-f23e-43e2-867e-275918dddcf3/ips?include=['facility']
It should be
GET /projects/cc99d24b-f23e-43e2-867e-275918dddcf3/ips?include=facility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test has been updated.
packet/Manager.py
Outdated
"tags": tags | ||
} | ||
|
||
data = self.call_api("/projects/%s/ips" % project_id, params=request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be type=POST
. Otherwise this does GET and reads something useless from the API. Even worse, the method call succeeds, and the IP is not reserved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
test/test_ips.py
Outdated
cls.manager.reserve_ip_address(project_id=cls.project.id, | ||
type="global_ipv4", | ||
quantity=1, | ||
facility="ewr1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please veify somehow that the global IP address is created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use public_ipv4
instead of global_ipv4
. public_ipv4
contains a broader IP address range.
test/test_ips.py
Outdated
for i in ips: | ||
if i.facility.code == "ewr1" \ | ||
and i.address_family == 4: | ||
ip = i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than lookup for an IP, please refer to the IP address allocated in the setUpClass method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@t0mk are we good to merge this? |
packet/Device.py
Outdated
self.created_at = data["created_at"] | ||
self.updated_at = data["updated_at"] | ||
if "ipxe_script_url" in data: | ||
self.ipxe_script_url = data["ipxe_script_url"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be tightened up to be self.ipxe_script_url = data.get("ipxe_script_url", None)
(this goes for the other if/else being done like this.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored. Nice catch @mattcburns
Yeah, looks OK. Feel free to merge. |
37f5916
to
e8802ce
Compare
…ts, ips, organizations, ports, vlans, volumes and VPN
e8802ce
to
ef0db65
Compare
live tests for:
Some of the features from the list were added to the SDK.
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)