コード例 #1
0
    def test_get_ownerships(self):

        # There should be no ownerships declared on the spec.
        ownerships = _db_get_ownerships("http://justatest.com")
        assert len(ownerships) == 0

        # We now declare 1 ownership.
        _db_declare_ownership(self.tapp, "test_TEST")
        ownerships = _db_get_ownerships("http://justatest.com")
        assert len(ownerships) == 1

        # We now create a second app for further testing.
        app2 = api.create_app("UTApp2", "translate", "{'spec':'http://justatest.com'}")
        api.add_var(app2, "spec", "http://justatest.com")

        # Ensure we still have 1 ownership.
        ownerships = _db_get_ownerships("http://justatest.com")
        assert len(ownerships) == 1

        # Add a second ownership for another language.
        _db_declare_ownership(app2, "testen_TESTEN")
        ownerships = _db_get_ownerships("http://justatest.com")
        assert len(ownerships) == 2

        # Ensure that the ownerships are right.
        firstOwnership = next(o for o in ownerships if o.value == "test_TEST")
        assert firstOwnership.app == self.tapp
        secondOwnership = next(o for o in ownerships if o.value == "testen_TESTEN")
        assert secondOwnership.app == app2
コード例 #2
0
ファイル: api_publish.py プロジェクト: zstars/appcomposer
def app_translation_serve_list():
    """
    Serves a list of translated apps, so that a cache can be updated.
    Aims to be SHINDIG-compatible, though it doesn't implement this feature yet.

    This is the new version (for the new ownership system). It is somewhat inefficient
    and the current etag scheme doesn't make much sense anymore.
    """

    # Get a list of distinct XMLs.
    specs = _db_get_diff_specs()

    output = {}

    for spec in specs:
        # For each spec we get the ownerships.
        ownerships = _db_get_ownerships(spec)

        bundles = []

        for ownership in ownerships:
            lang = ownership.value
            bm = BundleManager.create_from_existing_app(ownership.app.data)
            keys = [key for key in bm._bundles.keys() if BundleManager.fullcode_to_partialcode(key) == lang]

            etag = str(ownership.app.modification_date)
            bundles.append({"keys": keys, "etag": etag})

        output[spec] = {"bundles": bundles}

    response = make_response(json.dumps(output, indent=True))
    response.mimetype = "application/json"
    return response
コード例 #3
0
    def test_conflicting_composer(self):
        """
        Check that there is no mistake when there is a conflicting composer using the same appvar names.
        """
        # We now declare 1 ownership.
        _db_declare_ownership(self.tapp, "test_TEST")
        ownerships = _db_get_ownerships("http://justatest.com")
        assert len(ownerships) == 1

        # We now create a non-translate app.
        app2 = api.create_app("UTApp2", "dummy", "http://justatest.com", "{'spec':'http://justatest.com'}")
        api.add_var(app2, "ownership", "test_TEST")

        # Make sure that even though we added an ownership on an app with the same spec, it won't be
        # taken into account because it is a DUMMY and not a TRANSLATE composer.
        assert len(ownerships) == 1
コード例 #4
0
    def test_transfer_ownership(self):
        """
        Tests the method to transfer ownership.
        """
        # We now declare 1 ownership.
        _db_declare_ownership(self.tapp, "test_TEST")
        ownerships = _db_get_ownerships("http://justatest.com")
        assert len(ownerships) == 1
        # We now create a second app for further testing.
        app2 = api.create_app("UTApp2", "translate", "http://justatest.com", "{'spec':'http://justatest.com'}")

        # We transfer the ownership to the second app.
        _db_transfer_ownership("test_TEST", self.tapp, app2)

        # Verify that the ownership has indeed been transferred..
        owner = _db_get_lang_owner_app("http://justatest.com", "test_TEST")
        assert owner == app2
コード例 #5
0
ファイル: view_selectlang.py プロジェクト: zstars/appcomposer
def do_languages_initial_merge(app, bm):
    """
    Carries out an initial merge. Bundles from the language-owners are merged into the
    app.
    @param app: Target app. App into which the bundles of each language owner are merged.
    @param bm: Target BundleManager. Bundle manager into which the bundles of each language owner are merged.
    @note: The App's data is updated automatically to reflect the new merge.
    """

    # Retrieve every single "owned" App for that xmlspec.
    ownerships = _db_get_ownerships(bm.get_gadget_spec())

    for ownership in ownerships:
        language = ownership.value
        ownerapp = ownership.app
        bm.merge_language(language, ownerapp)

    update_app_data(app, bm.to_json())