def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() article_id = "528a5250aa2649ffd8ce8a90" comment_id = "528a5250aa2649ffd8ce8a92" cls.initial_data = "Test comment 2" # Load some initial data for this test case cls.data = { 'articles': [{ 'id': article_id, 'title': 'test', 'comments': [{ 'id': "528a5250aa2649ffd8ce8a91", 'text': "Test comment", }, { 'id': comment_id, 'text': cls.initial_data, }, { 'id': "528a5250aa2649ffd8ce8a93", 'text': "Test comment 2", }] }] } for article in cls.data['articles']: Article(**article).save() cls.response = cls.app.get('/articles/{}/comments/{}/text/'.format( article_id, comment_id))
def setUpClass(cls): server.app.debug = True cls.app = server.app.test_client() cls.mongo_client = MongoClient() # First manually put a post in the DB initial_data = { 'title': "Test title", 'text': "Test text" } Article(**initial_data).save() # Then POST an item with the same title (which should be unique) data = { 'title': "Test title", 'text': "Test text 2" } cls.response = cls.app.post( '/articles/', headers={'content-type': 'application/json'}, data=json.dumps(data) )
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() # Load some initial data for this test case cls.data = { 'articles': [ { 'title': "Test title", 'text': "Test text", 'publish': True, 'publish_date': datetime(2013, 10, 9, 8, 7, 8), 'comments': [ { 'text': "Test comment", 'email': "*****@*****.**", 'upvotes': [ { 'ip_address': "1.2.3.4", }, { 'ip_address': "2.3.4.5", } ] }, { 'text': "Test comment 2", 'email': "*****@*****.**", 'upvotes': [ { 'ip_address': "3.4.5.6", }, { 'ip_address': "4.5.6.7", } ] } ], 'top_comment': { 'text': "Top comment", 'upvotes': [ { 'ip_address': "5.6.7.8", }, { 'ip_address': "6.7.8.9", } ] }, 'tags': ['test', 'unittest', 'python', 'flask'] } ] } for article in cls.data['articles']: Article(**article).save() cls.response = cls.app.get('/articles/')
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() article_id = "528a5250aa2649ffd8ce8a90" comment_id = "528a5250aa2649ffd8ce8a92" cls.initial_data = [{ 'ip_address': "3.4.5.6", 'name': "Wjurrr" }, { 'ip_address': "4.5.6.7", 'name': "Hoinouh" }] # Load some initial data for this test case cls.data = { 'articles': [{ 'id': article_id, 'title': 'test', 'comments': [{ 'id': "528a5250aa2649ffd8ce8a91", 'text': "Test comment", 'upvotes': [{ 'ip_address': "1.2.3.4", 'name': "Jarhz" }, { 'ip_address': "2.3.4.5", 'name': "WHah" }] }, { 'id': comment_id, 'text': "Test comment 2", 'upvotes': cls.initial_data }, { 'id': "528a5250aa2649ffd8ce8a93", 'text': "Test comment 2", 'upvotes': [{ 'ip_address': "5.6.7.8", 'name': "Wwheck" }, { 'ip_address': "6.7.8.9", 'name': "Euflem" }] }] }] } for article in cls.data['articles']: Article(**article).save() cls.response = cls.app.get('/articles/{}/comments/{}/upvotes/'.format( article_id, comment_id))
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() article_id = "528a5250aa2649ffd8ce8a90" cls.initial_data = [ { 'text': "Test comment", 'upvotes': [ { 'ip_address': "1.2.3.4", 'name': "Naja" }, { 'ip_address': "2.3.4.5", 'name': "Hoei" } ] }, { 'text': "Test comment 2", 'upvotes': [ { 'ip_address': "3.4.5.6", 'name': "Wajz" }, { 'ip_address': "4.5.6.7", 'name': "Eaho" } ] } ] # Load some initial data for this test case cls.data = { 'articles': [ { 'id': article_id, 'title': 'test', 'comments': cls.initial_data, } ] } for article in cls.data['articles']: Article(**article).save() cls.response = cls.app.get('/articles/{}/comments/'.format(article_id))
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() article_id = "528a5250aa2649ffd8ce8a90" cls.initial_data = "Test title" # Load some initial data for this test case cls.data = { 'articles': [{ 'id': article_id, 'title': cls.initial_data }] } for article in cls.data['articles']: Article(**article).save() cls.response = cls.app.get('/articles/{}/title/'.format(article_id))
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() cls.initial_data = { 'title': "Test title", 'text': "Test text", 'publish': True, 'publish_date': datetime(2013, 10, 9, 8, 7, 8), 'comments': [ Comment(text="Test comment "), Comment(text="Test comment 2"), Comment(text="Test comment 3"), ], 'top_comment': Comment(text="Top comment"), 'tags': ['test', 'unittest', 'python', 'flask'] } cls.article = Article(**cls.initial_data).save() # the `id` field is the identifier field (duh) cls.comments_update = { 'comments': [{ 'id': unicode(cls.article['comments'][0]['id']), 'text': "Test comment update" }, { 'id': unicode(cls.article['comments'][1]['id']), 'text': "Test comment update 2" }] } cls.response = cls.app.put( '/articles/{}/'.format(unicode(cls.article['id'])), headers={'content-type': 'application/json'}, data=json.dumps(cls.comments_update))
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() article_id = "528a5250aa2649ffd8ce8a90" cls.initial_data = { 'id': article_id, 'title': "Test title", 'text': "Test text", } Article(**cls.initial_data).save() cls.data = { 'title': "Test title updated", 'text': "Test text updated", } cls.response = cls.app.post( '/articles/{}/'.format(article_id), headers={'content-type': 'application/json'}, data=json.dumps(cls.data))
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() article_id = "528a5250aa2649ffd8ce8a90" # Load some initial data for this test case cls.data = { 'articles': [{ 'id': article_id, 'title': "Test title", 'text': "Test text", 'publish': True, 'publish_date': datetime(2013, 10, 9, 8, 7, 8), 'version': 1.4, 'order': 1, 'serial_number': 4581951951031539524, 'comments': [{ 'text': "Test comment", 'email': "*****@*****.**", 'upvotes': [{ 'ip_address': "1.2.3.4", }, { 'ip_address': "2.3.4.5", }] }, { 'text': "Test comment 2", 'email': "*****@*****.**", 'upvotes': [{ 'ip_address': "3.4.5.6", }, { 'ip_address': "4.5.6.7", }] }], 'top_comment': { 'text': "Top comment", 'upvotes': [{ 'ip_address': "5.6.7.8", }, { 'ip_address': "6.7.8.9", }] }, 'tags': ['test', 'unittest', 'python', 'flask'] }] } for article in cls.data['articles']: Article(**article).save() cls.response = cls.app.get('/articles/{}/'.format(article_id))
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() article_id = "528a5250aa2649ffd8ce8a90" comment_id = "528a5250aa2649ffd8ce8a91" # Load some initial data for this test case cls.initial_data = { 'articles': [{ 'id': article_id, 'title': "Test title", 'text': "Test text", 'publish': True, 'publish_date': datetime(2013, 10, 9, 8, 7, 8), 'comments': [{ 'id': comment_id, 'text': "Test comment", 'email': "*****@*****.**", 'upvotes': [{ 'ip_address': "1.2.3.4", 'name': "Whoaa" }, { 'ip_address': "2.3.4.5", 'name': "Nothis" }] }, { 'text': "Test comment 2", 'email': "*****@*****.**", 'upvotes': [{ 'ip_address': "3.4.5.6", 'name': "Zwarz" }, { 'ip_address': "4.5.6.7", 'name': "Takada" }] }], 'top_comment': { 'text': "Top comment", 'upvotes': [{ 'ip_address': "5.6.7.8", 'name': "Warundro" }, { 'ip_address': "6.7.8.9", 'name': "HWQOOO" }] }, 'tags': ['test', 'unittest', 'python', 'flask'] }] } for article in cls.initial_data['articles']: Article(**article).save() cls.put_data = {'name': "Jawohl"} cls.put_ip_address = '5.5.5.5' cls.response = cls.app.put( '/articles/{}/comments/{}/upvotes/{}/'.format( article_id, comment_id, cls.put_ip_address), headers={'content-type': 'application/json'}, data=json.dumps(cls.put_data))
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() cls.initial_data = { 'title': "Test title", 'text': "Test text", 'publish': True, 'publish_date': datetime(2013, 10, 9, 8, 7, 8), 'comments': [ Comment(text="Test comment old", email="*****@*****.**", upvotes=[ Vote(ip_address="1.4.1.2", date=datetime(2012, 5, 2, 9, 1, 3)), Vote(ip_address="2.4.5.2", date=datetime(2012, 8, 2, 8, 2, 1)) ]), Comment(text="Test comment old 2", email="*****@*****.**", upvotes=[ Vote(ip_address="1.4.1.4", date=datetime(2013, 5, 2, 9, 1, 3)), Vote(ip_address="2.4.9.2", date=datetime(2013, 8, 2, 8, 2, 1)) ]), Comment(text="Test comment old 3", email="*****@*****.**", upvotes=[ Vote(ip_address="5.4.1.2", date=datetime(2012, 5, 2, 9, 2, 3)), Vote(ip_address="2.4.1.2", date=datetime(2012, 3, 2, 8, 2, 1)) ]), ], 'top_comment': Comment(text="Top comment old", email="*****@*****.**", upvotes=[ Vote(ip_address="5.4.1.2", date=datetime(2012, 5, 2, 9, 2, 3)), Vote(ip_address="2.4.1.2", date=datetime(2012, 3, 2, 8, 2, 1)) ]), 'tags': ["tag1", "tag2", "tag3"] } article = Article(**cls.initial_data).save() cls.update_data = { 'text': "Top comment new", 'email': "*****@*****.**", 'upvotes': [{ 'ip_address': "1.2.3.4" }, { 'ip_address': "2.2.3.4" }] } cls.response = cls.app.put( '/articles/{}/top_comment/'.format(unicode(article['id'])), headers={'content-type': 'application/json'}, data=json.dumps(cls.update_data))
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() comment_id = "528a5250aa2649ffd8ce8a90" cls.initial_data = { 'title': "Test title", 'text': "Test text", 'publish': True, 'publish_date': datetime(2013, 10, 9, 8, 7, 8), 'comments': [ Comment(id=comment_id, text="Test comment old", email="*****@*****.**", upvotes=[ Vote(ip_address="1.4.1.2", date=datetime(2012, 5, 2, 9, 1, 3), name="Jzorz"), Vote(ip_address="2.4.5.2", date=datetime(2012, 8, 2, 8, 2, 1), name="Nahnahnah") ]), Comment(text="Test comment 2 old", email="*****@*****.**", upvotes=[ Vote(ip_address="1.4.1.4", date=datetime(2013, 5, 2, 9, 1, 3), name="Zwefhalala"), Vote(ip_address="2.4.9.2", date=datetime(2013, 8, 2, 8, 2, 1), name="Jhardikranall") ]), ], 'top_comment': Comment(text="Top comment", email="*****@*****.**", upvotes=[ Vote(ip_address="5.4.1.2", date=datetime(2012, 5, 2, 9, 2, 3), name="Majananejjeew"), Vote(ip_address="2.4.1.2", date=datetime(2012, 3, 2, 8, 2, 1), name="Hoeieieie") ]), 'tags': ["tag1", "tag2", "tag3"] } article = Article(**cls.initial_data).save() cls.add_data = {'ip_address': "5.5.5.5", 'name': "Wejejejeje"} cls.response = cls.app.post( '/articles/{}/comments/{}/upvotes/'.format(unicode(article['id']), comment_id), headers={'content-type': 'application/json'}, data=json.dumps(cls.add_data))
def setUpClass(cls): cls.app = server.app.test_client() cls.mongo_client = MongoClient() # Test filters on all field types: cls.matching_values = { # StringField 'text': "This text should match", # BoolField 'publish': 1, # DateTimeField 'publish_date': datetime(2010, 10, 5), # IntField 'order': 333, # FloatField 'version': 2.5, # LongField 'serial_number': 4581951951031539524, # ListField 'tags': ['matching_tag1', 'matching_tag2'] } matching_articles = [{ 'title': "The first one", 'text': cls.matching_values['text'], 'publish': True, 'publish_date': cls.matching_values['publish_date'], 'order': cls.matching_values['order'], 'version': cls.matching_values['version'], 'serial_number': cls.matching_values['serial_number'], 'tags': cls.matching_values['tags'], 'top_comment': {} }, { 'title': "A sixt one", 'text': cls.matching_values['text'], 'publish': True, 'publish_date': cls.matching_values['publish_date'], 'order': cls.matching_values['order'], 'version': cls.matching_values['version'], 'serial_number': cls.matching_values['serial_number'], 'tags': cls.matching_values['tags'], 'top_comment': {} }] non_matching_articles = [] for i in range(100): # one divergent parameter should exclude the article exclude_match = random.choice( ('text', 'publish', 'publish_date', 'order', 'version', 'serial_number', 'tags')) title = "Non matching article #{}".format(i) if exclude_match == 'text': text = "Non matching text #{}".format(i) else: text = cls.matching_values['text'] if exclude_match == 'publish': publish = False else: publish = True if exclude_match == 'publish_date': publish_date = datetime(random.randint(1950, 2000), random.randint(1, 12), random.randint(1, 27)) else: publish_date = cls.matching_values['publish_date'] if exclude_match == 'order': order = random.randint(0, 100) else: order = cls.matching_values['order'] if exclude_match == 'version': version = float('1.{}'.format(random.randint(0, 9))) else: version = cls.matching_values['version'] if exclude_match == 'serial_number': serial_number = random.randint(1000000000000000000, 2000000000000000000) else: serial_number = cls.matching_values['serial_number'] if exclude_match == 'tags': tags = ['nonmatching_tag1', 'nonmatching_tag2'] else: tags = cls.matching_values['tags'] non_matching_articles.append({ 'title': title, 'text': text, 'publish': publish, 'publish_date': publish_date, 'order': order, 'version': version, 'serial_number': serial_number, 'tags': tags, 'top_comment': {} }) # Load some initial data for this test case initial_data = matching_articles + non_matching_articles for article in initial_data: Article(**article).save() params = {} for key, value in cls.matching_values.items(): if key == 'publish_date': params[key] = value.isoformat() elif key == 'tags': params[key] = ','.join(value) else: params[key] = unicode(value) query_string = '?{}'.format('&'.join( ['{}={}'.format(key, value) for key, value in params.items()])) cls.response = cls.app.get('/articles/{}'.format(query_string))