Example #1
0
    def test_get_caches_pending_to_purge_for_a_host(self):
        ''' Get the list of urls to be purged by a specific host '''

        hostname = 'myservername'
        # these 2 urls should return on the GET below
        new_url_1 = 'http://domain.com/path/to/purge_1'
        new_url_2 = 'http://domain.com/path/to/purge_2'

        # must not return on GET because it was purged
        purged_url = 'http://domain.com/path/already_purge'

        # must not return on GET because it was regitered before the host
        old_url = 'http://domain.com/path/old_url'

        db.session.add(
            Host(id=1,
                 hostname=hostname,
                 created_at=datetime.datetime(2016, 7, 12)))
        db.session.add(
            Url(id=1, url=old_url, created_at=datetime.datetime(2015, 7, 12)))
        db.session.add(Url(id=2, url=purged_url))
        db.session.add(Url(id=3, url=new_url_1))
        db.session.add(Url(id=4, url=new_url_2))
        db.session.add(Purge(id=1, url_id=2, host_id=1))
        db.session.commit()

        response = self.client.get('/hosts/pending_purge',
                                   query_string={'hostname': hostname})

        self.assertEqual(response.status_code, 200)

        computed = json.loads(response.get_data(as_text=True))
        self.assertEqual(computed, [new_url_1, new_url_2])
        self.assertNotIn(purged_url, computed)
Example #2
0
def add_host(hostname):
    ''' Add host do DB '''
    host = Host(hostname=hostname)
    db.session.add(host)

    try:
        db.session.commit()
    except sqlalchemy.exc.IntegrityError:
        return 'Duplicated host', 500

    return '', 201
Example #3
0
    def test_notify_purged_url(self):
        hostname = 'myservername'
        url = 'http://domain.com/path/to/purge'

        # Populate DB for test
        db.session.add(Url(id=1, url=url))
        db.session.add(Host(id=1, hostname=hostname))
        db.session.commit()

        response = self.client.post('/purge',
                                    data={
                                        'hostname':
                                        'myservername',
                                        'url':
                                        'http://domain.com/path/to/purge',
                                        'command_output':
                                        'result_from_purge_command',
                                    })

        self.assertEqual(response.status_code, 201)