From: Marek Marecki Date: Thu, 2 May 2013 23:31:59 +0000 (+0200) Subject: Small fixes in code and tests (added fancy test counter) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=62f1912f7d40cbab786a0a4716d7a1b64060e034;p=diaspy.git Small fixes in code and tests (added fancy test counter) --- diff --git a/.gitignore b/.gitignore index a9a6117..91de4f2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__/* .env testconf.py +TEST_COUNT diff --git a/Makefile b/Makefile index 91ab8ce..c085927 100644 --- a/Makefile +++ b/Makefile @@ -5,3 +5,6 @@ style-check: test: python3 -m unittest --verbose --catch --failfast tests.py + +test-python2: + python3 -m unittest --verbose --catch --failfast tests.py diff --git a/diaspy/__init__.py b/diaspy/__init__.py index e047ea5..c824fa5 100644 --- a/diaspy/__init__.py +++ b/diaspy/__init__.py @@ -1,4 +1,10 @@ +import diaspy.models as models +import diaspy.conversations as conversations +import diaspy.streams as streams +import diaspy.client as client +""" from diaspy import client from diaspy import models from diaspy import conversations from diaspy import streams +""" diff --git a/diaspy/client.py b/diaspy/client.py index 09e376d..1a43689 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -89,12 +89,12 @@ class Client: :returns: list -- list of Post objects """ if stream: + tagged_posts = diaspy.streams.Generic(self.connection, location='tags/{0}.json'.format(tag)) + else: r = self.connection.get('tags/{0}.json'.format(tag)) if r.status_code != 200: raise Exception('wrong status code: {0}'.format(r.status_code)) tagged_posts = [diaspy.models.Post(str(post['id']), self.connection) for post in r.json()] - else: - tagged_posts = diaspy.streams.Generic(self.connection, location='tags/{0}.json'.format(tag)) return tagged_posts def get_notifications(self): diff --git a/diaspy/connection.py b/diaspy/connection.py index 2f0329e..af978d6 100644 --- a/diaspy/connection.py +++ b/diaspy/connection.py @@ -26,6 +26,7 @@ class Connection(): self.session = requests.Session() self._token_regex = re.compile(r'content="(.*?)"\s+name="csrf-token') self._userinfo_regex = re.compile(r'window.current_user_attributes = ({.*})') + self.login_data = {} self._setlogin(username, password) def get(self, string): diff --git a/tests.py b/tests.py index 8379924..549e6c3 100644 --- a/tests.py +++ b/tests.py @@ -10,49 +10,64 @@ import re import diaspy +#### SETUP STUFF #### test suite configuration variables: can be adjusted to your liking import testconf __pod__ = testconf.__pod__ __username__ = testconf.__username__ __passwd__ = testconf.__passwd__ -__connection__ = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) -__connection__.login() +# Test counter +try: + test_count_file = open('TEST_COUNT', 'r') + test_count = int(test_count_file.read()) + test_count_file.close() +except (IOError, ValueError): + test_count = 0 +finally: + test_count += 1 +test_count_file = open('TEST_COUNT', 'w') +test_count_file.write(str(test_count)) +test_count_file.close() +print('Running test no. {0}'.format(test_count)) +print('Running tests on connection to pod: "{0}"\n'.format(__pod__)) +test_connection = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) +test_connection.login() + + +#### Test suite code class StreamTest(unittest.TestCase): def testGetting(self): c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) c.login() - stream = diaspy.streams.Stream(c) - stream.update() + stream = diaspy.streams.Generic(c) def testGettingLength(self): c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) c.login() - stream = diaspy.streams.Stream(c) - stream.update() + stream = diaspy.streams.Generic(c) len(stream) def testClearing(self): - stream = diaspy.streams.Stream(__connection__) - stream.update() + stream = diaspy.streams.Stream(test_connection) stream.clear() self.assertEqual(0, len(stream)) def testPurging(self): - stream = diaspy.streams.Stream(__connection__) + stream = diaspy.streams.Stream(test_connection) post = stream.post('#diaspy test') stream.update() post.delete() stream.purge() - self.assertNotIn(post.post_id, [post.post_id for post in stream]) + self.assertNotIn(post.post_id, [p.post_id for p in stream]) def testPostingText(self): c = diaspy.connection.Connection(pod=__pod__, username=__username__, password=__passwd__) c.login() stream = diaspy.streams.Stream(c) - post = stream.post('#diaspy test') + post = stream.post('#diaspy test no. {0}'.format(test_count)) self.assertEqual(diaspy.models.Post, type(post)) def testPostingImage(self): @@ -90,12 +105,18 @@ class ClientTests(unittest.TestCase): self.assertEqual(list, type(notifications)) if notifications: self.assertEqual(dict, type(notifications[0])) - def testGettingTag(self): + def testGettingTagAsList(self): client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__) tag = client.get_tag('foo') self.assertEqual(list, type(tag)) if tag: self.assertEqual(diaspy.models.Post, type(tag[0])) + def testGettingTagAsStream(self): + client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__) + tag = client.get_tag('foo', stream=True) + self.assertEqual(diaspy.streams.Generic, type(tag)) + if tag: self.assertEqual(diaspy.models.Post, type(tag[0])) + def testGettingMailbox(self): client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__) mailbox = client.get_mailbox()