def on_request(ch, method, props, req):
    req_json = json.loads(req)

    teachers = Teachers()
    teachers.add(req_json['teachers'])
    subjects = Subjects()
    subjects.add(req_json['subjects'])
    timeslots = TimeSlots(req_json['timeslots'])

    solver = Solver(teachers, subjects, timeslots)
    solver.solve()

    response = solver.solution

    ch.basic_publish(exchange='',
                     routing_key=props.reply_to,
                     properties=pika.BasicProperties(
                         correlation_id=props.correlation_id
                     ),
                     body=str(response))
    ch.basic_ack(delivery_tag=method.delivery_tag)
    def test_solver(self):
        teachers = Teachers()
        teachers.add(['Bob', 'Jill', 'Tim', 'Ben'])
        subjects = Subjects()
        subjects.add(['Sport', 'Art'])
        timeslots = TimeSlots(4)

        solver = Solver(teachers,
                        subjects,
                        timeslots)

        solver.solve()

        self.assertEqual(len(solver.solution.row), 2)
        self.assertEqual(len(solver.solution.col), 4)
        self.assertEqual(len(solver.solution.flat), 8)
        self.assertTrue([num in solver.solution.flat for num in
                         range(len(teachers.store)+1)])

        teachers.add('Jeff')
        with self.assertRaises(ValueError):
            solver = Solver(teachers,
                            subjects,
                            timeslots)
    def test_subjects(self):
        subjects = Subjects()
        subjects.add(['Music', 'Art'])
        self.assertEqual(len(subjects.store), 2)

        subjects.add('Sport')
        self.assertEqual(len(subjects.store), 3)
        self.assertEqual(subjects.store[1], 'Art')

        self.assertRaises(TypeError, lambda: subjects.add(1))