def test_update_rql_driver_error(self):
     with self.app.test_request_context():
         with patch.object(Interactions, 'update',
                           side_effect=RqlDriverError(None)):
             update(DEFAULT_REGISTRATIONS_TABLE,
                    record_id='123',
                    username=None,
                    updates={})
             self.assertRaises(RqlDriverError)
 def test_update_no_record_id(self):
     with self.app.test_request_context():
         with patch.object(Interactions, 'update', return_value={}):
             response = update(DEFAULT_REGISTRATIONS_TABLE,
                               record_id=None,
                               username='******',
                               updates={})
             self.assertEqual(response.status_code, client.OK)
 def test_update_rql_runtime_error(self):
     with self.app.test_request_context():
         with patch.object(Interactions, 'update',
                           side_effect=RqlRuntimeError(None, None, None)):
             response = update(DEFAULT_REGISTRATIONS_TABLE,
                               record_id='123', username=None, updates={})
             self.assertRaises(RqlRuntimeError)
             self.assertEqual(response.status_code,
                              client.INTERNAL_SERVER_ERROR)
 def test_update_bad_request(self, connection_method):
     connection_method.return_value = Mock(__enter__=Mock, __exit__=Mock())
     with self.app.test_request_context():
         with patch.object(rethink, 'table', return_value=Mock()) as \
                 table_method:
             response = update(DEFAULT_REGISTRATIONS_TABLE,
                               record_id='123',
                               username=None,
                               updates={})
             self.assertEqual(response.status_code, client.BAD_REQUEST)
             table_method.assert_called_once_with(
                 DEFAULT_REGISTRATIONS_TABLE
             )
Exemplo n.º 5
0
    def patch(self):
        """
        Updates account. Only one field can be updated: endpoint
        Updating the endpoint also resets the failed_count
        """
        json_data = request.get_json()
        username = request.headers['username']

        if 'endpoint' in json_data:
            update_json = {
                'endpoint': json_data['endpoint'],
                'failed_count': 0
            }
        else:
            return make_response(jsonify(
                {'Error': 'Missing endpoint field'}), client.BAD_REQUEST)

        return update(DEFAULT_ACCOUNTS_TABLE, username=username,
                      updates=update_json)
Exemplo n.º 6
0
    def patch(self, registration_id):
        """
        Updates registration. Only one field can be updated: description
        """
        return_val = validate_access(request.headers['username'],
                                     registration_id=registration_id)

        if return_val:
            return return_val

        json_data = request.get_json()
        update_json = {}

        if 'description' in json_data:
            update_json['description'] = json_data['description']
        else:
            return make_response(
                jsonify({'Error': 'Description field missing'}),
                client.BAD_REQUEST)

        return update(DEFAULT_REGISTRATIONS_TABLE,
                      record_id=registration_id,
                      updates=update_json)
Exemplo n.º 7
0
    def patch(self, registration_id):
        """
        Updates registration. Only one field can be updated: description
        """
        return_val = validate_access(
            request.headers['username'],
            registration_id=registration_id)

        if return_val:
            return return_val

        json_data = request.get_json()
        update_json = {}

        if 'description' in json_data:
            update_json['description'] = json_data['description']
        else:
            return make_response(
                jsonify({'Error': 'Description field missing'}),
                client.BAD_REQUEST)

        return update(DEFAULT_REGISTRATIONS_TABLE,
                      record_id=registration_id,
                      updates=update_json)
 def test_update_bad_request(self):
     with self.app.test_request_context():
         with patch.object(Interactions, "update", return_value=None):
             response = update(DEFAULT_REGISTRATIONS_TABLE, record_id="123", username=None, updates={})
             self.assertEqual(response.status_code, client.BAD_REQUEST)