Exemplo n.º 1
0
def test_request_response():
    response = get_users()

    assert_dict_contains_subset(
        {'Content-Type': 'application/json; charset=utf-8'}, response.headers)
    assert_true(response.ok)
    assert_is_instance(response.json(), list)
Exemplo n.º 2
0
    def test_perform_requests_called_correctly_for_post_method(
            self, mock_request):
        url = 'https://rundeck.example.com/api/13/test_endpoint'
        mock_request.return_value = self.resp

        self.client._perform_request(url,
                                     method='POST',
                                     params={'xmlBatch': '123\n456'})

        args = mock_request.call_args
        nt.assert_equal(2, len(args))
        nt.assert_equal((
            'POST',
            url,
        ), args[0])
        nt.assert_in('headers', args[1])
        nt.assert_in('data', args[1])
        headers = args[1]['headers']
        nt.assert_dict_contains_subset(
            {
                'X-Rundeck-Auth-Token': self.token,
                'User-Agent': 'PyRundeck v ' + __version__
            }, headers)
        data = args[1]['data']
        nt.assert_dict_contains_subset({'xmlBatch': '123\n456'}, data)
Exemplo n.º 3
0
    def test_api001(self,datas):
        #近一步优化,将request请求进行封装
        base_url = datas['base_url']
        api_command = datas['api_command']
        url = base_url+api_command
        # unicode 转换为str
        # 当params为空的unicode时,使用eval会报错,所以,需要判断一下:
        # 当params为非空时,使用eval(datas['params'])将unicode转换为str
        # 当params为空的nnicode类型时,重新定义params='',此时params为空的str类型;
        params = datas['params']
        if params != '':
            params = eval(datas['params'])
            print 'ok'
        else:
            params = ''
            print 'nothing'
        # set_trace()
        res = requests.get(url=url, params=params)
        res_code = res.status_code
        # 字典
        res_result = res.json()
        expect_code = int(datas['expect_code'])
        # excel中读取的expect_result是unicode格式,使用eval转换dict
        expect_result = eval(datas['expect_result'])
        # 比较状态码和结果

        # return expect_code,expect_result,res_code,res_result

        assert_equal(expect_code, res_code,msg=u'请求错误%d'%res_code)
        assert_dict_contains_subset(expect_result,res_result,msg=u'预期结果错误%s'%res_result)
Exemplo n.º 4
0
def test_modelmapper_model_save():
    db = get_db()
    users = dibble.mapper.ModelMapper(AdvancedUserModel, db.user)

    user = users()
    user.logincount.inc(1)
    user.username.set('Foo Bar')
    user.usernames.push('Foo Bar')
    user.save()

    u = dict(users.collection.find_one())
    expected = {
        'logincount': 1,
        'username': '******',
        'usernames': ['Foo Bar']
    }

    assert_dict_contains_subset(expected, u)

    users.collection.update({}, {'$set': {'username': '******'}})

    user.logincount.inc(41)
    user.save()

    u = dict(users.collection.find_one())
    expected = {
        'logincount': 42,
        'username': '******',
        'usernames': ['Foo Bar']
    }

    assert_dict_contains_subset(expected, u)
Exemplo n.º 5
0
def test_createColumns():
    columns_to_create = [Column(name="FirstTestColumn", columnType="INTEGER"), Column(name="SecondTestColumn",
                                                                                      columnType="DOUBLE")]
    created_columns = syn.createColumns(columns_to_create)
    assert_equals(len(columns_to_create), len(created_columns))
    for col_to_create, created_col in zip(columns_to_create, created_columns):
        assert_in('id', created_col)
        assert_dict_contains_subset(col_to_create, created_col)
def test_createColumns():
    columns_to_create = [Column(name="FirstTestColumn", columnType="INTEGER"), Column(name="SecondTestColumn",
                                                                                      columnType="DOUBLE")]
    created_columns = syn.createColumns(columns_to_create)
    assert_equals(len(columns_to_create), len(created_columns))
    for col_to_create, created_col in zip(columns_to_create, created_columns):
        assert_in('id', created_col)
        assert_dict_contains_subset(col_to_create, created_col)
Exemplo n.º 7
0
def test_set_evar():

    test_evars = {'ekey': 'evalue'}

    for k, v in test_evars.items():
        lpa.set_evar(k, v)
    lpa_evars = lpa.get_cfg('evars')

    assert_dict_contains_subset(test_evars, lpa_evars)
Exemplo n.º 8
0
def test_get_all_evars():

    test_evars = {'ekey1': 'evalue1', 'ekey2': 'evalue2'}
    for k, v in test_evars.items():
        lpa.set_evar(k, v)

    lpa_evars = lpa.get_evar()

    assert_dict_contains_subset(test_evars, lpa_evars)
Exemplo n.º 9
0
def test_get_all_evars():

    test_evars = {'ekey1': 'evalue1', 'ekey2': 'evalue2'}
    for k, v in test_evars.items():
        lpa.set_evar(k, v)

    lpa_evars = lpa.get_evar()

    assert_dict_contains_subset(test_evars, lpa_evars)
Exemplo n.º 10
0
def test_set_evar():

    test_evars = {'ekey': 'evalue'}

    for k, v in test_evars.items():
        lpa.set_evar(k, v)
    lpa_evars = lpa.get_cfg('evars')

    assert_dict_contains_subset(test_evars, lpa_evars)
    def test_basic_put(self):
        "A basic put should work."
        r1 = requests.put(self.url, self.simple_params)
        n.assert_equal(r1.status_code, 204)
        n.assert_equal(r1.content, '')

        r2 = requests.get(self.url)
        n.assert_equal(r2.status_code, 200)
        n.assert_dict_contains_subset(self.http_params, json.loads(r2.text))
 def test_creates_user_no_email(self):
     user = create_user(self.ec_dict)
     assert_dict_contains_subset({
              'id': u'e350cb61-ed72-4335-b915-7617b5e931f0',
              'name': u'741c5e3e-53d0-431e-9f10-b6ebd39590f4',
              'email': u'noemail',
         },
         user
     )
Exemplo n.º 13
0
 def test_api001_case(self):
     set_trace()
     # self.rr1,没有test_api001()属性,有'test_api001_1', 'test_api001_2',属性
     expect_code, expect_result, res_code, res_result = self.rr1.test_api001(
     )
     assert_equal(expect_code, res_code, msg=u'请求错误%d' % res_code)
     assert_dict_contains_subset(expect_result,
                                 res_result,
                                 msg=u'预期结果错误%s' % res_result)
 def test_creates_user_no_email(self):
     user = create_user(self.ec_dict)
     assert_dict_contains_subset({
              'id': u'e350cb61-ed72-4335-b915-7617b5e931f0',
              'name': '*****@*****.**',
              'email': u'noemail',
              'sysadmin': True,
         },
         user
     )
Exemplo n.º 15
0
    def test_request_response(self):
        mock_users_url = 'http://localhost:{port}/users'.format(port=self.mock_server_port)

        # Patch USERS_URL so that the service uses the mock server URL instead of the real URL.
        with patch.dict('project.services.__dict__', {'USERS_URL': mock_users_url}):
            response = get_users()

        assert_dict_contains_subset({'Content-Type': 'application/json; charset=utf-8'}, response.headers)
        assert_true(response.ok)
        assert_list_equal(response.json(), [])
Exemplo n.º 16
0
def test_dict(test_controller):
    """verify that __iter__() (used by dict()) works"""
    test_controller.duty = .1
    assert_dict_contains_subset(
        {
            'interval': 1,
            'duty': .1,
        },
        dict(test_controller)
    )
    def test_request_response(self):
        mock_users_url = 'http://localhost:{port}/users'.format(port=self.mock_server_port)

        # Patch USERS_URL so that the service uses the mock server URL instead of the real URL.
        with patch.dict('example.services.__dict__', {'USERS_URL': mock_users_url}):
            response = get_users()

        assert_dict_contains_subset({'Content-Type': 'application/json; charset=utf-8'}, response.headers)
        assert_true(response.ok)
        assert_list_equal(response.json(), [])
 def test_creates_user_no_email(self):
     user = create_user(self.ec_dict)
     assert_dict_contains_subset({
              'id': u'dcfb1b12-fe52-4d71-9aad-c60fc4c6952c',
              'name': u'johndoe',
              'about': u'Description',
              'email': u'noemail',
         },
         user
     )
 def test_creates_user_no_email(self):
     user = create_user(self.ec_dict)
     assert_dict_contains_subset({
              'id': u'e350cb61-ed72-4335-b915-7617b5e931f0',
              'name': '*****@*****.**',
              'fullname': '*****@*****.**',
              'email': u'noemail',
         },
         user
     )
 def test_creates_users(self):
     user = create_user(self.ec_dict)
     assert_dict_contains_subset({
              'id': u'dcfb1b12-fe52-4d71-9aad-c60fc4c6952c',
              'name': u'johndoe',
              'fullname': u'John Doe',
              'about': u'Description',
              'email': u'*****@*****.**',
         },
         user
     )
Exemplo n.º 21
0
 def test_recording(self):
     recorder = MongodbEnvironLagRecorder(
         self.collection, 'PATH', 'REMOTE_USER')
     
     environ = {'PATH': '/', 'REMOTE_USER': '******'}
     recorder(2.5, environ)
     
     eq_(1, self.collection.count())
     
     mongo_document = self.collection.find_one()
     assert_dict_contains_subset(environ, mongo_document)
Exemplo n.º 22
0
def simpledec(decorator=None, f=None, *args, **kwargs):
    sd_dec = sd.simple_decorator(decorator)
    decorated_f = sd_dec(f)
    nt.assert_dict_contains_subset(
            meta_comp(f),
            meta_comp(decorated_f),
            msg = "decorated function failed. function: %s - %r decorator: %s - %r" % (
                                            f.__name__, meta_comp(f),decorator.__name__,meta_comp(decorated_f)))
    nt.assert_dict_contains_subset(
            meta_comp(decorator),
            meta_comp(sd_dec),
            msg = "simple_decorator on decorator fn %s failed" % decorator.__name__)
Exemplo n.º 23
0
def test_get_context(awsclient):
    actual = get_context(awsclient, 'dev', 'kumo', 'deploy')
    expected_subset = {
        'tool': 'kumo',
        'command': 'deploy',
        'env': 'dev',
    }
    assert_dict_contains_subset(expected_subset, actual)
    # the api_key is currently not rolled out see OPS-126
    # assert_in('_datadog_api_key', actual)
    assert_in('user', actual)
    assert_in('version', actual)
    def test_creates_user_no_email(self):
        user = create_user(self.ec_dict)
        assert_dict_contains_subset({
                 'id': u'e350cb61-ed72-4335-b915-7617b5e931f0',
                 'name': '*****@*****.**',
                 'email': u'noemail',
            },
            user
        )

        members = helpers.call_action('member_list', id=self.test_org['id'])
        assert_equals('Admin', members[1][2])
    def _assert_credentials_set_in_request(key_class, expected_key_name):
        authentication_key_value = get_uuid4_str()
        authentication_key = key_class(authentication_key_value)
        connection = \
            _MockPortalConnection(authentication_key=authentication_key)

        connection.send_get_request(_STUB_URL_PATH)

        expected_credentials = {expected_key_name: [authentication_key_value]}
        prepared_request = connection.prepared_requests[0]
        query_string_args = \
            _get_query_string_args_from_url(prepared_request.url)
        assert_dict_contains_subset(expected_credentials, query_string_args)
Exemplo n.º 26
0
    def _assert_credentials_set_in_request(key_class, expected_key_name):
        authentication_key_value = get_uuid4_str()
        authentication_key = key_class(authentication_key_value)
        connection = \
            _MockPortalConnection(authentication_key=authentication_key)

        connection.send_get_request(_STUB_URL_PATH)

        expected_credentials = {expected_key_name: [authentication_key_value]}
        prepared_request = connection.prepared_requests[0]
        query_string_args = \
            _get_query_string_args_from_url(prepared_request.url)
        assert_dict_contains_subset(expected_credentials, query_string_args)
Exemplo n.º 27
0
def response_content_element_has(step, element, identifier):
    from lettuce.django.steps.models import hashes_data

    element_data = world.response.data[element]
    element_data_by_id = {data.get(identifier): dict(data) for data in element_data}

    # Transform tabular data.
    step_data_by_id = {data.get(identifier): data for data in hashes_data(step)}

    assert_equal(len(element_data_by_id), len(step_data_by_id))

    for identifier, data in step_data_by_id.items():
        assert_dict_contains_subset(actual=element_data_by_id[identifier], expected=data)
Exemplo n.º 28
0
 def user_should_see_the_created_article(self, step):
     """User should see the created article"""
     stc = get_selenium_config(step.context)
     stc_conduit = get_conduit_config(step.context)
     art = ViewArticlePageObject(stc.driver)
     article = stc_conduit.test_data.data.get('last_article')
     current_title = art.read_title()
     current_article = art.read_article()
     assert_dict_contains_subset(
         {
             'title': current_title,
             'article': current_article
         }, article)
     stc.attach_screenshot_to_tests_report(step)
Exemplo n.º 29
0
    def test_user_create(self, mock_request):
        content = {"UserName": '******',
            "About": "about",
            "DisplayName": "display name",
            "Roles": ['OrganisationEditor'],
            "FirstName": "firstname",
            "LastName": "lastname",
            "UserId": "userid123",
            "IsRegistered": False,
            "OrganisationId": 'organisation123',
            "Email": "*****@*****.**"
        }
        mock_request.return_value = mock.Mock(
            status_code=200,
            content=json.dumps(content),
            **{
                'raise_for_status.return_value': None,
                'json.return_value': content,
            }
        )
        site_user = helpers.call_action('get_site_user')
        handle_user_update(
            context={
                'model': model,
                'ignore_auth': True,
                'local_action': True,
                'user': site_user['name']
            },
            audit={'CustomProperties':{'UserName':'******'}},
            harvest_object=None,
        )

        user = helpers.call_action('user_show', id='testuser')
        membership = helpers.call_action('member_list', id='organisation123')
        nt.assert_dict_contains_subset(
            {'about': u'about',
             'display_name': u'display name',
             'email_hash': '6dc2fde946483a1d8a84b89345a1b638',
             'fullname': u'display name',
             'id': u'userid123',
             'name': u'testuser',
             'state': u'active',
             'sysadmin': False
            },
            user
        )
        nt.assert_equals(membership[1], (u'userid123', u'user', u'Editor'))

        membership = helpers.call_action('member_list', id='an_org')
        nt.assert_false(u'userid123' in set(i[0] for i in membership))
Exemplo n.º 30
0
def test_glider_information():
    assert_dict_contains_subset(
        dict(model='', reg='', cid=''),
        read_igc_headers(['AFLA6NG', 'HFDTE',
                          'HFGTYGLIDERTYPE:',
                          'HFGIDGLIDERID:',
                          'HFCIDCOMPETITIONID:']))

    assert_dict_contains_subset(
        dict(model='HORNET', reg='D_4449', cid='TH'),
        read_igc_headers(['AFLA6NG', 'HFDTE150812',
                          'HFGTYGLIDERTYPE:HORNET',
                          'HFGIDGLIDERID:D_4449',
                          'HFCIDCOMPETITIONID:TH']))
Exemplo n.º 31
0
def test_modelmapper_unsafe_update():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.counter.set(1)
    m.save()

    m._update.inc('counter', 41)
    m.save()

    expected = {'foo': 'bar', 'counter': 42}
    assert_dict_contains_subset(expected, dict(m))
Exemplo n.º 32
0
    def test_chart_new(self):
        chart1 = self.new_basic_chart()["chart"]
        assert_dict_contains_subset(self.basic_chart, chart1)

        # test chart created successful
        rv = self.app.get("/api/chart/{}".format(chart1["id"]))
        assert_equal(rv.status_code, 200)

        chart2 = _load_json(rv)["chart"]
        assert_equal(chart1, chart2)

        # test the new created chart in charts list
        charts = _load_json(self.app.get("/api/charts"))["charts"]
        assert_in(chart1, charts)
Exemplo n.º 33
0
def test_glider_information():
    assert_dict_contains_subset(
        dict(model='', reg='', cid=''),
        read_igc_headers([
            'AFLA6NG', 'HFDTE', 'HFGTYGLIDERTYPE:', 'HFGIDGLIDERID:',
            'HFCIDCOMPETITIONID:'
        ]))

    assert_dict_contains_subset(
        dict(model='HORNET', reg='D_4449', cid='TH'),
        read_igc_headers([
            'AFLA6NG', 'HFDTE150812', 'HFGTYGLIDERTYPE:HORNET',
            'HFGIDGLIDERID:D_4449', 'HFCIDCOMPETITIONID:TH'
        ]))
Exemplo n.º 34
0
    def test_dashboard_new(self):
        dashboard1 = self.new_basic_dashboard()["dashboard"]
        assert_dict_contains_subset(self.basic_dashboard, dashboard1)

        # test dashboard created successful
        rv = self.app.get("/api/dashboard/{}".format(dashboard1["id"]))
        assert_equal(rv.status_code, 200)

        dashboard2 = _load_json(rv)["dashboard"]
        assert_equal(dashboard1, dashboard2)

        # test the new created dashboard in dashboards list
        dashboards = _load_json(self.app.get("/api/dashboards"))["dashboards"]
        assert_in(dashboard1, dashboards)
Exemplo n.º 35
0
    def test_change_source(self):
        change_source = get_uuid4_str()
        connection = _MockPortalConnection(change_source=change_source)

        connection.send_get_request(_STUB_URL_PATH)

        prepared_request = connection.prepared_requests[0]
        query_string_args = \
            _get_query_string_args_from_url(prepared_request.url)
        expected_change_source_args = {'auditId': [change_source]}
        assert_dict_contains_subset(
            expected_change_source_args,
            query_string_args,
        )
Exemplo n.º 36
0
def test_modelmapper_unsafe_update():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.counter.set(1)
    m.save()

    m._update.inc('counter', 41)
    m.save()

    expected = {'foo': 'bar', 'counter': 42}
    assert_dict_contains_subset(expected, dict(m))
Exemplo n.º 37
0
def test_subfield_mapper():
    mapper = get_mapper()
    tm = mapper()

    tm.foo['bar']['baz'].set('fumm')
    tm.save()

    res = mapper.collection.find_one()
    expected = {'foo': {'bar': {'baz': 'fumm'}}}
    assert_dict_contains_subset(expected, res)

    tm.foo['bar']['baz'].set('fnorb')
    tm.save()

    res = mapper.collection.find_one()
    expected = {'foo': {'bar': {'baz': 'fnorb'}}}
    assert_dict_contains_subset(expected, res)

    tm.foo['bar'].set({'baz': 'ding'})
    tm.save()

    res = mapper.collection.find_one()
    expected = {'foo': {'bar': {'baz': 'ding'}}}
    assert_dict_contains_subset(expected, res)

    tm.foo.set({'bar': {'baz': 'yadda'}})
    tm.save()

    res = mapper.collection.find_one()
    expected = {'foo': {'bar': {'baz': 'yadda'}}}
    assert_dict_contains_subset(expected, res)
    def test_change_source(self):
        change_source = get_uuid4_str()
        connection = _MockPortalConnection(change_source=change_source)

        connection.send_get_request(_STUB_URL_PATH)

        prepared_request = connection.prepared_requests[0]
        query_string_args = \
            _get_query_string_args_from_url(prepared_request.url)
        expected_change_source_args = {'auditId': [change_source]}
        assert_dict_contains_subset(
            expected_change_source_args,
            query_string_args,
            )
Exemplo n.º 39
0
def test_modelmapper_model_reload():
    db = get_db()
    users = dibble.mapper.ModelMapper(AdvancedUserModel, db.user)

    user = users()
    user.username.set('Foo Bar')
    user.save()

    users.collection.update({}, {'$set': {'username': '******'}})

    user.reload()

    expected = {'username': '******'}

    assert_dict_contains_subset(expected, dict(user))
Exemplo n.º 40
0
    def test_perform_request_called_correctly_for_get_method(self,
                                                             mock_request):
        url = 'https://rundeck.example.com/api/13/test_endpoint'
        mock_request.return_value = self.resp

        self.client._perform_request(url)
        args = mock_request.call_args
        nt.assert_equal(2, len(args))
        nt.assert_equal(('GET', url,), args[0])
        nt.assert_in('headers', args[1])
        headers = args[1]['headers']
        nt.assert_dict_contains_subset({'X-Rundeck-Auth-Token': self.token,
                                        'User-Agent':
                                        'PyRundeck v ' + __version__},
                                       headers)
    def test_with_extra_query_string_args(self):
        """
        Any extra query string argument co-exists with authentication-related
        arguments.

        """
        connection = _MockPortalConnection()

        extra_query_string_args = {'foo': ['bar']}
        connection.send_get_request(_STUB_URL_PATH, extra_query_string_args)

        prepared_request = connection.prepared_requests[0]
        query_string_args = \
            _get_query_string_args_from_url(prepared_request.url)
        assert_dict_contains_subset(extra_query_string_args, query_string_args)
Exemplo n.º 42
0
def test_modelmapper_model_reload():
    db = get_db()
    users = dibble.mapper.ModelMapper(AdvancedUserModel, db.user)

    user = users()
    user.username.set('Foo Bar')
    user.save()

    users.collection.update({}, {'$set': {'username': '******'}})

    user.reload()

    expected = {'username': '******'}

    assert_dict_contains_subset(expected, dict(user))
Exemplo n.º 43
0
    def test_with_extra_query_string_args(self):
        """
        Any extra query string argument co-exists with authentication-related
        arguments.

        """
        connection = _MockPortalConnection()

        extra_query_string_args = {'foo': ['bar']}
        connection.send_get_request(_STUB_URL_PATH, extra_query_string_args)

        prepared_request = connection.prepared_requests[0]
        query_string_args = \
            _get_query_string_args_from_url(prepared_request.url)
        assert_dict_contains_subset(extra_query_string_args, query_string_args)
Exemplo n.º 44
0
 def test_get_form_kwargs_populates_form_with_data_to_be_cloned(self):
     """
     When accessed via the tasks.clone url, the view displays a form
     whose initial data is that of the task being cloned, except for
     the 'name' field, which should be prefixed with 'Copy of '
     """
     user = UserFactory.create()
     original_task = TaskFactory.create()
     TaskKeywordFactory.create_batch(3, task=original_task)
     original_data = get_filled_taskform(original_task).data
     self.view.kwargs = {'clone': original_task.pk}
     self.view.request = Mock(user=user)
     with patch('oneanddone.tasks.views.generic.CreateView.get_form_kwargs') as get_form_kwargs:
         get_form_kwargs.return_value = {'initial': {}}
         initial = self.view.get_form_kwargs()['initial']
     eq_(initial['keywords'], original_task.keywords_list)
     eq_(initial['name'], ' '.join(['Copy of', original_task.name]))
     del original_data['name']
     assert_dict_contains_subset(original_data, initial)
Exemplo n.º 45
0
    def test_perform_request_calls_request_correctly_with_https(self,
                                                                mock_request):
        mock_request.return_value = self.resp

        https_url = 'https://rundeck.example.com'

        client = RundeckApiClient(self.token, https_url)
        client._perform_request(https_url)

        args, kwargs = mock_request.call_args
        nt.assert_dict_contains_subset({'verify': True}, kwargs)

        path_to_pem = '/path/to/pem/file'
        other_client = RundeckApiClient(self.token, https_url,
                                        pem_file_path=path_to_pem)
        other_client._perform_request(https_url)
        args, kwargs = mock_request.call_args

        nt.assert_dict_contains_subset({'verify': path_to_pem}, kwargs)
 def test_creates_user_no_email(self, mock_request):
     mock_request.return_value = mock.Mock(
         status_code=200,
         content=json.dumps(self.org_dict),
         **{
             'raise_for_status.return_value': None,
             'json.return_value': self.org_dict,
         }
     )
     user = create_user(self.ec_dict)
     assert_dict_contains_subset({
              'id': u'e350cb61-ed72-4335-b915-7617b5e931f0',
              'name': '*****@*****.**',
              'email': u'noemail',
         },
         user
     )
     org = helpers.call_action('organization_show', id='2')
     assert_equals('microsoft', org['name'])
Exemplo n.º 47
0
    def test_perform_request_calls_request_correctly_with_https(
            self, mock_request):
        mock_request.return_value = self.resp

        https_url = 'https://rundeck.example.com'

        client = RundeckApiClient(self.token, https_url)
        client._perform_request(https_url)

        args, kwargs = mock_request.call_args
        nt.assert_dict_contains_subset({'verify': True}, kwargs)

        path_to_pem = '/path/to/pem/file'
        other_client = RundeckApiClient(self.token,
                                        https_url,
                                        pem_file_path=path_to_pem)
        other_client._perform_request(https_url)
        args, kwargs = mock_request.call_args

        nt.assert_dict_contains_subset({'verify': path_to_pem}, kwargs)
Exemplo n.º 48
0
 def test_get_form_kwargs_populates_form_with_data_to_be_cloned(self):
     """
     When accessed via the tasks.clone url, the view displays a form
     whose initial data is that of the task being cloned, except for
     the 'name' field, which should be prefixed with 'Copy of '
     """
     user = UserFactory.create()
     original_task = TaskFactory.create()
     TaskKeywordFactory.create_batch(3, task=original_task)
     original_data = get_filled_taskform(original_task).data
     self.view.kwargs = {'clone': original_task.pk}
     self.view.request = Mock(user=user)
     with patch('oneanddone.tasks.views.generic.CreateView.get_form_kwargs'
                ) as get_form_kwargs:
         get_form_kwargs.return_value = {'initial': {}}
         initial = self.view.get_form_kwargs()['initial']
     eq_(initial['keywords'], original_task.keywords_list)
     eq_(initial['name'], ' '.join(['Copy of', original_task.name]))
     del original_data['name']
     assert_dict_contains_subset(original_data, initial)
def test_create_signature_string():
    test = yaml_read("request.yaml")
    for http_trace in test["test_rsa"]:
        trace = http_trace["http"]
        for t in http_trace["tests"]:

            s_data = t["params"]
            with create_mock_request(trace):
                ss = Signature(**s_data)
                ret = ss.sign_http_message(request)

                p = parse_signature_header(ret)
                assert_dict_contains_subset(s_data, p)
                sstring = ss.signature_string(request.method, request.path,
                                              request.headers)
                assert_equal(t["expected_string"], sstring)

                check_ss = Signature(**p)
                check_ss.verify(request.method, request.path, request.headers)
                headers = dict(**request.headers)
                assert headers
Exemplo n.º 50
0
    def test_initialization_sets_up_default_client_correctly(self):
        nt.assert_equal(self.token, self.client.token)
        nt.assert_dict_contains_subset({'X-Rundeck-Auth-Token':
                                        self.token, 'User-Agent':
                                        'PyRundeck v ' + __version__},
                                       self.client.client_args['headers'])

        new_client = RundeckApiClient(self.token, config.root_url,
                                      client_args={'headers':
                                                   {'User-Agent':
                                                    'dummy agent string'}})
        nt.assert_equal(self.token, new_client.token)
        nt.assert_dict_contains_subset({
            'X-Rundeck-Auth-Token': self.token,
            'User-Agent': 'dummy agent string'
        }, new_client.client_args['headers'])

        newest_client = RundeckApiClient(self.token, config.root_url,
                                         client_args={
                                             'headers':
                                             {
                                                 'bogus_header': 'bogus_value'
                                             }
                                         })

        nt.assert_dict_contains_subset({'X-Rundeck-Auth-Token': self.token,
                                        'User-Agent':
                                        'PyRundeck v ' + __version__},
                                       newest_client.client_args['headers'])

        nt.assert_equal(self.token, newest_client.token)
Exemplo n.º 51
0
    def test_initialization_sets_up_default_client_correctly(self):
        nt.assert_equal(self.token, self.client.token)
        nt.assert_dict_contains_subset(
            {
                'X-Rundeck-Auth-Token': self.token,
                'User-Agent': 'PyRundeck v ' + __version__
            }, self.client.client_args['headers'])

        new_client = RundeckApiClient(
            self.token,
            config.root_url,
            client_args={'headers': {
                'User-Agent': 'dummy agent string'
            }})
        nt.assert_equal(self.token, new_client.token)
        nt.assert_dict_contains_subset(
            {
                'X-Rundeck-Auth-Token': self.token,
                'User-Agent': 'dummy agent string'
            }, new_client.client_args['headers'])

        newest_client = RundeckApiClient(
            self.token,
            config.root_url,
            client_args={'headers': {
                'bogus_header': 'bogus_value'
            }})

        nt.assert_dict_contains_subset(
            {
                'X-Rundeck-Auth-Token': self.token,
                'User-Agent': 'PyRundeck v ' + __version__
            }, newest_client.client_args['headers'])

        nt.assert_equal(self.token, newest_client.token)
Exemplo n.º 52
0
    def test_get_recordings_and_identify_kiwi(self):
        from configuration import Configurator
        from ornithokrites import ParallelOrnithokrites

        results_test = './tests/results_test.out'
        results_expected = './tests/results_expected.csv'

        app_config = Configurator().parse_arguments()
        ornithokrites = ParallelOrnithokrites(app_config)

        handler = logging.FileHandler(results_test, 'w')
        formatter = logging.Formatter('%(message)s')
        handler.setFormatter(formatter)
        log = logging.getLogger('log.html')
        log.addHandler(handler)

        ornithokrites.run()

        results_expected_dict = load_expected_results(results_expected)
        results_text_dict = load_results(results_test)

        nt.assert_dict_contains_subset(results_expected_dict, results_text_dict)
Exemplo n.º 53
0
def test_record_list():
    driver.get("http://127.0.0.1:8765/ProjectGlass/")
    # assert there are four records
    rows = driver.find_elements_by_tag_name('tr')
    assert_equal(len(rows), 4 + 1)  # first row is the header
    column_headers = [
        elem.text for elem in rows[0].find_elements_by_tag_name('th')
    ]
    # assert the labels are correct and that the reason and outcome fields are correct
    expected_content = substitute_labels([{
        'label': 0,
        'outcome': 'works fine',
        'reason': 'initial run',
        'version': '6038f9c...',
        'main': 'glass_sem_analysis.py'
    }, {
        'label': 1,
        'outcome': '',
        'reason': 'No filtering'
    }, {
        'label':
        2,
        'outcome':
        'The default colourmap is nicer',
        'reason':
        'Trying a different colourmap'
    }, {
        'label': 3,
        'outcome': '',
        'reason': 'Added labels to output',
        'version': '6038f9c...*'
    }])(utils.env)
    for row, expected in zip(rows[1:], reversed(expected_content)):
        cells = row.find_elements_by_tag_name('td')
        label = cells[0].text
        assert_equal(row.get_attribute('id'), label)
        actual = dict((key.lower(), cell.text)
                      for key, cell in zip(column_headers, cells))
        assert_dict_contains_subset(expected, actual)
Exemplo n.º 54
0
    def test_api002(self,datas):
        # set_trace()
        base_url = datas['base_url']
        api_command = datas['api_command']
        url = base_url+api_command
        # 当params为空的unicode时,使用eval会报错,所以,需要判断一下:
        # 当params为非空时,使用eval(datas['params'])将unicode转换为str

        # 当params为空的nnicode类型时,重新定义params='',此时params为空的str类型;
        params = datas['params']
        if params != '':
            params = eval(datas['params'])
        else:
            params = ''
        # set_trace()
        res = requests.get(url=url, params=params)
        res_code = res.status_code
        res_result = res.json()

        expect_code = int(datas['expect_code'])
        expect_result = eval(datas['expect_result'])
        assert_equal(expect_code, res_code, msg=u'请求错误%d' % res_code)
        assert_dict_contains_subset(expect_result, res_result, msg=u'预期结果错误%s' % res_result)
Exemplo n.º 55
0
 def test_to_dict(self):
     ev = Event(**self.record)
     nt.assert_dict_contains_subset(self.record, ev.to_dict())
     nt.assert_dict_contains_subset({'DELETED': 0, 'ID': 1}, ev.to_dict())
Exemplo n.º 56
0
 def test_to_dict(self):
     test = Partner(**self.record)
     nt.assert_dict_contains_subset(self.record, test.to_dict())
Exemplo n.º 57
0
def get_response(step):
    assert_dict_contains_subset({'Content-Type': 'application/json; charset=utf-8'}, world.response.headers)
    assert_true(world.response.ok)
    assert_list_equal(world.response.json(), [])
Exemplo n.º 58
0
def get_response_with_dict(step):
    assert_dict_contains_subset(step.hashes.first, world.response.json())
Exemplo n.º 59
0
def get_response_with_list(step):
    for expected, actual in izip_longest(list(step.hashes),
                                         world.response.json()):
        assert_dict_contains_subset(expected, actual)
Exemplo n.º 60
0
def assert_params_contain(first, second):
    assert_dict_contains_subset(first, parse_qs(second))