def test_dev_leaderboard(self):
        UserCode(
            user="******",
            code_link="https://gitlab.com/real_url/raw/circuswire.js",
            code_type="js",
            owners=["future", "uzi"],
            approved=True,
        ).save()

        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/thetwin.js",
            code_type="js",
            owners=["future", "uzi", "wharf"],
            approved=True,
        ).save()

        result = UserCode.dev_leaderboard()
        assert result == [("richard", 3), ("satie", 2), ("eno", 1)]
Exemple #2
0
    def set_js(self):
        if len(self.args) == 1:
            custom_js = self.args[0]
            user_code = UserCode(user=self.user,
                                 code_link=custom_js,
                                 code_type="js").update_or_create()
        else:
            widget_name = self.args[0]
            custom_js = self.args[1]
            user_code = UserCode(user=self.user,
                                 code_link=custom_js,
                                 code_type="js",
                                 name=widget_name).update_or_create()

        # Switch to NOT USE requests
        response = requests.get(custom_js)

        new_js_dir = Path(__file__).parent.parent.joinpath(f"js")
        new_js_dir.mkdir(exist_ok=True)

        new_js_path = new_js_dir.joinpath(f"{user_code._name}.js")
        print(f"Saving Custom js for @{self.user} {new_js_path}")

        with open(new_js_path, "w") as f:
            f.write(response.text)

        return f"Thanks for the custom JS @{self.user}!"
    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_owned_by(self):
        UserCode(
            user="******",
            code_link="https://gitlab.com/real_url/raw/bubbles.js",
            code_type="js",
            approved=False,
        ).save()

        assert UserCode.owned_by("eno") == ["bubbles.js"]
Exemple #5
0
async def generate_widgets_page(winner):
    widgets = UserCode.all()
    dev_leaderboard = UserCode.dev_leaderboard()

    context = {
        "base_url": DEPLOY_URL,
        "widgets": widgets,
        "winner": winner,
        "dev_leaderboard": dev_leaderboard,
    }
    await _render_and_save_html("widgets.html", context, "widgets.html")
 def test_buy_js(self):
     user_code = UserCode(
         user="******",
         code_link="https://gitlab.com/real_url/beginwidget.js",
         code_type="js",
         approved=True,
     ).save()
     result = UserCodeRouter("beginbotbot", "buyjs",
                             ["beginwidget"]).route()
     assert result == "@beginbotbot bought beginwidget.js from @eno!"
     assert UserCode.find_owners("beginwidget") == ["eno", "beginbotbot"]
    def test_extracing_name_from_url(self):
        UserCode(
            user="******", code_link="https://gitlab.com/real_url/raw", code_type="js",
        ).save()

        last = UserCode.last()
        assert last["approved"] == False
        assert last["name"] == "eno"
        assert last["owners"] == []

        assert UserCode.owned_by("eno") == ["eno.js"]
    def _user_data(self):
        results = []

        # Iterate through each user
        for user_dict in self._all_users:

            widgets = UserCode.js_for_user(user_dict["name"])
            user_dict["widgets"] = widgets

            # Looking for Matching Soundeffects
            matching_effects = [
                sfx
                for sfx in self._all_sfxs
                if user_dict["name"] == sfx.name[: -len(sfx.suffix)]
            ]
            if matching_effects:
                command_file = matching_effects[0]
                user_dict["command_file"] = command_file.name

            if user_dict["name"] in self.command_users:
                command_info = self.command_users[user_dict["name"]]["commands"]
                total_propery_value = sum([command["cost"] for command in command_info])
                user_dict["wealth"] = user_dict.get("cool_points", 0) + total_propery_value

            # This small change to have all the command info
            user_dict["commands"] = [
                cmd
                for cmd in self._all_cmds
                if user_dict["name"] in cmd["permitted_users"]
            ]

            user_dict["sfx_count"] = len(user_dict["commands"])

            results.append(user_dict)
        return list(reversed(sorted(results, key=lambda user: user.get("wealth", 0))))
 def test_approving_js(self):
     UserCode(
         user="******",
         code_link=
         "https://gist.githubusercontent.com/davidbegin/raw/beginfun.js",
         code_type="js",
     ).save()
     result = UserCodeRouter("beginbotbot", "approvejs",
                             ["beginfun"]).route()
     assert "@beginbotbot's beginfun.js has been approved!" in result
    def test_updating_js(self):
        user = "******"
        result = UserCodeRouter(
            user,
            "js",
            ["https://gist.githubusercontent.com/davidbegin/raw/beginfun.js"],
        ).route()
        assert UserCode.count() == 1

        UserCode.approve(user, "beginfun")
        user_code = UserCode.last()
        assert user_code["approved"] == True

        result = UserCodeRouter(
            user,
            "js",
            [
                "https://gist.githubusercontent.com/davidbegin/raw/234232342/beginfun.js"
            ],
        ).route()
        assert UserCode.count() == 1
        user_code = UserCode.last()
        assert user_code["user"] == "beginbotbot"
        assert user_code["approved"] == True
        assert (
            user_code["code_link"] ==
            "https://gist.githubusercontent.com/davidbegin/raw/234232342/beginfun.js"
        )
        assert user_code["code_type"] == "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}
    def test_submit_custom_js(self):
        user = "******"
        result = UserCodeRouter(
            user,
            "js",
            ["https://gist.githubusercontent.com/davidbegin/raw"],
        ).route()
        assert "Thanks for the custom JS @beginbotbot!" in result

        js_filepath = Path(__file__).parent.parent.parent.joinpath(
            "chat_thief/js/beginbotbot.js")
        assert js_filepath.exists()
        user_code = UserCode.last()
        assert user_code["user"] == "beginbotbot"
        assert (user_code["code_link"] ==
                "https://gist.githubusercontent.com/davidbegin/raw")
        assert user_code["code_type"] == "js"
    def test_user_code(self):
        assert UserCode.count() == 0

        UserCode(
            user="******",
            code_link="https://gitlab.com/real_url/beginwidget.js",
            code_type="js",
            approved=True,
        ).save()

        last = UserCode.last()
        assert last["approved"] == True
        assert last["name"] == "beginwidget"
        assert last["owners"] == []

        assert UserCode.owned_by("eno") == ["beginwidget.js"]

        assert UserCode.find_owners("beginwidget") == [
            "eno",
        ]

        result = UserCode.purchase("begin", "beginwidget")
        assert UserCode.find_owners("beginwidget") == ["eno", "begin"]
        assert UserCode.owned_by("begin") == ["beginwidget.js"]
Exemple #14
0
 def approve_js(self):
     user_to_approve = self.parser.target_user
     potential_widget = self.args[0]
     print(f"Attempting to Approve Potential Widget: {potential_widget}")
     return UserCode.approve(user_to_approve, potential_widget)
Exemple #15
0
 def buy_js(self):
     # user_to_approve = self.parser.target_user
     potential_widget = self.args[0]
     return UserCode.purchase(self.user, potential_widget)