def test_create_batch_change(mocked_responses, vinyldns_client):
    ar = AddRecord('foo.bar.com', RecordType.A, 100, '1.2.3.4')
    drs = DeleteRecordSet('baz.bar.com', RecordType.A)

    arc = AddRecordChange(forward_zone.id, forward_zone.name, 'foo', 'foo.bar.com', RecordType.A, '1.2.3.4',
                          'Complete', 'id1', 'system-message', 'rchangeid1', 'rsid1')
    drc = DeleteRecordSetChange(forward_zone.id, forward_zone.name, 'baz', 'baz.bar.com', RecordType.A, 'Complete',
                                'id2', 'system-message', 'rchangeid2', 'rsid2')
    bc = BatchChange('user-id', 'user-name', 'batch change test', datetime.utcnow(), [arc, drc], 'bcid')
    mocked_responses.add(
        responses.POST, 'http://test.com/zones/batchrecordchanges',
        body=to_json_string(bc), status=200
    )
    r = vinyldns_client.create_batch_change(
        BatchChangeRequest(
            changes=[ar, drs],
            comments='batch change test'
        ))

    assert r.user_id == bc.user_id
    assert r.user_name == bc.user_name
    assert r.comments == bc.comments
    assert r.created_timestamp == bc.created_timestamp
    assert r.id == bc.id
    for l, r in zip(r.changes, bc.changes):
        check_single_changes_are_same(l, r)
示例#2
0
def test_cancel_batch_change(mocked_responses, vinyldns_client):
    error_message = (
        "Zone Discovery Failed: zone for 'foo.bar.com' does not exist in"
        " VinylDNS. If zone exists, then it must be connected to in VinylDNS.")

    error = ValidationError('ZoneDiscoveryError', error_message)

    arc = AddRecordChange(forward_zone.id, forward_zone.name,
                          'cancel', 'cancel.bar.com', RecordType.A, 200,
                          AData('1.2.3.4'), 'PendingReview', 'id1', [error],
                          'system-message', 'cchangeid1', 'csid1')

    drc = DeleteRecordSetChange(forward_zone.id, forward_zone.name, 'cancel2',
                                'cancel2.bar.com', RecordType.A, 'Complete',
                                'id2', [], 'system-message', 'cchangeid2',
                                'csid2')

    bc = BatchChange('user-id',
                     'user-name',
                     datetime.utcnow(), [arc, drc],
                     'bcid',
                     'Cancelled',
                     'Cancelled',
                     owner_group_id='owner-group-id')

    mocked_responses.add(
        responses.POST,
        'http://test.com/zones/batchrecordchanges/bcid/cancel',
        body=to_json_string(bc),
        status=200)

    c = vinyldns_client.cancel_batch_change('bcid')

    check_batch_changes_are_same(c, bc)
示例#3
0
def test_approve_batch_change(mocked_responses, vinyldns_client):
    arc = AddRecordChange(forward_zone.id, forward_zone.name,
                          'foo', 'foo.bar.com', RecordType.A, 200,
                          AData('1.2.3.4'), 'PendingReview', 'id1', [],
                          'system-message', 'rchangeid1', 'rsid1')

    drc = DeleteRecordSetChange(forward_zone.id, forward_zone.name, 'baz',
                                'baz.bar.com', RecordType.A, 'PendingReview',
                                'id2', [], 'system-message', 'rchangeid2',
                                'rsid2')

    bc = BatchChange('user-id',
                     'user-name',
                     datetime.utcnow(), [arc, drc],
                     'bcid',
                     'Complete',
                     'ManuallyApproved',
                     comments='batch change test',
                     owner_group_id='owner-group-id',
                     reviewer_id='admin-id',
                     reviewer_user_name='admin',
                     review_comment='looks good',
                     review_timestamp=datetime.utcnow())

    mocked_responses.add(
        responses.POST,
        'http://test.com/zones/batchrecordchanges/bcid/approve',
        body=to_json_string(bc),
        status=200)

    r = vinyldns_client.approve_batch_change('bcid', 'looks good')

    check_batch_changes_are_same(r, bc)
示例#4
0
def test_get_batch_change(mocked_responses, vinyldns_client):
    arc = AddRecordChange(forward_zone.id, forward_zone.name,
                          'foo', 'foo.bar.com', RecordType.A, 200,
                          AData('1.2.3.4'), 'Complete', 'id1', [],
                          'system-message', 'rchangeid1', 'rsid1')

    drc = DeleteRecordSetChange(forward_zone.id, forward_zone.name, 'baz',
                                'baz.bar.com', RecordType.A, 'Complete', 'id2',
                                [], 'system-message', 'rchangeid2', 'rsid2')

    drc_with_data = DeleteRecordSetChange(forward_zone.id, forward_zone.name,
                                          'biz', 'biz.bar.com', RecordType.A,
                                          'Complete', 'id3', [],
                                          'system-message', 'rchangeid3',
                                          'rsid3', AData("5.6.7.8"))

    bc = BatchChange('user-id',
                     'user-name',
                     datetime.utcnow(), [arc, drc, drc_with_data],
                     'bcid',
                     'Complete',
                     'AutoApproved',
                     comments='batch change test',
                     owner_group_id='owner-group-id')

    mocked_responses.add(responses.GET,
                         'http://test.com/zones/batchrecordchanges/bcid',
                         body=to_json_string(bc),
                         status=200)

    r = vinyldns_client.get_batch_change('bcid')

    check_batch_changes_are_same(r, bc)
示例#5
0
    def get_batch_change(self, batch_change_id, **kwargs):
        """
        Get an existing batch change.

        :param batch_change_id: the unique identifier of the batchchange
        :return: the content of the response
        """
        url = urljoin(self.index_url, u'/zones/batchrecordchanges/{0}'.format(batch_change_id))
        response, data = self.__make_request(url, u'GET', self.headers, None, **kwargs)
        return BatchChange.from_dict(data) if data is not None else None
示例#6
0
    def create_batch_change(self, batch_change_input, **kwargs):
        """
        Create a new batch change.

        :param batch_change_input: the batchchange to be created
        :return: the content of the response
        """
        url = urljoin(self.index_url, u'/zones/batchrecordchanges')
        response, data = self.__make_request(url, u'POST', self.headers, to_json_string(batch_change_input), **kwargs)
        return BatchChange.from_dict(data)
示例#7
0
    def reject_batch_change(self, batch_change_id, rejection=None, **kwargs):
        """
        Reject a batch change

        :return: the content of the response
        """
        url = urljoin(self.index_url, u'/zones/batchrecordchanges/{0}/reject'.format(batch_change_id))
        response, data = self.__make_request(url, u'POST', self.headers,  to_review_json(rejection), **kwargs)

        return BatchChange.from_dict(data)
示例#8
0
    def cancel_batch_change(self, batch_change_id, **kwargs):
        """
        Cancel a batch change

        :return: the content of the response
        """
        url = urljoin(self.index_url, u'/zones/batchrecordchanges/{0}/cancel'.format(batch_change_id))
        response, data = self.__make_request(url, u'POST', self.headers, **kwargs)

        return BatchChange.from_dict(data) if data is not None else None
示例#9
0
    def approve_batch_change(self, batch_change_id, approval=None, **kwargs):
        """
        Approve a batch change

        :return: the content of the response
        """
        url = urljoin(self.index_url, '/zones/batchrecordchanges/{0}/approve'.format(batch_change_id),
                      to_json_string(approval))
        response, data = self.__make_request(url, u'POST', self.headers, to_review_json(approval), **kwargs)

        return BatchChange.from_dict(data)
示例#10
0
def test_create_batch_change(mocked_responses, vinyldns_client):
    ar = AddRecord('foo.baa.com', RecordType.A, 100, AData('1.2.3.4'))
    drs = DeleteRecordSet('baz.bar.com', RecordType.A)
    drs_with_data = DeleteRecordSet('baz-with-data.bar.com', RecordType.A,
                                    AData('5.6.7.8'))

    arc = AddRecordChange(forward_zone.id, forward_zone.name,
                          'foo', 'foo.bar.com', RecordType.A, 200,
                          AData('1.2.3.4'), 'Complete', 'id1', [],
                          'system-message', 'rchangeid1', 'rsid1')

    drc = DeleteRecordSetChange(forward_zone.id, forward_zone.name, 'baz',
                                'baz.bar.com', RecordType.A, 'Complete', 'id2',
                                [], 'system-message', 'rchangeid2', 'rsid2')

    drc_with_data = DeleteRecordSetChange(forward_zone.id, forward_zone.name,
                                          'baz-with-data',
                                          'baz-with-data.bar.com',
                                          RecordType.A, 'Complete', 'id2', [],
                                          'system-message', 'rchangeid3',
                                          'rsid3', AData('5.6.7.8'))

    # Python 2/3 compatibility
    try:
        tomorrow = datetime.now().astimezone() + timedelta(1)
    except TypeError:
        tomorrow = datetime.now(tzlocal()).astimezone(tzlocal()) + timedelta(1)

    bc = BatchChange('user-id',
                     'user-name',
                     datetime.utcnow(), [arc, drc, drc_with_data],
                     'bcid',
                     'Scheduled',
                     'PendingReview',
                     comments='batch change test',
                     owner_group_id='owner-group-id',
                     scheduled_time=tomorrow)

    mocked_responses.add(responses.POST,
                         'http://test.com/zones/batchrecordchanges',
                         body=to_json_string(bc),
                         status=200)

    r = vinyldns_client.create_batch_change(
        BatchChangeRequest(changes=[ar, drs, drs_with_data],
                           comments='batch change test',
                           owner_group_id='owner-group-id',
                           scheduled_time=tomorrow))

    check_batch_changes_are_same(r, bc)
示例#11
0
    def create_batch_change(self, batch_change_input, allow_manual_review=None, **kwargs):
        """
        Create a new batch change.

        :param batch_change_input: the batchchange to be created
        :param allow_manual_review: set to false to fail rather than go to
        review if there are errors
        :return: the content of the response
        """
        arg = ''

        if allow_manual_review is not None:
            arg = u'allowManualReview={0}'.format(allow_manual_review)

        url = urljoin(self.index_url, u'/zones/batchrecordchanges') + u'?' + arg
        response, data = self.__make_request(url, u'POST', self.headers, to_json_string(batch_change_input), **kwargs)

        return BatchChange.from_dict(data)
示例#12
0
def test_reject_batch_change(mocked_responses, vinyldns_client):
    error_message = "Zone Discovery Failed: zone for \"foo.bar.com\" does not exist in VinylDNS. \
    If zone exists, then it must be connected to in VinylDNS."

    error = ValidationError('ZoneDiscoveryError', error_message)

    arc = AddRecordChange(forward_zone.id, forward_zone.name,
                          'reject', 'reject.bar.com', RecordType.A, 200,
                          AData('1.2.3.4'), 'PendingReview', 'id1', [error],
                          'system-message', 'rchangeid1', 'rsid1')

    drc = DeleteRecordSetChange(forward_zone.id, forward_zone.name, 'reject2',
                                'reject2.bar.com', RecordType.A, 'Complete',
                                'id2', [], 'system-message', 'rchangeid2',
                                'rsid2')

    bc = BatchChange('user-id',
                     'user-name',
                     datetime.utcnow(), [arc, drc],
                     'bcid',
                     'Rejected',
                     'Rejected',
                     comments='batch change test',
                     owner_group_id='owner-group-id',
                     reviewer_id='admin-id',
                     reviewer_user_name='admin',
                     review_comment='not good',
                     review_timestamp=datetime.utcnow())

    mocked_responses.add(
        responses.POST,
        'http://test.com/zones/batchrecordchanges/bcid/reject',
        body=to_json_string(bc),
        status=200)

    r = vinyldns_client.reject_batch_change('bcid', 'not good')

    check_batch_changes_are_same(r, bc)