Example #1
0
    def test_worker_can_verify_based_on_expectations(self):
        fetched_result = json.loads(u'{ "user": { "name": "bigo", "items": [ { "foo": "bar", "baz": "bleh" }, { "foo": "poker", "size": "small" } ]  } }')

        some_assertions = ['user.name', 'something.not[0].there', 'user.items[1]', 'user.items[0].baz']
        t = Task(url=u'http://smth.com', expected_fields=some_assertions)
        worker = Worker(t)

        worker.verify(fetched_result)
        errors = worker.get_errors()
        self.assertNotEquals([], errors)
        self.assertFalse(worker.has_expected_data())
Example #2
0
    def test_worker_happy_path(self):
        fetched_result = u'{ "user": { "name": "bigo", "items": [ { "foo": "bar", "baz": "bleh" }, { "foo": "poker", "size": "small" } ]  } }'

        responses.add(responses.GET,
                "http://bigodin.es",
                body=fetched_result,
                content_type='application/json',
                status=200)

        some_assertions = ['user.name', 'user.items[1]', 'user.items[0].baz']
        t = Task(url=u'http://bigodin.es', expected_fields=some_assertions)
        worker = Worker(t)

        worker.execute()
        errors = worker.get_errors()
        self.assertEquals(1, len(responses.calls))
        self.assertEquals([], errors)
        self.assertTrue(worker.has_expected_data())
Example #3
0
 def test_contructor(self):
     task = Task(url="http://foo.com/")
     worker = Worker(task)
     self.assertTrue(worker.has_expected_data())