def testRunResoures(self):
        # Do the whole healthcheck for all Resources for now
        resources = Resource.query.all()
        for resource in resources:
            result = run_test_resource(resource)
            print('resource: %s result=%s' % (resource.url, result.success))
            run = Run(resource, result)

            print('Adding Run: success=%s, response_time=%ss\n' %
                  (str(run.success), run.response_time))
            self.db.session.add(run)
            self.db.session.commit()

        self.db.session.close()

        # Verify
        resources = Resource.query.all()
        for resource in resources:
            # Each Resource should have one Run
            self.assertEquals(resource.runs.count(), 1,
                              'RunCount should be 1 for %s' % resource.url)
            self.assertEquals(
                resource.runs[0].success, True,
                'Run should be success for %s report=%s' %
                (resource.url, str(resource.runs[0])))
Example #2
0
 def setUp(self):
     self.db = DB
     self.db.create_all()
     fixtures = json.load(open('fixtures.json'))
     # add users
     for user in fixtures['users']:
         account = User(user['user']['username'], user['user']['password'],
                        user['user']['email'], user['user']['role'])
         self.db.session.add(account)
     # add data
     for record in fixtures['data']:
         resource = Resource(account, record['resource']['resource_type'],
                             record['resource']['title'],
                             record['resource']['url'])
         self.db.session.add(resource)
         for run in record['runs']:
             dt = datetime.datetime.strptime(run[0], '%Y-%m-%dT%H:%M:%SZ')
             run2 = Run(resource, run[1], run[2], run[3], dt)
             self.db.session.add(run2)
     self.db.session.commit()