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

Live tests, added missing features #54

Merged
merged 1 commit into from
Aug 20, 2019

Conversation

jasmingacic
Copy link
Contributor

@jasmingacic jasmingacic commented Aug 6, 2019

live tests for:

  • batches,
  • devices,
  • emails,
  • events,
  • ips
  • organizations,
  • ports,
  • vlans,
  • volumes and
  • VPN

Some of the features from the list were added to the SDK.


This change is Reviewable

@jasmingacic
Copy link
Contributor Author

Updated docs are going to be added here as well.

tox.ini Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
packet/BGPConfig.py Show resolved Hide resolved
@@ -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"]

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jasmingacic
Copy link
Contributor Author

@t0mk The README still needs some work to be done. So we are going to revisit it again.

@t0mk
Copy link
Contributor

t0mk commented Aug 9, 2019

@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.
I am trying to see how it would be most useful for a user, and now that you're looking at packet-python, it's good time to improve it.

Feel free to give feedback on my code comments.

I will test some of the code today.

Copy link
Contributor

@t0mk t0mk left a 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.

@classmethod
def setUpClass(self):
self.manager = packet.Manager(auth_token=os.environ['PACKET_AUTH_TOKEN'])
self.projectId = self.manager.list_projects()[0].id
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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")

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good

test/test_ips.py Show resolved Hide resolved
test/test_ips.py Outdated
def test_create_device_ip(self):
ip = None
params = {
"include": ["facility"]
Copy link
Contributor

@t0mk t0mk Aug 14, 2019

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

Copy link
Contributor

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.

"tags": tags
}

data = self.call_api("/projects/%s/ips" % project_id, params=request)
Copy link
Contributor

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.

Copy link
Contributor

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")
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed

@jasmingacic
Copy link
Contributor Author

@t0mk are we good to merge this?

@amenowanna amenowanna requested a review from mattcburns August 16, 2019 16:01
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"]
Copy link
Collaborator

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.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Refactored. Nice catch @mattcburns

@t0mk
Copy link
Contributor

t0mk commented Aug 18, 2019

Yeah, looks OK. Feel free to merge.

…ts, ips, organizations, ports, vlans, volumes and VPN
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