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 new membership routes #79

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

Python client library for [VinylDNS](https://www.vinyldns.io/)

This project is a work in progress! If you would like to help us get this where it needs to be,
please reach out to us in [gitter](https://gitter.im/vinyldns/Lobby).

To run, `pip install vinyldns-python` and then:

```python
Expand Down Expand Up @@ -66,7 +63,10 @@ read the [tox docs](https://tox.readthedocs.io/en/latest/index.html).
## Local Development
See the [quickstart](https://github.com/vinyldns/vinyldns/blob/master/README.md#quickstart) in the
VinylDNS api for details on how to start up a local instance of the api in docker. With that
running, you can make requests with the following client details:
running, create a file (ex: test.py) in `src` folder, from where you can make requests with the following client details:
```python
local_client = VinylDNSClient("http://localhost:9000", "okAccessKey", "okSecretKey")
from vinyldns.client import VinylDNSClient

local_client = VinylDNSClient("http://localhost:9000", "UserAccessKey", "UserSecretKey")
local_client.list_zones()
```
16 changes: 14 additions & 2 deletions src/vinyldns/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
from vinyldns.boto_request_signer import BotoRequestSigner

from vinyldns.batch_change import BatchChange, ListBatchChangeSummaries, to_review_json
from vinyldns.membership import Group, ListGroupsResponse, ListGroupChangesResponse, ListMembersResponse, \
ListAdminsResponse
from vinyldns.membership import Group, ListGroupsResponse, GroupChange, ListGroupChangesResponse, \
ListMembersResponse, ListAdminsResponse
from vinyldns.serdes import to_json_string
from vinyldns.zone import ListZonesResponse, ListZoneChangesResponse, Zone, ZoneChange
from vinyldns.record import ListRecordSetsResponse, ListRecordSetChangesResponse, RecordSet, RecordSetChange
Expand Down Expand Up @@ -380,6 +380,18 @@ def list_group_changes(self, group_id, start_from=None, max_items=None, **kwargs

return ListGroupChangesResponse.from_dict(data)

def get_group_change(self, group_change_id, **kwargs):
"""
Get a group change.

:param group_change_id: Id of the group change to get
:return: the group change json
"""
url = urljoin(self.index_url, u'/groups/change/' + group_change_id)
response, data = self.__make_request(url, u'GET', self.headers, **kwargs)

return GroupChange.from_dict(data) if data is not None else None

def connect_zone(self, zone, **kwargs):
"""
Create a new zone with the given name and email.
Expand Down
8 changes: 6 additions & 2 deletions src/vinyldns/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ def from_dict(d):


class GroupChange(object):
def __init__(self, new_group, change_type, user_id, old_group, id, created):
def __init__(self, new_group, change_type, user_id, old_group, id, created, user_name, group_change_message):
self.new_group = new_group
self.change_type = change_type
self.user_id = user_id
self.old_group = old_group
self.id = id
self.created = created
self.user_name = user_name
self.group_change_message = group_change_message

@staticmethod
def from_dict(d):
Expand All @@ -106,7 +108,9 @@ def from_dict(d):
user_id=d['userId'],
old_group=map_option(d.get('oldGroup'), Group.from_dict),
id=d['id'],
created=map_option(d.get('created'), parse_datetime)
created=map_option(d.get('created'), parse_datetime),
user_name=d['userName'],
group_change_message=d['groupChangeMessage']
)


Expand Down
29 changes: 24 additions & 5 deletions tests/test_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ def test_list_group_admins(mocked_responses, vinyldns_client):


def test_list_group_changes(mocked_responses, vinyldns_client):
change1 = GroupChange(sample_group, 'Create', 'user', None, 'id', datetime.datetime.utcnow())
change2 = GroupChange(sample_group2, 'Update', 'user', sample_group, 'id2', datetime.datetime.utcnow())
lgcr = ListGroupChangesResponse([change1, change2], 'start', 'next', 100)
change1 = GroupChange(sample_group, 'Create', 'user', None, 'id', datetime.datetime.utcnow(), 'test200',
'Group Created.')
change2 = GroupChange(sample_group2, 'Update', 'user', sample_group, 'id2', datetime.datetime.utcnow(),
'test200', 'Group name changed to \'ok2\'.')
lgcr = ListGroupChangesResponse([change1, change2], 1, 3, 100)
mocked_responses.add(
responses.GET, 'http://test.com/groups/foo/activity?startFrom=start&maxItems=100',
responses.GET, 'http://test.com/groups/foo/activity?startFrom=1&maxItems=100',
body=to_json_string(lgcr), status=200
)
r = vinyldns_client.list_group_changes('foo', 'start', 100)
r = vinyldns_client.list_group_changes('foo', 1, 100)
assert r.next_id == lgcr.next_id
assert r.start_from == lgcr.start_from
assert r.max_items == lgcr.max_items
Expand All @@ -163,10 +165,27 @@ def test_list_group_changes(mocked_responses, vinyldns_client):
assert l.user_id == r.user_id
assert l.id == r.id
assert l.created == r.created
assert l.user_name == r.user_name
assert l.group_change_message == r.group_change_message
check_groups_are_same(l.new_group, r.new_group)
check_groups_are_same(l.old_group, r.old_group)


def test_get_group_change(mocked_responses, vinyldns_client):
change = GroupChange(sample_group, 'Create', 'user', None, 'id', datetime.datetime.utcnow(),
'test200', 'Group Created.')
mocked_responses.add(
responses.GET, 'http://test.com/groups/change/123',
body=to_json_string(change), status=200)
r = vinyldns_client.get_group_change('123')
assert r.change_type == change.change_type
assert r.user_id == change.user_id
assert r.id == change.id
assert r.created == change.created
assert r.user_name == change.user_name
assert r.group_change_message == change.group_change_message


def test_group_serdes():
r = from_json_string(to_json_string(sample_group), Group.from_dict)
check_groups_are_same(sample_group, r)
6 changes: 3 additions & 3 deletions tests/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ def test_get_record_set_change(record_set, mocked_responses, vinyldns_client):

def test_list_record_set_changes(mocked_responses, vinyldns_client):
changes = [gen_rs_change(c) for c in record_set_values]
lrscr = ListRecordSetChangesResponse(forward_zone.id, changes, 'next', 'start', 100)
lrscr = ListRecordSetChangesResponse(forward_zone.id, changes, 1, 3, 100)
mocked_responses.add(responses.GET,
'http://test.com/zones/{0}/recordsetchanges?startFrom=start&maxItems=100'.format(
'http://test.com/zones/{0}/recordsetchanges?startFrom=1&maxItems=100'.format(
forward_zone.id), body=to_json_string(lrscr), status=200)
r = vinyldns_client.list_record_set_changes(forward_zone.id, 'start', 100)
r = vinyldns_client.list_record_set_changes(forward_zone.id, 1, 100)
r.start_from = lrscr.start_from
r.next_id = lrscr.next_id
r.max_items = lrscr.max_items
Expand Down