예제 #1
0
    def test_worker_connection(self):
        """
            Purpose: Test regular running of worker
            Expectation: startup system, hit the reddit user and parse the data, send to mothership

            :precondition: Mothership server running
            :return:
            """
        server = MothershipServer()
        server.run()
        try:
            worker = BasicUserParseWorker(
                "https://www.reddit.com/user/alecnin")
            worker.send_to_mother()
        # connect to mother, so should not raise exception, should run everything else
        except ConnectionRefusedError:
            self.fail('connection failure')
예제 #2
0
    def test_worker_send_to_mothership(self):
        worker = BasicUserParseWorker("https://www.reddit.com/user/Chrikelnel")
        test_data = "test_data"
        test_root = "root"

        # Set up our own socket on the mothership port.
        # Precondition: ip in settings.py for mothership is localhost

        s = socket.socket()
        addr = (settings.MOTHERSHIP['host'], settings.MOTHERSHIP['port'])
        s.bind(addr)
        s.listen(5)

        worker.send_to_mother(test_data, test_root)

        worker, address = s.accept()
        data = worker.recv(1024)
        data = json.loads(data.decode('ascii'))

        self.assertEqual(data['data'], test_data)
        self.assertEqual(data['root'], test_root)

        worker.close()
        s.close()