コード例 #1
0
ファイル: example_generation.py プロジェクト: weizai118/trove
 def mgmt_get_host_detail(self):
     results = self.clients.do("mgmt_get_host_detail",
         "/mgmt/hosts/fake_host", "GET", 200, "OK",
         lambda client : client.mgmt.hosts.get("fake_host"))
     with Check() as check:
         for host in results:
             check.equal(results[0].name, "fake_host")
             check.equal(results[1].name, "fake_host")
             # XML entries won't come back as these types. :(
             check.true(isinstance(results[0].percentUsed, int)),
             check.true(isinstance(results[0].totalRAM, int)),
             check.true(isinstance(results[0].usedRAM, int)),
     with Check() as check:
         for host in results:
             check.equal(2, len(host.instances))
             for instance in host.instances:
                 check.equal(instance['status'], 'ACTIVE')
                 check.true(instance['name'] == 'json_rack_instance' or
                            instance['name'] == 'xml_rack_instance')
                 #TODO: Check with GUID regex.
                 check.true(isinstance(instance['id'], six.string_types))
                 check.true(isinstance(instance['server_id'],
                                       six.string_types))
                 check.true(isinstance(instance['tenant_id'],
                                       six.string_types))
コード例 #2
0
 def check_func():
     with Check() as c:
         c.equal(2, 2)
         c.equal("BEE", "BEE")
         c.equal(37, 37)
         raise RuntimeError("Unexplained error!")
         c.equal("CAT", "RAT")
コード例 #3
0
 def verify_correct_update(self):
     quotas = self.mgmt_client.quota.show(self.user1.tenant)
     with Check() as check:
         check.equal(0, quotas["instances"])
         check.equal(CONFIG.trove_max_volumes_per_tenant,
                     quotas["volumes"])
     asserts.assert_equal(len(quotas), 2)
コード例 #4
0
ファイル: example_generation.py プロジェクト: weizai118/trove
    def do(self, name, url, method, status, reason, func, func_args=None):
        """
        Performs the given function twice, first for the JSON client, then for
        the XML one, and writes both to their respective files.
        'name' is the name of the file, while 'url,' 'method,' 'status,'
        and 'reason' are expected values that are asserted against.
        If func_args is present, it is a list of lists, each one of which
        is passed as the *args to the two invocations of "func".
        """
        func_args = func_args or [[], []]
        snippet_writer = SnippetWriter(conf)
        results = []
        for index, client in enumerate(self.clients):
            client.client.snippet_writer = snippet_writer
            client.client.name = name
            args = func_args[index]
            result = func(client, *args)
            with Check() as check:
                if isinstance(url, (list, tuple)):
                    check.equal(client.client.old_info['url'], url[index])
                else:
                    check.equal(client.client.old_info['url'], url)
                check.equal(client.client.old_info['method'], method)
                check.equal(client.client.old_info['response_headers'].status,
                            status)
                check.equal(client.client.old_info['response_headers'].reason,
                            reason)
            results.append(result)
            # To prevent this from writing a snippet somewhere else...
            client.client.name = "junk"

        return results
コード例 #5
0
 def check_quotas_are_set_to_defaults(self):
     quotas = self.mgmt_client.quota.show(self.user1.tenant)
     with Check() as check:
         check.equal(CONFIG.trove_max_instances_per_user,
                     quotas["instances"])
         check.equal(CONFIG.trove_max_volumes_per_user, quotas["volumes"])
     assert_equal(len(quotas), 2)
コード例 #6
0
     def test_method_im_class_points_to_class(self):
        from proboscis import test
        from proboscis.asserts import Check

        @test
        def func1():
            pass

        @test(groups=["top_level_class_group"])
        class ExampleTest(object):
            @test
            def test_1(self):
                pass

        with Check() as check:
            for t in self.registry.tests:
                if t.home == ExampleTest:
                    pass
                elif t.home == ExampleTest.test_1:
                    if not t.is_child:
                        check.fail("Test Entry did not mark method as such!")
                    else:
                        check.true(ExampleTest in t.homes,
                                   "Class was not stored in 'homes' property.")
                        check.true(ExampleTest.test_1 in t.homes,
                                   "Method was not stored in 'homes' property.")
                        check.equal(t.method, ExampleTest.test_1)
                    # Just make sure this doesn't blow up...
                    repr(t)
                elif t.home == func1:
                    check.is_none(t.method)
コード例 #7
0
    def mc_artist_info(self):
        aid = 'Apoecs6off3y6k4h5nvqqos4b5e'  # amorphis
        optional_keys = set(('albums', 'topTracks', 'related_artists'))

        include_all_res = self.mc.get_artist_info(aid,
                                                  include_albums=True,
                                                  max_top_tracks=1,
                                                  max_rel_artist=1)

        no_albums_res = self.mc.get_artist_info(aid, include_albums=False)
        no_rel_res = self.mc.get_artist_info(aid, max_rel_artist=0)
        no_tracks_res = self.mc.get_artist_info(aid, max_top_tracks=0)

        with Check() as check:
            check.true(
                set(include_all_res.keys()) & optional_keys == optional_keys)

            check.true(
                set(no_albums_res.keys()) & optional_keys == optional_keys -
                {'albums'})
            check.true(
                set(no_rel_res.keys()) & optional_keys == optional_keys -
                {'related_artists'})
            check.true(
                set(no_tracks_res.keys()) & optional_keys == optional_keys -
                {'topTracks'})
コード例 #8
0
ファイル: snippets.py プロジェクト: viettelidc-oss/trove
def write_snippet(get_replace_list, client, name, url, method, status, reason,
                  func, *func_args):
    """
        'name' is the name of the file, while 'url,' 'method,' 'status,'
        and 'reason' are expected values that are asserted against.
        If func_args is present, it is a list of lists, each one of which
        is passed as the *args to the two invocations of "func".
        """
    func_args = func_args or []
    snippet_writer = SnippetWriter(conf, get_replace_list)
    results = []
    client.client.snippet_writer = snippet_writer
    client.client.name = name
    args = func_args
    result = func(client, *args)

    # Now write the snippet (if this happens earlier we can't replace
    # data such as the instance ID).
    client.client.write_snippet()
    with Check() as check:
        check.equal(client.client.old_info['url'], url)
        check.equal(client.client.old_info['method'], method)
        check.equal(client.client.old_info['response_headers'].status, status)
        check.equal(client.client.old_info['response_headers'].reason, reason)
    results.append(result)
    # To prevent this from writing a snippet somewhere else...
    client.client.name = "junk"

    return results
コード例 #9
0
 def test_single_failure_is_presented(self):
     try:
         with Check() as check:
             check.equal(4, 6)
         fail("Expected an assertion!")
     except ASSERTION_ERROR as ae:
         assert_true("4 != 6" in str(ae), str(ae))
コード例 #10
0
def create_dbaas_client(user):
    """Creates a rich client for the RedDwarf API using the test config."""
    auth_strategy = None

    kwargs = {
        'service_type': 'reddwarf',
        'insecure': test_config.values['reddwarf_client_insecure'],
    }

    def set_optional(kwargs_name, test_conf_name):
        value = test_config.values.get(test_conf_name, None)
        if value is not None:
            kwargs[kwargs_name] = value

    force_url = 'override_reddwarf_api_url' in test_config.values
    set_optional('auth_strategy', 'auth_strategy')
    set_optional('region_name', 'reddwarf_client_region_name')
    set_optional('service_url', 'override_reddwarf_api_url')

    dbaas = Dbaas(user.auth_user, user.auth_key, user.tenant,
                  test_config.reddwarf_auth_url, **kwargs)
    dbaas.authenticate()
    with Check() as check:
        check.is_not_none(dbaas.client.auth_token, "Auth token not set!")
        if not force_url and user.requirements.is_admin:
            expected_prefix = test_config.dbaas_url
            actual = dbaas.client.management_url
            msg = "Dbaas management url was expected to start with %s, but " \
                  "was %s." % (expected_prefix, actual)
            check.true(actual.startswith(expected_prefix), msg)
    return TestClient(dbaas)
コード例 #11
0
ファイル: example_generation.py プロジェクト: weizai118/trove
 def mgmt_get_account_details(self):
     results = self.clients.do("mgmt_get_account_details",
         "/mgmt/accounts/admin", "GET", 200, "OK",
         lambda client : client.mgmt.accounts.show("admin"))
     with Check() as check:
         for account_info in results:
             check.equal(2, len(account_info.instances))
             check.equal('admin', account_info.id)
コード例 #12
0
    def mc_search_aa_no_playlists(self):
        res = self.mc.search_all_access('amorphis', max_results=100)

        # TODO is there a search query that will consistently get playlist results?
        res.pop('playlist_hits')

        with Check() as check:
            for type_, hits in res.items():
                check.true(len(hits) > 0, "%s had %s hits, expected > 0" % (type_, len(hits)))
コード例 #13
0
        def assert_metadata_reverted(sid, orig_md):
            result_md = self._assert_get_song(sid)

            with Check() as check:
                for name in orig_md:
                    #If it's not volatile, it should be back to what it was.
                    if not md_expectations[name].volatile:
                        same, message = test_utils.md_entry_same(name, orig_md, result_md)
                        check.true(same, "failed to revert: " + message)
コード例 #14
0
ファイル: snippets.py プロジェクト: viettelidc-oss/trove
 def mgmt_get_account_details(self):
     results = self.snippet(
         "mgmt_get_account_details",
         "/mgmt/accounts/%s" % conf['normal_user_tenant'], "GET", 200, "OK",
         lambda client: client.mgmt.accounts.show(
             conf['normal_user_tenant'], ))
     with Check() as check:
         for account_info in results:
             check.equal(conf['normal_user_tenant'], account_info.id)
コード例 #15
0
    def mc_search_store_no_playlists(self):
        res = self.mc.search('morning', max_results=100)

        # TODO Playlist results are not returned consistently.
        res.pop('playlist_hits')

        with Check() as check:
            for type_, hits in res.items():
                check.true(len(hits) > 0, "%s had %s hits, expected > 0" % (type_, len(hits)))
コード例 #16
0
 def tear_down(self):
     """Tear down all instances."""
     with Check() as check:
         for instance in self._list_all():
             check.equal(
                 instance.status, "ACTIVE",
                 "Instance %s not active but is %s!" %
                 (instance.id, instance.status))
     self.delete_instances()
コード例 #17
0
    def mc_album_info(self):
        include_tracks = self.mc.get_album_info(TEST_STORE_ALBUM_ID, include_tracks=True)
        no_tracks = self.mc.get_album_info(TEST_STORE_ALBUM_ID, include_tracks=False)

        with Check() as check:
            check.true('tracks' in include_tracks)
            check.true('tracks' not in no_tracks)

            del include_tracks['tracks']
            check.equal(include_tracks, no_tracks)
コード例 #18
0
ファイル: snippets.py プロジェクト: grze/trove
 def mgmt_get_host_detail(self):
     results = self.snippet(
         "mgmt_get_host_detail", "/mgmt/hosts/fake_host_1", "GET", 200,
         "OK", lambda client: client.mgmt.hosts.get("fake_host_1"))
     with Check() as check:
         for host in results:
             check.equal(results[0].name, "fake_host_1")
             # XML entries won't come back as these types. :(
             check.true(isinstance(results[0].percentUsed, int)),
             check.true(isinstance(results[0].totalRAM, int)),
             check.true(isinstance(results[0].usedRAM, int)),
     with Check() as check:
         for host in results:
             check.equal(1, len(host.instances))
             for instance in host.instances:
                 check.equal(instance['status'], 'ACTIVE')
                 check.true(isinstance(instance['name'], basestring))
                 check.true(isinstance(instance['id'], basestring))
                 check.true(isinstance(instance['server_id'], basestring))
                 check.true(isinstance(instance['tenant_id'], basestring))
コード例 #19
0
ファイル: example_generation.py プロジェクト: weizai118/trove
 def mgmt_list_hosts(self):
     results = self.clients.do("mgmt_list_hosts",
         "/mgmt/hosts", "GET", 200, "OK",
         lambda client : client.mgmt.hosts.index())
     with Check() as check:
         for hosts in results:
             check.equal(1, len(hosts))
             check.equal("fake_host", hosts[0].name)
         check.equal(2, results[0][0].instanceCount)
         # In XML land this is a string. :'(
         check.equal("2", results[1][0].instanceCount)
コード例 #20
0
ファイル: usage.py プロジェクト: luccacabra/trove
 def check_message(self, resource_id, event_type, **attrs):
     messages = self.get_messages(resource_id)
     print("%s %s" % (messages, resource_id))
     found = None
     for message in messages:
         if message['event_type'] == event_type:
             found = message
     assert_not_equal(found, None)
     with Check() as check:
         for key, value in attrs.iteritems():
             check.equal(found[key], value)
コード例 #21
0
    def mc_podcast_series_info(self):
        optional_keys = {'episodes'}

        include_episodes = self.mc.get_podcast_series_info(TEST_PODCAST_SERIES_ID, max_episodes=1)
        no_episodes = self.mc.get_podcast_series_info(TEST_PODCAST_SERIES_ID, max_episodes=0)

        with Check() as check:
            check.true(set(include_episodes.keys()) & optional_keys == optional_keys)

            check.true(set(no_episodes.keys()) & optional_keys ==
                       optional_keys - {'episodes'})
コード例 #22
0
def mm_prevents_bad_mac_format():
    mm = create_clients().musicmanager

    with Check() as check:
        for bad_mac in [
                'bogus', '11:22:33:44:55:66:', '11:22:33:44:55:ab',
                '11:22:33:44:55'
        ]:
            check.raises(ValueError,
                         mm._perform_upauth,
                         uploader_id=bad_mac,
                         uploader_name='valid')
コード例 #23
0
 def test_multiple_failures_are_presented(self):
     try:
         with Check() as c:
             c.equal(2, 27)
             c.equal("BEE", "BEE")
             c.equal(39, 37)
             c.equal("CAT", "RAT")
         fail("Expected an assertion!")
     except ASSERTION_ERROR as ae:
         msg = str(ae)
         assert_true("2 != 27" in msg, msg)
         assert_true("39 != 37" in msg, msg)
         assert_true("'CAT' != 'RAT'" in msg, msg)
コード例 #24
0
ファイル: snippets.py プロジェクト: viettelidc-oss/trove
    def mgmt_list_hosts(self):
        results = self.snippet("mgmt_list_hosts", "/mgmt/hosts", "GET", 200,
                               "OK", lambda client: client.mgmt.hosts.index())

        with Check() as check:
            for hosts in results:
                check.equal(2, len(hosts))
                check.true("fake_host_1" == hosts[0].name
                           or "fake_host_1" == hosts[1].name)
                check.true("fake_host_2" == hosts[0].name
                           or "fake_host_2" == hosts[1].name)
                check.true(1 == results[0][1].instanceCount
                           or 1 == results[0][0].instanceCount)
コード例 #25
0
    def mc_search_store_no_playlists(self):
        res = self.mc.search('morning', max_results=100)

        # TODO Playlist results are not returned consistently.
        res.pop('playlist_hits')

        with Check() as check:
            for type_, hits in res.items():
                if ((not test_subscription_features() and
                     type_ in ('artist_hits', 'song_hits', 'album_hits'))):
                    # These results aren't returned for non-sub accounts.
                    check.true(len(hits) == 0, "%s had %s hits, expected 0" % (type_, len(hits)))
                else:
                    check.true(len(hits) > 0, "%s had %s hits, expected > 0" % (type_, len(hits)))
コード例 #26
0
 def test_when_failures_and_an_error_occurs(self):
     try:
         with Check() as c:
             c.equal(2, 27)
             c.equal("BEE", "BEE")
             c.equal(39, 37)
             raise RuntimeError("Unexplained error!")
             c.equal("CAT", "RAT")  # This is never reached.
     except ASSERTION_ERROR as ae:
         msg = str(ae)
         assert_true("2 != 27" in msg, msg)
         assert_true("39 != 37" in msg, msg)
         assert_false("CAT != RAT" in msg, msg)
         assert_true("RuntimeError: Unexplained error!" in msg, msg)
コード例 #27
0
    def song_delete(self):
        # split deletion between wc and mc
        # mc is only to run if subscription testing not enabled
        with Check() as check:
            for i, testsong in enumerate(self.all_songs):
                if True:
                    res = self.mc.delete_songs(testsong.sid)
                else:
                    with warnings.catch_warnings():
                        warnings.simplefilter("ignore")
                        res = self.wc.delete_songs(testsong.sid)
                check.equal(res, [testsong.sid])

        self.assert_songs_state(self.mc.get_all_songs, sids(self.all_songs), present=False)
コード例 #28
0
    def song_delete(self):
        # split deletion between wc and mc
        # mc is the only to run if AA testing not enabled
        with Check() as check:
            for i, testsong in enumerate(self.all_songs):
                if i % 2 == 0:
                    res = self.mc.delete_songs(testsong.sid)
                else:
                    res = self.wc.delete_songs(testsong.sid)
                check.equal(res, [testsong.sid])

        self.assert_songs_state(self.mc.get_all_songs,
                                sids(self.all_songs),
                                present=False)
        self.assert_list_with_deleted(self.mc.get_all_songs)
コード例 #29
0
    def song_delete(self):
        if self.songs is None:
            raise SkipTest('did not store self.songs')

        # split deletion between wc and mc
        # mc is the only to run if AA testing not enabled
        with Check() as check:
            for i, testsong in enumerate(self.songs):
                if i % 2 == 0:
                    res = self.mc.delete_songs(testsong.sid)
                else:
                    res = self.wc.delete_songs(testsong.sid)
                check.equal(res, [testsong.sid])

        self.assert_songs_state([s.sid for s in self.songs], present=False)
        self.assert_list_with_deleted(self.mc.get_all_songs)
コード例 #30
0
        def assert_metadata_is(sid, orig_md, correct_dependent_md):
            result_md = self._assert_get_song(sid)

            with Check() as check:
                for name, expt in md_expectations.items():
                    if name in orig_md:
                        #TODO really need to factor out to test_utils?

                        #Check mutability if it's not volatile or dependent.
                        if not expt.volatile and expt.depends_on is None:
                            same, message = test_utils.md_entry_same(name, orig_md, result_md)
                            check.equal(not expt.mutable, same,
                                        "metadata mutability incorrect: " + message)

                        #Check dependent md.
                        if expt.depends_on is not None:
                            same, message = test_utils.md_entry_same(
                                name, correct_dependent_md, result_md
                            )
                            check.true(same, "dependent metadata incorrect: " + message)