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_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"]