Exemple #1
0
    def test_its_real(self):
        assert UserPage.count() == 0

        UserPage.bootstrap_user_page(user="******", widgets=["bubbles"])

        result = UserPage.last()
        assert result["widgets"] == {"bubbles": True}
Exemple #2
0
    def route(self):
        self.url_parser = SoundeffectRequestParser(self.user,
                                                   self.args).parse()

        if self.command == "css":
            return self.set_css()

        if self.command == "js":
            return self.set_js()

        if self.command == "approvejs" and self.user in STREAM_LORDS:
            return self.approve_js()

        if self.command == "buyjs":
            return self.buy_js()

        if self.command == "deactivate" or self.command == "removejs":
            js_to_deactivate = self.args[0]
            UserPage.deactivate(self.user, js_to_deactivate)
            return f"Attempting to remove: {js_to_deactivate}"

        if self.command == "activate" or self.command == "addjs":
            js_to_add = self.args[0]
            UserPage.activate(self.user, js_to_add)
            return f"Attempting to Reactivate: {js_to_add}"
    def test_deactivate_widgets(self):
        UserCode(
            user="******",
            code_link="https://gitlab.com/real_url/raw/bubbles.js",
            code_type="js",
            owners=["future"],
            approved=True,
        ).save()

        UserCode(
            user="******",
            code_link="https://gitlab.com/real_url/raw/fun.js",
            code_type="js",
            owners=["future"],
            approved=False,
        ).save()

        UserPage.bootstrap_user_page("future", ["bubbles", "fun"])
        UserPage.deactivate("future", "fun")
        result = UserCode.js_for_user("future")
        assert result == {
            "approved": ["bubbles.js"],
            "unapproved": ["fun.js"],
            "deactivated": ["fun.js"],
        }
    def test_deactivate_js(self):
        user_code = UserCode(
            user="******",
            code_link="https://gitlab.com/real_url/beginwidget.js",
            code_type="js",
            approved=True,
            owners=["beginbotbot"],
        ).save()
        UserPage.bootstrap_user_page(user="******",
                                     widgets=["beginwidget"])

        result = UserCodeRouter("beginbotbot", "deactivate",
                                ["beginwidget"]).route()
        user_page = UserPage.for_user("beginbotbot")
        assert user_page["widgets"] == {"beginwidget": False}
Exemple #5
0
    def route(self):
        if self.command == "css":
            return self.set_css()

        if self.command == "js":
            return self.set_js()

        if self.command == "approvejs" and self.user == "beginbotbot":
            return self.approve_js()

        if self.command == "buyjs":
            return self.buy_js()

        if self.command == "deactivate" or self.command == "removejs":
            js_to_deactivate = self.args[0]
            UserPage.deactivate(self.user, js_to_deactivate)
            return f"Attempting to remove: {js_to_deactivate}"

        if self.command == "activate" or self.command == "addjs":
            js_to_add = self.args[0]
            UserPage.activate(self.user, js_to_add)
            return f"Attempting to Reactivate: {js_to_add}"
    def js_for_user(cls, user):
        def is_owned_by(user_code):
            return user in user_code.get("owners", []) or user_code["user"] == user

        results = cls.db().search(is_owned_by)
        owned_by = {"approved": [], "unapproved": [], "deactivated": []}

        for result in results:
            if result.get("approved", False):
                owned_by["approved"].append(f"{result['name']}.js")
            else:
                owned_by["unapproved"].append(f"{result['name']}.js")

        user_page = UserPage.for_user(user)
        if user_page:
            widgets = user_page["widgets"]
            if widgets:
                deactivated = [
                    f"{widget}.js" for (widget, active) in widgets.items() if not active
                ]
            owned_by["deactivated"] = deactivated
        return owned_by
Exemple #7
0
 def test_for_user(self):
     UserPage.bootstrap_user_page(user="******", widgets=["bubbles"])
     user_page = UserPage.for_user("eno")
     assert user_page["widgets"] == {"bubbles": True}
Exemple #8
0
 def test_deactivating(self):
     UserPage.bootstrap_user_page(user="******", widgets=["bubbles"])
     result = UserPage.deactivate("eno", "bubbles")
     user_page = UserPage.last()
     assert user_page["widgets"] == {"bubbles": False}