Example #1
1
def test_last_child_exclude_pseudo():
    html = """<html>
    <head>
    <style type="text/css">
    div {
        text-align: right;
    }
    div:last-child {
        text-align: left;
    }
    </style>
    </head>
    <body>
    <div>First child</div>
    <div>Last child</div>
    </body>
    </html>"""

    expect_html = """<html>
    <head>
    </head>
    <body>
    <div style="text-align:right" align="right">First child</div>
    <div style="text-align:left" align="left">Last child</div>
    </body>
    </html>"""

    p = Premailer(html, exclude_pseudoclasses=True)
    result_html = p.transform()

    expect_html = whitespace_between_tags.sub("><", expect_html).strip()
    result_html = whitespace_between_tags.sub("><", result_html).strip()

    eq_(expect_html, result_html)
Example #2
1
 def test_lite_to_unreviewed(self):
     upload = self.upload("extension")
     d = parse_addon(upload.path)
     self.addon.update(status=amo.STATUS_LITE)
     eq_(self.addon.status, amo.STATUS_LITE)
     f = File.from_upload(upload, self.version, self.platform, parse_data=d)
     eq_(f.status, amo.STATUS_UNREVIEWED)
 def test_aurora_android_releasenotes_url(self, mock_reverse):
     """
     Should return the results of reverse with the correct args
     """
     release = Release(channel="Aurora", version="42.0a2", product="Firefox for Android")
     eq_(misc.releasenotes_url(release), mock_reverse.return_value)
     mock_reverse.assert_called_with("firefox.android.releasenotes", args=("42.0a2", "aurora"))
Example #4
1
 def test_edit_collection_category(self):
     self.make_publisher()
     eq_(Category.objects.count(), 0)
     # Invalid (non-existant) category.
     updates = {"category": 1}
     res, data = self.edit_collection(self.client, **updates)
     eq_(res.status_code, 400)
Example #5
1
 def test_corrupt_locale_browser_path(self, extract_path):
     extract_path.return_value = "locale browser de woot?!"
     obj = self.file_create("langpack-localepicker")
     eq_(obj.get_localepicker(), "")
     extract_path.return_value = "locale browser de woo:t?!as"
     # Result should be 'locale browser de woo:t?!as', but we have caching.
     eq_(obj.get_localepicker(), "")
Example #6
1
 def test_no_reviews_premium_no_add_review_link(self):
     # Ensure no 'Review this App' link for non-purchased premium apps.
     self.enable_waffle()
     Review.objects.all().delete()
     self.webapp.update(premium_type=amo.ADDON_PREMIUM)
     r = self.client.get(self.detail)
     eq_(pq(r.content)("#add-first-review").length, 0)
Example #7
1
    def test_CrashPairsByCrashId(self, rget):
        url = reverse("api:model_wrapper", args=("CrashPairsByCrashId",))
        response = self.client.get(url)
        eq_(response.status_code, 400)
        dump = json.loads(response.content)
        ok_(dump["errors"]["uuid"])
        ok_(dump["errors"]["hang_id"])

        def mocked_get(url, **options):
            return Response(
                """
              {
                "hits": [{"guess": "work"}],
                "total": 1
              }
            """
            )
            raise NotImplementedError(url)

        rget.side_effect = mocked_get

        response = self.client.get(url, {"uuid": "123", "hang_id": "987"})
        eq_(response.status_code, 200)
        dump = json.loads(response.content)
        ok_(dump["hits"])
        ok_(dump["total"])
Example #8
0
 def test_not_rated(self):
     # We don't have any reviews, and I'm not allowed to submit a review.
     self.enable_waffle()
     Review.objects.all().delete()
     self.log_in_dev()
     r = self.client.get(self.detail)
     eq_(pq(r.content)(".not-rated").length, 1)
Example #9
0
    def test_CommentsBySignature(self, rget):
        url = reverse("api:model_wrapper", args=("CommentsBySignature",))
        response = self.client.get(url)
        eq_(response.status_code, 400)
        dump = json.loads(response.content)
        ok_(dump["errors"]["signature"])

        def mocked_get(url, **options):
            if "crashes/comments" in url:
                return Response(
                    """
                {
                  "hits": [
                   {
                     "user_comments": "This is a comment",
                     "date_processed": "2012-08-21T11:17:28-07:00",
                     "email": "some@emailaddress.com",
                     "uuid": "469bde48-0e8f-3586-d486-b98810120830"
                    }
                  ],
                  "total": 1
                }
              """
                )
            raise NotImplementedError(url)

        rget.side_effect = mocked_get

        response = self.client.get(url, {"signature": "one & two"})
        eq_(response.status_code, 200)
        dump = json.loads(response.content)
        ok_(dump["hits"])
        ok_(dump["total"])
Example #10
0
 def test_Platforms(self, rget):
     url = reverse("api:model_wrapper", args=("Platforms",))
     response = self.client.get(url)
     eq_(response.status_code, 200)
     dump = json.loads(response.content)
     ok_(dump[0]["code"])
     ok_(dump[0]["name"])
Example #11
0
    def test_CORS(self, rget):
        """any use of model_wrapper should return a CORS header"""

        def mocked_get(url, **options):
            return Response(
                """
                {
                  "breakpad_revision": "1139",
                  "hits": [
                    {
                      "date_oldest_job_queued": null,
                      "date_recently_completed": null,
                      "processors_count": 1,
                      "avg_wait_sec": 0.0,
                      "waiting_job_count": 0,
                      "date_created": "2013-04-01T21:40:01+00:00",
                      "id": 463859,
                      "avg_process_sec": 0.0
                    }
                  ],
                  "total": 12,
                  "socorro_revision": "9cfa4de"
                }
            """
            )

        rget.side_effect = mocked_get

        url = reverse("api:model_wrapper", args=("Status",))
        response = self.client.get(url)
        eq_(response.status_code, 200)
        eq_(response["Access-Control-Allow-Origin"], "*")
Example #12
0
    def test_share_count(self):
        addon = Addon.objects.get(id=3615)

        eq_(addon.share_counts[TWITTER.shortname], 29)

        # total count with no shares
        eq_(addon.share_counts[FACEBOOK.shortname], 0, "Total count with no shares must be 0")
Example #13
0
def test_prefer_inline_to_class():
    html = """<html>
    <head>
    <style>
    .example {
        color: black;
    }
    </style>
    </head>
    <body>
    <div class="example" style="color:red"></div>
    </body>
    </html>"""

    expect_html = """<html>
    <head>
    </head>
    <body>
    <div style="color:red"></div>
    </body>
    </html>"""

    p = Premailer(html)
    result_html = p.transform()

    expect_html = whitespace_between_tags.sub("><", expect_html).strip()
    result_html = whitespace_between_tags.sub("><", result_html).strip()

    eq_(expect_html, result_html)
Example #14
0
def test_doctype():
    html = (
        '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
        '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
        """<html>
        <head>
        </head>
        <body>
        </body>
        </html>"""
    )

    expect_html = (
        '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
        '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
        """<html>
        <head>
        </head>
        <body>
        </body>
        </html>"""
    )

    p = Premailer(html)
    result_html = p.transform()

    expect_html = whitespace_between_tags.sub("><", expect_html).strip()
    result_html = whitespace_between_tags.sub("><", result_html).strip()

    eq_(expect_html, result_html)
Example #15
0
def test_child_selector():
    html = """<html>
    <head>
    <style type="text/css">
    body > div {
        text-align: right;
    }
    </style>
    </head>
    <body>
    <div>First div</div>
    </body>
    </html>"""

    expect_html = """<html>
    <head>
    </head>
    <body>
    <div style="text-align:right" align="right">First div</div>
    </body>
    </html>"""

    p = Premailer(html)
    result_html = p.transform()

    expect_html = whitespace_between_tags.sub("><", expect_html).strip()
    result_html = whitespace_between_tags.sub("><", result_html).strip()

    eq_(expect_html, result_html)
Example #16
0
 def test_premium_no_add_review_link_visitor(self):
     # Check for no review link for premium apps for non-logged user.
     self.enable_waffle()
     self.client.logout()
     self.webapp.update(premium_type=amo.ADDON_PREMIUM)
     r = self.client.get(self.detail)
     eq_(pq(r.content)("#add-first-review").length, 0)
Example #17
0
 def test_premium_add_review_link(self):
     # Check for review link for owners of purchased premium apps.
     self.enable_waffle()
     self.webapp.addonpurchase_set.create(user=self.user)
     self.webapp.update(premium_type=amo.ADDON_PREMIUM)
     r = self.client.get(self.detail)
     eq_(pq(r.content)("#add-first-review").length, 1)
Example #18
0
    def test_basic_stage(self):
        res = self._test_url(self.iframe_install_url)
        allowed_origins = json.loads(res.context["allowed_origins"])
        self._test_trailing_slashes(allowed_origins)
        eq_(
            allowed_origins,
            [
                "app://packaged.marketplace.allizom.org",
                "app://marketplace.allizom.org",
                "https://marketplace.allizom.org",
                "app://tarako.marketplace.allizom.org",
                "https://hello.firefox.com",
                "https://call.firefox.com",
            ],
        )

        res = self._test_url(self.potatolytics_url)
        allowed_origins = json.loads(res.context["allowed_origins"])
        self._test_trailing_slashes(allowed_origins)
        eq_(
            allowed_origins,
            [
                "app://packaged.marketplace.allizom.org",
                "app://marketplace.allizom.org",
                "https://marketplace.allizom.org",
                "app://tarako.marketplace.allizom.org",
            ],
        )
Example #19
0
 def test_review_link_plural(self):
     # We have reviews.
     self.enable_waffle()
     self.webapp.update(total_reviews=2)
     r = self.client.get(self.detail)
     total = numberfmt(self.webapp.total_reviews)
     eq_(pq(r.content)(".average-rating").text(), "Rated 4 out of 5 stars 2 reviews")
Example #20
0
 def test_transonic(self, mock_fxa):
     mock_fxa.return_value = ("fakestate", "http://example.com/fakeauthurl")
     res = self._test_url("/curate/")
     self.assertTemplateUsed(res, "commonplace/index.html")
     self.assertEquals(res.context["repo"], "transonic")
     self.assertNotContains(res, "splash.css")
     eq_(res["Cache-Control"], "max-age=180")
Example #21
0
def test_rm_stdin(stderr, stdout):
    with HTTMock(service_rm):
        tool = get_tool("rm")
        server = Server("localhost")
        status = tool.execute(server, ["rm"])
        eq_(0, status)
        eq_("/content/path/node\n", stdout.getvalue())
Example #22
0
 def test_composer_tool_install_latest(self):
     ctx = utils.FormattedDict(
         {
             "PHP_VM": "will_default_to_php_strategy",
             "BUILD_DIR": "/build/dir",
             "CACHE_DIR": "/cache/dir",
             "COMPOSER_VERSION": "latest",
             "BP_DIR": "",
             "WEBDIR": "",
         }
     )
     builder = Dingus(_ctx=ctx)
     installer = Dingus()
     cfInstaller = Dingus()
     builder.install = Dingus(_installer=cfInstaller, return_value=installer)
     ct = self.extension_module.ComposerExtension(ctx)
     ct._builder = builder
     ct.install()
     eq_(2, len(builder.install.calls()))
     # make sure PHP is installed
     assert installer.package.calls().once()
     eq_("PHP", installer.package.calls()[0].args[0])
     call = installer.package.calls()[0]
     assert call.return_value.calls().once()
     assert installer.calls().once()
     # make sure composer is installed
     assert installer._installer.calls().once()
     assert installer._installer.calls()[0].args[0] == "https://getcomposer.org/composer.phar", (
         "was %s" % installer._installer.calls()[0].args[0]
     )
Example #23
0
    def create_additional_data(self):
        self.category = Category.objects.create(slug="ccc", name="CatCatCat", type=amo.ADDON_WEBAPP)
        self.empty_category = Category.objects.create(slug="emptycat", name="Empty Cat", type=amo.ADDON_WEBAPP)
        eq_(Category.objects.count(), 2)

        collection_data = {
            "collection_type": COLLECTIONS_TYPE_BASIC,
            "description": "A collection of my favorite spanish games",
            "name": "My Favorite spanish games",
            "region": mkt.regions.SPAIN.id,
            "carrier": mkt.carriers.UNKNOWN_CARRIER.id,
        }
        self.collection2 = Collection.objects.create(**collection_data)

        collection_data = {
            "collection_type": COLLECTIONS_TYPE_BASIC,
            "description": "A collection of my favorite phone games",
            "name": "My Favorite phone games",
            "carrier": mkt.carriers.TELEFONICA.id,
        }
        self.collection3 = Collection.objects.create(**collection_data)

        collection_data = {
            "collection_type": COLLECTIONS_TYPE_BASIC,
            "description": "A collection of my favorite categorized games",
            "name": "My Favorite categorized games",
            "region": mkt.regions.SPAIN.id,
            "carrier": mkt.carriers.TELEFONICA.id,
            "category": self.category,
        }
        self.collection4 = Collection.objects.create(**collection_data)
Example #24
0
def test_users_list():
    u1 = UserProfile(username="jconnor", display_name="John Connor", pk=1)
    u2 = UserProfile(username="sconnor", display_name="Sarah Connor", pk=2)
    eq_(users_list([u1, u2]), ", ".join((user_link(u1), user_link(u2))))

    # handle None gracefully
    eq_(user_link(None), "")
Example #25
0
 def test_trusted_public_to_beta(self):
     upload = self.upload("beta-extension")
     d = parse_addon(upload.path)
     self.addon.update(status=amo.STATUS_PUBLIC, trusted=True)
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     f = File.from_upload(upload, self.version, self.platform, is_beta=True, parse_data=d)
     eq_(f.status, amo.STATUS_BETA)
Example #26
0
def test_user_link_unicode():
    """make sure helper won't choke on unicode input"""
    u = UserProfile(username=u"jmüller", display_name=u"Jürgen Müller", pk=1)
    eq_(user_link(u), u'<a href="%s" title="%s">Jürgen Müller</a>' % (u.get_url_path(), u.name))

    u = UserProfile(username="\xe5\xaf\x92\xe6\x98\x9f", pk=1)
    eq_(user_link(u), u'<a href="%s" title="%s">%s</a>' % (u.get_url_path(), u.name, u.username))
Example #27
0
 def test_trusted_lite_to_lite(self):
     upload = self.upload("extension")
     d = parse_addon(upload.path)
     self.addon.update(status=amo.STATUS_LITE, trusted=True)
     eq_(self.addon.status, amo.STATUS_LITE)
     f = File.from_upload(upload, self.version, self.platform, parse_data=d)
     eq_(f.status, amo.STATUS_LITE)
Example #28
0
 def test_can_review_purchased(self):
     self.webapp.addonpurchase_set.create(user=self.user)
     self.webapp.update(premium_type=amo.ADDON_PREMIUM)
     data = {"body": "x", "rating": 1}
     eq_(self.client.get(self.add, data).status_code, 200)
     r = self.client.post(self.add, data)
     self.assertRedirects(r, self.webapp.get_ratings_url("list"), status_code=302)
 def test_desktop_releasenotes_url(self, mock_reverse):
     """
     Should return the results of reverse with the correct args
     """
     release = Release(version="42.0", product="Firefox")
     eq_(misc.releasenotes_url(release), mock_reverse.return_value)
     mock_reverse.assert_called_with("firefox.desktop.releasenotes", args=("42.0", "release"))
Example #30
0
def test_inline_wins_over_external():
    html = """<html>
    <head>
    <style type="text/css">
    div {
        text-align: left;
    }
    /* This tests that a second loop for the same style still doesn't
     * overwrite it. */
    div {
        text-align: left;
    }
    </style>
    </head>
    <body>
    <div style="text-align:right">Some text</div>
    </body>
    </html>"""

    expect_html = """<html>
    <head>
    </head>
    <body>
    <div style="text-align:right" align="right">Some text</div>
    </body>
    </html>"""

    p = Premailer(html)
    result_html = p.transform()

    expect_html = whitespace_between_tags.sub("><", expect_html).strip()
    result_html = whitespace_between_tags.sub("><", result_html).strip()

    eq_(expect_html, result_html)