示例#1
0
def test_login():
    data = {
        'isValid': True,
        'messages': [],
        'user': {
            'User': '******',
            'FullName': 'Swarm User',
            'Email': '*****@*****.**',
            'Type': 'standard',
            'Password': '******',
            'isAdmin': False,
            'isSuper': False
        }
    }

    responses.add(
        responses.POST,
        re.compile(r'.*/api/v\d+/login'),
        json=data
    )

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.login()
    assert 'user' in response
示例#2
0
def test_create_exception():
    client_v1 = SwarmClient('http://server/api/v1', 'login', 'password')
    with pytest.raises(SwarmCompatibleError):
        client_v1.reviews.create(111, required_reviewers=['p.belskiy'])

    client_v6 = SwarmClient('http://server/api/v6', 'login', 'password')
    with pytest.raises(SwarmCompatibleError):
        client_v6.reviews.create(222, reviewer_groups=['master'])
示例#3
0
def test_response_invalid_json():
    responses.add(
        responses.GET,
        re.compile(r'.*/api/v\d+/version'),
        body='invalid json',
        status=200
    )

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    with pytest.raises(SwarmError):
        client.get_version()
示例#4
0
def test_response_non_ok():
    responses.add(
        responses.GET,
        re.compile(r'.*/api/v\d+/version'),
        json={'error': 'server error'},
        status=500
    )

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    with pytest.raises(SwarmError):
        client.get_version()
示例#5
0
def test_get_default_reviewers():
    data = {
        'change': {
            'id': '1050',
            'defaultReviewers': {
                'groups': {
                    'group1': {
                        'required': '1'
                    },
                    'group2': {}
                },
                'users': {
                    'user1': {},
                    'user2': {
                        'required': 'true'
                    }
                }
            }
        }
    }

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/changes/\d+/defaultreviewers'),
                  json=data)

    client = SwarmClient('http://server/api/v8', 'login', 'password')

    response = client.changes.get_default_reviewers(1050)
    assert 'defaultReviewers' in response['change']
示例#6
0
def test_get():
    data_1 = [{
        'User': '******',
        'FullName': 'Bruno First'
    }, {
        'User': '******',
        'FullName': 'Super Second'
    }]

    data_2 = {'isValid': False, 'messages': 'No such group'}

    responses.add(responses.GET, re.compile(r'.*/api/v\d+/users'), json=data_1)

    responses.add(responses.GET, re.compile(r'.*/api/v\d+/users'), json=data_2)

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.users.get(
        fields=['User', 'FullName'],
        users=['super', 'bruno'],
    )

    assert len(response) > 0

    response = client.users.get(group='none')

    assert response['isValid'] is False
示例#7
0
def test_cleanup():
    data = {'complete': [{'1': ['2']}], 'incomplete': []}

    responses.add(responses.POST,
                  re.compile(r'.*/api/v\d+/reviews/12345/cleanup'),
                  json=data,
                  status=200)

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.reviews.cleanup(12345, reopen=True)
    assert 'complete' in response

    client = SwarmClient('http://server/api/v5', 'login', 'password')
    with pytest.raises(SwarmCompatibleError):
        client.reviews.cleanup(12345)
示例#8
0
def test_destroy_session():
    data = {
        'isValid': True,
        'messages': []
    }

    responses.add(
        responses.DELETE,
        re.compile(r'.*/api/v\d+/session'),
        json=data
    )

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.destroy_session()
    assert 'messages' in response
示例#9
0
def test_get_latest_revision_and_change():
    client = SwarmClient('http://server/api/v9', 'login', 'password')

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/reviews/12345'),
                  json={
                      'review': {
                          'versions': [{
                              'change': 1
                          }, {
                              'change': 2,
                              'archiveChange': 3
                          }]
                      }
                  },
                  status=200)

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/reviews/555'),
                  json={'review': {
                      'versions': [{
                          'change': 7
                      }]
                  }},
                  status=200)

    revision, change = client.reviews.get_latest_revision_and_change(12345)
    assert revision == 2
    assert change == 3

    revision, change = client.reviews.get_latest_revision_and_change(555)
    assert revision == 1
    assert change == 7
示例#10
0
def test_logout():
    data = {
        'isValid': True,
        'messages': []
    }

    responses.add(
        responses.POST,
        re.compile(r'.*/api/v\d+/logout'),
        json=data
    )

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.logout()
    assert 'messages' in response
示例#11
0
def test_get():
    data = {
        'topic': 'reviews/911',
        'comments': {
            '35': {
                'id': 35,
                'body':
                'Excitation thunder cats intelligent man braid organic bitters.',
                'time': 1461164347,
                'user': '******'
            },
            '39': {
                'id': 39,
                'body':
                'Chamber tote bag butcher, shirk truffle mode shabby chic single-origin coffee.',
                'time': 1461164347,
                'user': '******'
            }
        },
        'lastSeen': 39
    }

    responses.add(responses.GET, re.compile(r'.*/comments'), json=data)

    client = SwarmClient('http://server/api/v9', 'login', 'password')
    response = client.comments.get(after=30,
                                   topic='reviews/911',
                                   context_version=2,
                                   limit=2,
                                   fields=['id', 'body', 'time', 'user'])

    assert response['topic'] == 'reviews/911'
示例#12
0
def test_login_saml():
    data = {
        'isValid': 'true',
        'url': '<url to redirect to>'
    }

    responses.add(
        responses.POST,
        re.compile(r'.*/api/v\d+/login/saml'),
        json=data
    )

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.login(saml=True)
    assert 'isValid' in response
示例#13
0
def test_edit():
    data = {
        'comment': {
            'id': 1,
            'attachments': [],
            'body': 'Edited comment',
            'context': [],
            'edited': 123466790,
            'flags': ['closed'],
            'likes': [],
            'taskState': 'comment',
            'time': 123456789,
            'topic': 'reviews/42',
            'updated': 123456790,
            'user': '******'
        }
    }

    responses.add(responses.PATCH, re.compile(r'.*\/comments/123'), json=data)

    client = SwarmClient('http://server/api/v8', 'login', 'password')

    response = client.comments.edit(
        123,
        'Edited comment',
        topic='review/42',
        task_state='comment',
        flags=['closed'],
        silence_notification=True,
        delay_notification=True,
    )

    assert response['comment']['body'] == 'Edited comment'
    assert 'closed' in response['comment']['flags']
示例#14
0
def test_get():
    data = {
        'projects': [{
            'id': 'testproject1',
            'description': 'Test test test',
            'members': ['alice'],
            'name': 'TestProject'
        }, {
            'id': 'testproject2',
            'description': 'Test test test',
            'members': ['alice'],
            'name': 'TestProject'
        }]
    }

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/projects'),
                  json=data)

    client = SwarmClient('http://server/api/v2', 'login', 'password')

    response = client.projects.get(
        fields=['id', 'description', 'members', 'name'],
        workflow='some-workflow')

    assert 'projects' in response
示例#15
0
def test_get_latest_revision_and_change_exception():
    client = SwarmClient('http://server/api/v9', 'login', 'password')

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/reviews/12345'),
                  json={'review': {}},
                  status=200)

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/reviews/12345'),
                  json={'review': {
                      'versions': []
                  }},
                  status=200)

    responses.add(
        responses.GET,
        re.compile(r'.*/api/v\d+/reviews/12345'),
        json={'review': {
            'versions': [{
                'change': 1
            }, {
                'archiveChange': 3
            }]
        }},
        status=200)

    with pytest.raises(SwarmError):
        client.reviews.get_latest_revision_and_change(12345)

    with pytest.raises(SwarmError):
        client.reviews.get_latest_revision_and_change(12345)

    with pytest.raises(SwarmError):
        client.reviews.get_latest_revision_and_change(12345)
示例#16
0
def test_get():
    data = {
        'workflows': [{
            'id': '1',
            'name': 'myWorkflow',
            'description': 'A description',
            'on_submit': {
                'with_review': {
                    'rule': 'no_checking'
                },
                'without_review': {
                    'rule': 'no_checking'
                }
            },
            'auto_approve': {
                'rule': 'never'
            },
            'counted_votes': {
                'rule': 'anyone'
            },
            'shared': 'true',
            'owners': ['user1', 'user2']
        }, {
            'id': '2',
            'name': 'myWorkflow 2',
            'description': 'A description',
            'on_submit': {
                'with_review': {
                    'rule': 'no_checking'
                },
                'without_review': {
                    'rule': 'no_checking'
                }
            },
            'auto_approve': {
                'rule': 'votes'
            },
            'counted_votes': {
                'rule': 'members'
            },
            'shared': 'true',
            'owners': ['user3', 'user4']
        }]
    }

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/workflows'),
                  json=data)

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.workflows.get(fields=[
        'id', 'name', 'description', 'on_submit', 'auto_approve',
        'counted_votes', 'shared', 'owners'
    ],
                                    no_cache=True)

    assert 'workflows' in response
示例#17
0
def test_add_change():
    data = {
        'review': {
            'id':
            123,
            'author':
            'bruno',
            'changes': [122, 124],
            'commits': [],
            'commitStatus': [],
            'created':
            1399325913,
            'deployDetails': [],
            'deployStatus':
            None,
            'description':
            'Adding .jar that should have been included in r110\n',
            'groups': [],
            'participants': {
                'bruno': []
            },
            'pending':
            True,
            'projects': [],
            'state':
            'needsReview',
            'stateLabel':
            'Needs Review',
            'testDetails': [],
            'testStatus':
            None,
            'type':
            'default',
            'updated':
            1399325913,
            'versions': [{
                'difference': 1,
                'stream': None,
                'change': 124,
                'user': '******',
                'time': 1399330003,
                'pending': True,
                'archiveChange': 124
            }]
        }
    }

    responses.add(responses.POST,
                  re.compile(r'.*/api/v\d+/reviews/12345/changes'),
                  json=data,
                  status=200)

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.reviews.add_change(12345, change=124, mode='append')

    assert 'review' in response
示例#18
0
def test_check_auth_token():
    data = {
        'results': {
            'trigger': 'GAuth says yes!',
            'successMsg': 'Second factor authentication approved.'
        },
        'code': 200
    }

    responses.add(
        responses.POST,
        re.compile(r'.*/api/v\d+/checkauth'),
        json=data
    )

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.check_auth('TOKEN')
    assert 'results' in response
示例#19
0
def test_get_info_error():
    data = {'error': 'Not Found'}

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/reviews/12345'),
                  json=data,
                  status=404)

    client = SwarmClient('http://server/api/v1', 'login', 'password')
    with pytest.raises(SwarmNotFoundError):
        client.reviews.get_info(12345)
示例#20
0
def test_get_exception():
    client = SwarmClient('http://server/api/v4', 'login', 'password')

    with pytest.raises(SwarmCompatibleError):
        client.comments.get(ignore_archived=True)

    with pytest.raises(SwarmCompatibleError):
        client.comments.get(tasks_only=True)

    with pytest.raises(SwarmCompatibleError):
        client.comments.get(task_states=['open'])
示例#21
0
def test_delete():
    data = {'isValid': True, 'messages': ['Workflow [1] was deleted']}

    responses.add(responses.DELETE,
                  re.compile(r'.*/api/v\d+/workflows/1'),
                  json=data)

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.workflows.delete(1)
    assert 'messages' in response
示例#22
0
def test_sync_client():
    responses.add(
        responses.GET,
        re.compile(r'.*/api/v\d+/version'),
        json=GET_VERSION_DATA,
        status=200
    )

    try:
        client = SwarmClient(
            'http://server/api/v9',
            'login',
            'password',
            timeout=10,
        )

        version = client.get_version()
        assert version['year'] == '2018'
    finally:
        client.close()
示例#23
0
def test_delete():
    data = {'id': 'my-group'}

    responses.add(responses.DELETE,
                  re.compile(r'.*/api/v\d+/groups/my-group'),
                  json=data)

    client = SwarmClient('http://server/api/v2', 'login', 'password')

    response = client.groups.delete('my-group')
    assert 'id' in response
示例#24
0
def test_get_check_status():
    data = {'status': 'OK', 'isValid': 'true', 'messages': []}

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/changes/\d+/check'),
                  json=data)

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.changes.get_check_status(1050, 'enforced')
    assert 'status' in response
示例#25
0
def test_get_affects_projects():
    data = {'change': {'id': '1050', 'projects': {'jam': ['live', 'main']}}}

    responses.add(responses.GET,
                  re.compile(r'.*/api/v\d+/changes/\d+/affectsprojects'),
                  json=data)

    client = SwarmClient('http://server/api/v8', 'login', 'password')

    response = client.changes.get_affects_projects(1050)
    assert 'projects' in response['change']
示例#26
0
def test_obliterate():
    data = {
        'isValid': True,
        'message': 'review 1 has been Obliterated',
        'code': 200
    }

    responses.add(responses.POST,
                  re.compile(r'.*/api/v\d+/reviews/12345/obliterate'),
                  json=data,
                  status=200)

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.reviews.obliterate(12345)
    assert 'message' in response

    client = SwarmClient('http://server/api/v8', 'login', 'password')
    with pytest.raises(SwarmCompatibleError):
        client.reviews.obliterate(12345)
示例#27
0
def test_delete():
    data = {'id': 'testproject4'}

    responses.add(responses.DELETE,
                  re.compile(r'.*/api/v\d+/projects/testproject4'),
                  json=data)

    client = SwarmClient('http://server/api/v2', 'login', 'password')

    response = client.projects.delete('testproject4')
    assert 'id' in response
示例#28
0
def test_notify():
    data = {
        'isValid': True,
        'message': 'No comment notifications to send',
        'code': 200
    }

    responses.add(responses.POST, re.compile(r'.*\/comments'), json=data)

    client = SwarmClient('http://server/api/v9', 'login', 'password')
    response = client.comments.notify('reviews/911')
    assert response['isValid'] is True
示例#29
0
def test_get_auth_methods():
    data = {
        'results': {
            'methods': {
                '1': {
                    'methodName': 'Method Name will be here',
                    'methodDesc': 'Method Description will be here'
                },
                '2': {
                    'methodName': 'Method Name will be here',
                    'methodDesc': 'Method Description will be here'
                },
                '3': {
                    'methodName': 'Method Name will be here',
                    'methodDesc': 'Method Description will be here'
                },
                '4': {
                    'methodName': 'Method Name will be here',
                    'methodDesc': 'Method Description will be here'
                }
            }
        },
        'option': {
            'persist': 'option',
            'nextState': 'init-auth'
        },
        'code': 200
    }

    responses.add(
        responses.GET,
        re.compile(r'.*/api/v\d+/listmethods'),
        json=data
    )

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.get_auth_methods()
    assert 'results' in response
示例#30
0
def test_update():
    data = {
        'workflow': {
            'id': '1',
            'name': 'myWorkflow',
            'description': 'A description',
            'on_submit': {
                'with_review': {
                    'rule': 'no_checking'
                },
                'without_review': {
                    'rule': 'no_checking'
                }
            },
            'auto_approve': {
                'rule': 'votes'
            },
            'counted_votes': {
                'rule': 'anyone'
            },
            'shared': 'true',
            'owners': ['user1', 'user2']
        }
    }

    responses.add(responses.PUT,
                  re.compile(r'.*/api/v\d+/workflows/1'),
                  json=data)

    client = SwarmClient('http://server/api/v9', 'login', 'password')

    response = client.workflows.update(
        1,
        name='myWorkflow',
        description='A description',
        shared=True,
        owners=['user1', 'user2'],
        on_submit={
            'with_review': {
                'rule': 'no_checking'
            },
            'without_review': {
                'rule': 'no_checking'
            }
        },
        end_rules=['no_revision'],
        auto_approve='never',
        counted_votes='members',
    )

    assert 'workflow' in response