def test_article_detail(self, mock_requests_post): mock_requests_post.return_value = fixtures.request_post_schedule db.run(db.create_articles_properties_events) db.run(db.create_version_zero_articles) resp = self.client.get('/api/article/09003') self.assertEqual(json.loads(resp.data), json.loads(fixtures.article_detail_example))
def test_queue_article_publication(self, fake_queue_provider): fake_queue_provider.return_value = fixtures.FakeQueueProvider() db.run(db.create_complete_article_properties_events) input = {"articles": [{"id": "09003"}]} data_expected = {"articles": [{"id": "09003", "publication-status": "queued", "run": "b6ef5d1f-23b3-4f4e-9ba3-7de24f885171", "version": "3"}]} resp = self.client.post('/api/queue_article_publication', data=json.dumps(input), content_type='application/json') self.assertDictEqual(json.loads(resp.data), data_expected)
def test_article_scheduler_for_range(self, mock_requests_get): mock_requests_get.return_value = fixtures.request_get_schedule_for_range db.run(db.create_complete_article_properties_events) path = "/api/article_schedule_for_range/from/1464217200/to/1495753200/" resp = self.client.get(path) self.assertEqual(resp.status_code, 200, 'failed testing path %s' % path) articles_response = json.loads(resp.data).get("articles") expected_articles = json.loads( fixtures.scheduled_articles_to_return).get("articles") articles_response.sort() expected_articles.sort() advance_article = articles_response[0] normal_article = articles_response[1] advance_article_expected = expected_articles[0] normal_article_expected = expected_articles[1] for key in advance_article: self.assertEqual(advance_article[key], advance_article_expected[key]) for key in normal_article: self.assertEqual(normal_article[key], normal_article_expected[key])
def test_store_message_duplicate_does_not_get_added(self): #given db.run(db.create_messages_including_example) message_id = fixtures.message_id_example timestamp = fixtures.timestamp_example #when try: conn, cur = db.get_connection() articles._store_message(cur,message_id,timestamp) db.commit_close_connection(conn,cur) except Exception, e: self.fail("test_repeated_message_does_not_get_added raised an exception. Details: " + str(e))
def test_store_message(self): #given db.run(db.create_random_message) message_id = fixtures.message_id_example timestamp = fixtures.timestamp_example #when conn, cur = db.get_connection() articles._store_message(cur,message_id,timestamp) db.commit_close_connection(conn,cur) #then count = db.retrieve_first("select count(message_id) from message") self.assertEqual(2, count)
def test_store_message(self): #given db.run(db.create_random_message) message_id = fixtures.message_id_example timestamp = fixtures.timestamp_example #when conn, cur = db.get_connection() articles._store_message(cur, message_id, timestamp) db.commit_close_connection(conn, cur) #then count = db.retrieve_first("select count(message_id) from message") self.assertEqual(2, count)
def test_store_message_duplicate_does_not_get_added(self): #given db.run(db.create_messages_including_example) message_id = fixtures.message_id_example timestamp = fixtures.timestamp_example #when try: conn, cur = db.get_connection() articles._store_message(cur, message_id, timestamp) db.commit_close_connection(conn, cur) except Exception, e: self.fail( "test_repeated_message_does_not_get_added raised an exception. Details: " + str(e))
def test_queue_article_publication_error(self): db.run(db.create_articles_properties_events) input = {"articles": [{"id": "09888888"}]} data_expected = { u'articles': [{ u'publication-status': u'error', u'id': u'09888888', u'run': None, u'version': u'None' }] } resp = self.client.post('/api/queue_article_publication', data=json.dumps(input), content_type='application/json') self.assertDictEqual(json.loads(resp.data), data_expected)
def test_queue_article_publication(self, fake_queue_provider): fake_queue_provider.return_value = fixtures.FakeQueueProvider() db.run(db.create_complete_article_properties_events) input = {"articles": [{"id": "09003"}]} data_expected = { "articles": [{ "id": "09003", "publication-status": "queued", "run": "b6ef5d1f-23b3-4f4e-9ba3-7de24f885171", "version": "3" }] } resp = self.client.post('/api/queue_article_publication', data=json.dumps(input), content_type='application/json') self.assertDictEqual(json.loads(resp.data), data_expected)
def test_store_message_duplicate_does_not_get_added(self): # given db.run(db.create_messages_including_example) message_id = fixtures.message_id_example timestamp = fixtures.timestamp_example # when try: conn, cur = db.get_connection() articles._store_message(cur, message_id, timestamp) db.commit_close_connection(conn, cur) except Exception as e: self.fail( "test_repeated_message_does_not_get_added raised an exception. Details: " + str(e)) # then count = db.retrieve_first("select count(message_id) from message") self.assertEqual(2, count)
def test_article_scheduler_for_range(self, mock_requests_get): mock_requests_get.return_value = fixtures.request_get_schedule_for_range db.run(db.create_complete_article_properties_events) path = "/api/article_schedule_for_range/from/1464217200/to/1495753200/" resp = self.client.get(path) self.assertEqual(resp.status_code, 200, 'failed testing path %s' % path) articles_response = json.loads(resp.data).get("articles") expected_articles = json.loads(fixtures.scheduled_articles_to_return).get("articles") articles_response.sort() expected_articles.sort() advance_article = articles_response[0] normal_article = articles_response[1] advance_article_expected = expected_articles[0] normal_article_expected = expected_articles[1] for key in advance_article: self.assertEqual(advance_article[key], advance_article_expected[key]) for key in normal_article: self.assertEqual(normal_article[key], normal_article_expected[key])
def test_queue_article_publication_error(self): db.run(db.create_articles_properties_events) input = {"articles": [{"id": "09888888"}]} data_expected = {u'articles': [{u'publication-status': u'error', u'id': u'09888888', u'run': None, u'version': u'None'}]} resp = self.client.post('/api/queue_article_publication', data=json.dumps(input), content_type='application/json') self.assertDictEqual(json.loads(resp.data), data_expected)
def test_current_model(self, mock_requests_post): db.run(db.create_articles_properties_events) mock_requests_post.return_value = fixtures.request_post_schedule resp = self.client.get('/api/current') self.assertDictEqual(json.loads(resp.data), json.loads(fixtures.current_articles_example))
def setUp(self): dashboard.app.config['TESTING'] = True self.client = dashboard.app.test_client() db.run(db.create_tables_schema) pass
def setUp(self): db.run(db.create_tables_schema)