Skip to content

Instantly share code, notes, and snippets.

@gjbagrowski
Last active August 29, 2015 14:20
Show Gist options
  • Save gjbagrowski/929a77f145258f6559d5 to your computer and use it in GitHub Desktop.
Save gjbagrowski/929a77f145258f6559d5 to your computer and use it in GitHub Desktop.
from django.test import TestCase, Client
URLS = (
{}
)
class MyTest(TestCase):
def create_test_client(self, urldata):
def make_request(self, uindex, **data):
self.get(
'/p/', data,
HTTP_REFERER=self.urldata['url'] + self.urldata['urls'][uindex])
client = Client()
self.create_client_sessions(client)
client.urldata = urldata
client.widget_request = make_request
return client
def setUp(self):
self.client1 = self.create_test_client(URLS[0])
self.client2 = self.create_test_client(URLS[1])
def test_xxx(self):
self.client.make_request(1, uid='JNDaos9d8aj3i0123', ut=3)
from django.test import TestCase, Client
URLS = (
{
'url': 'http://mediamarkt.pl',
'urls': ['onas', 'kontakt'],
'urls': {'onas': 'kontanct/asdas/asdfasd.php'},
}
)
class WidgetClient(Client):
def widget_get(self, key, **data):
return self.get(
'/p/', data,
HTTP_REFERER=self.urldata['url'] + self.urldata['urls'][key])
def __init__(self, urldata, *args, **kwargs):
self.urldata = urldata
super(self, WidgetClient).__init__(*args, **kwargs)
self.create_client_session()
class MyTest(TestCase):
def setUp(self):
self.client1 = WidgetClient(URLS[0])
self.client2 = WidgetClient(URLS[1])
def test_xxx(self):
response = self.client.widget_get(1, uid='JNDaos9d8aj3i0123', ut=3)
self.assertEqual(response.status_code, 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment