import unittest
import requests
import threading
import hunting.server as server


class TestRunEndpoint(unittest.TestCase):
    def setUp(self):
        self.port = server.get_random_open_port()
        self.server = server.new_server(self.port)

        def start_on_port():
            self.server.serve_forever()
        server_thread = threading.Thread(target=start_on_port)
        server_thread.start()

    def tearDown(self):
        self.server.shutdown()

    def url(self, path):
        url = 'http://localhost:{0}/{1}'.format(self.port, path)
        return url

    def test_run_codes(self):
        # 200 if valid
        r200 = requests.get(self.url('run/test/hero_versus_zero.json'))
        self.assertEqual(r200.status_code, 200)

        # 404 if invalid resource
        r404 = requests.get(self.url('run/test/whatwhattheheck.idontknow'))
        self.assertEqual(r404.status_code, 404)

        # 500 if bad json
        r500 = requests.get(self.url('run/test/deformed.json'))
        self.assertEqual(r500.status_code, 500)

@@ -42,16 +42,28 @@
 reading%0A
+import json%0A
 import h
@@ -86,16 +86,276 @@
  server%0A
+import hunting.resources as resources%0A%0A%0Adef sort_dicts(obj):%0A    if isinstance(obj, dict):%0A        return sorted((k, sort_dicts(v)) for k, v in obj.items())%0A    if isinstance(obj, list):%0A        return (sort_dicts(x) for x in obj)%0A    else:%0A        return obj%0A
 %0A%0Aclass 
@@ -1309,12 +1309,370 @@
 _code, 500)%0A
+%0A    def test_run_contents_simple(self):%0A        response = requests.get(self.url('run/test/hero_versus_zero.json'))%0A        parsed_response = sort_dicts(response.json())%0A        with open(resources.get_full_path('test/results/hero_versus_zero.json')) as f:%0A            expected = sort_dicts(json.load(f))%0A        self.assertEqual(parsed_response, expected)%0A

Add test for contents of run response