Skip to content

Commit

Permalink
Add test_wikidot suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Mar 10, 2024
1 parent c68e2cf commit 50fc82b
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
87 changes: 87 additions & 0 deletions test/data/user_info_win.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<div class="owindow" style="width: 60%">
<div class="title modal-header">
User info <\/div>
<div class="content modal-body">
<img style="float:left; padding: 2px 8px; background-color: #FFF;" src="https:\/\/www.wikidot.com\/avatar.php?userid=4598089&amp;timestamp=1710039304" alt="" \/>
<h1>aismallard<\/h1>

<table class="table">
<tr>
<td class="active">
<b>Gender<\/b>
<\/td>
<td>
female <\/td>
<\/tr>
<tr>
<td class="active">
<b>Website<\/b>
<\/td>
<td>
<a href="https:\/\/scpwiki.com\/aismallard">https:\/\/scpwiki.com\/aismallard<\/a>
<\/td>

<tr>
<td class="active">
<b>Wikidot.com User since:<\/b>
<\/td>
<td>
<span class="odate time_1536706055 format_%25e%20%25b%20%25Y%2C%20%25H%3A%25M%20%28%25O%20ago%29">11 Sep 2018 22:47<\/span>
<\/td>
<\/tr>


<tr>
<td class="active">
<b>Account type<\/b>
<\/td>
<td>
free
<\/td>
<\/tr>

<tr>
<td class="active">
<b>Karma level<\/b>
<\/td>
<td>
guru <img src="\/\/www.wikidot.com\/userkarma.php?u=4598089&amp;onlyKarma=true"\/>
(<a href="http:\/\/www.wikidot.com\/doc:karma" target="_blank">what is this?<\/a>)<br\/>
<\/td>
<\/tr>

<tr>
<td class="active">
<b>Member of this Site: since<\/b>
<\/td>
<td>
<span class="odate time_1536730624 format_%25e%20%25b%20%25Y%2C%20%25H%3A%25M%20%28%25O%20ago%29">12 Sep 2018 05:37<\/span>
<\/td>
<\/tr>
<tr>
<td class="active">
<b>Role in this Site<\/b>
<\/td>
<td>
Site Administrator <\/td>
<\/tr>

<\/table>

<div style="margin-top: 10px">
<div style="float:right">
<a href="javascript:;" class="btn btn-danger btn-small btn-sm" onclick="WIKIDOT.modules.UserInfoWinModule.listeners.flagUser(event, 4598089)">Flag user as abusive<\/a>
<!--<span id="user-abuse-report-button">?<\/span>-->
<\/div>
<a href="http:\/\/www.wikidot.com\/user:info\/aismallard" class="btn btn-primary">Profile page<\/a>
<a href="http:\/\/www.wikidot.com\/account\/messages#\/new\/4598089" class="btn btn-primary">Write private message<\/a>
<a href="javascript:;" onclick="WIKIDOT.modules.UserInfoWinModule.listeners.addContact(event,4598089)" class="btn btn-primary">Add to contacts<\/a>
<\/div>
<\/div>
<div class="button-bar modal-footer">
<a href="javascript:;" class="btn btn-danger" onclick="OZONE.dialog.cleanAll()">Close window<\/a>
<\/div>

<div id="user-abuse-report-button-hovertip" style="display: none">
Notify administrators\/moderators about abusive user. <\/div>
<\/div>
31 changes: 31 additions & 0 deletions test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,35 @@
Helpers and utilities for the Yellowstone unit tests.
"""

import os
from dataclasses import dataclass

TEST_SOURCE = "[test_source]"


@dataclass
class FakeResponse:
data: dict

@staticmethod
def from_file(filename: str) -> "FakeResponse":
path = os.path.join(os.path.dirname(__file__), "data", f"{filename}.html")
with open(path) as file:
body = file.read()

return FakeResponse(
{
"status": "ok",
"CURRENT_TIMESTAMP": 1710000000,
"body": body,
"jsInclude": [],
"cssInclude": [],
"callbackIndex": 1,
},
)

def raise_for_status(self):
pass

def json(self) -> dict:
return self.data
51 changes: 51 additions & 0 deletions test/test_wikidot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import unittest
from unittest.mock import patch

import requests

from yellowstone.config import Config
from yellowstone.wikidot import Wikidot

from .helpers import FakeResponse


class TestWikidotClass(unittest.TestCase):
def setUp(self):
self.config = Config(
s3_bucket="test",
site_slugs=["test", "test-tls"],
sites_use_tls=["test-tls"],
sites_use_admin_members=[],
always_fetch_site=True,
)
self.wikidot = Wikidot(self.config, username="test", api_key="test")

def test_ajax_module_connector(self):
http_response = FakeResponse.from_file("user_info_win")
with patch.object(requests, "post", return_value=http_response):
html = self.wikidot.ajax_module_connector(
"www",
"users/UserInfoWinModule",
{"user_id": 4598089},
)
self.assertEqual(html, http_response.data["body"])

def test_site_url(self):
ajax_url = self.wikidot.site_url("test")
self.assertEqual(ajax_url, "http://test.wikidot.com")

ajax_url = self.wikidot.site_url("test-tls")
self.assertEqual(ajax_url, "https://test-tls.wikidot.com")

def test_ajax_url(self):
ajax_url = self.wikidot.ajax_module_url("test")
self.assertEqual(ajax_url, "http://test.wikidot.com/ajax-module-connector.php")

ajax_url = self.wikidot.ajax_module_url("test-tls")
self.assertEqual(
ajax_url, "https://test-tls.wikidot.com/ajax-module-connector.php"
)

def test_generate_token7(self):
token7 = self.wikidot.generate_token7()
self.assertEqual(len(token7), 32)

0 comments on commit 50fc82b

Please sign in to comment.