#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json

import unittest

from downstream_node.startup import app, db
from downstream_node.models import Challenges


class TestDownstream(unittest.TestCase):
    def setUp(self):
        self.app = app.test_client()
        app.config['TESTING'] = True
        db.create_all()

    def tearDown(self):
        db.engine.execute('DROP TABLE challenges,files')
        del self.app

    def test_api_downstream_challenge(self):
        r = self.app.get('/api/downstream/challenges/test')
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.content_type, 'application/json')

        r_json = json.loads(r.data)
        self.assertIsInstance(r_json, dict)
        self.assertEqual(len(r_json.get('challenges')), 1000)
        self.assertEqual(r_json.get('challenges')[0].get('filename'), 'thirty-two_meg.testfile')

    def test_api_downstream_challenge_answer(self):
        r = self.app.get('api/downstream/challenges/answer/test')



if __name__ == '__main__':
    unittest.main()
@@ -921,32 +921,108 @@
 e_answer(self):%0A
+        # Prime DB%0A        self.app.get('/api/downstream/challenges/test')%0A%0A
         r = self
@@ -1031,16 +1031,17 @@
 pp.get('
+/
 api/down
@@ -1072,16 +1072,1398 @@
 /test')%0A
+        self.assertEqual(r.status_code, 405)%0A%0A        r = self.app.post('/api/downstream/challenges/answer/test')%0A        self.assertEqual(r.status_code, 400)%0A        self.assertEqual(json.loads(r.data).get('msg'), 'missing request json')%0A%0A        data = %7B%0A            'seed': 'test seed'%0A        %7D%0A        r = self.app.post(%0A            '/api/downstream/challenges/answer/test',%0A            data=json.dumps(data)%0A        )%0A        self.assertEqual(r.status_code, 400)%0A        self.assertEqual(json.loads(r.data).get('msg'), 'missing data')%0A%0A        data.update(%7B%0A            'response': 'test response',%0A            'block': 12345%0A        %7D)%0A        r = self.app.post(%0A            '/api/downstream/challenges/answer/test',%0A            data=json.dumps(data)%0A        )%0A        self.assertEqual(r.status_code, 404)%0A%0A        chals = Challenges(%0A            filename='thirty-two_meg.testfile',%0A            rootseed='test root seed',%0A            seed='test seed',%0A            block=12345,%0A            response='test response'%0A        )%0A        db.session.add(chals)%0A        db.session.commit()%0A%0A        r = self.app.post(%0A            '/api/downstream/challenges/answer/test',%0A            data=json.dumps(data)%0A        )%0A        self.assertEqual(r.status_code, 200)%0A        self.assertEqual(json.loads(r.data).get('msg'), 'ok')%0A        self.assertIs(json.loads(r.data).get('match'), True)
 %0A%0A%0Aif __

Add final web tests