def test_extractor_post_triggers_slack_notification(self, testapp):
        ''' A valid heartbeat post triggers a Slack notification
        '''
        # set up the extractor
        department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
        Extractor.create(username='******', email='*****@*****.**', password="******", department_id=department.id, next_month=10, next_year=2006)

        # set the correct authorization
        testapp.authorization = ('Basic', ('extractor', 'password'))

        # set a fake Slack webhook URL
        fake_webhook_url = 'http://webhook.example.com/'
        current_app.config['SLACK_WEBHOOK_URL'] = fake_webhook_url

        # create a mock to receive POST requests to that URL
        responses.add(responses.POST, fake_webhook_url, status=200)

        # post a sample json object to the heartbeat URL
        testapp.post_json("/data/heartbeat", params={"heartbeat": "heartbeat"})

        # test the captured post payload
        post_body = json.loads(responses.calls[0].request.body)
        assert 'Comport Pinged by Extractor!' in post_body['text']

        # delete the fake Slack webhook URL
        del(current_app.config['SLACK_WEBHOOK_URL'])
        # reset the mock
        responses.reset()
 def test_reject_extractor_post_with_wrong_password(self, testapp):
     ''' An extractor login with the wrong password is rejected.
     '''
     Extractor.create(username='******', email='*****@*****.**', password="******")
     testapp.authorization = ('Basic', ('extractor', 'drowssap'))
     response = testapp.post("/data/heartbeat", expect_errors=True)
     assert response.status_code == 401
     assert response.text == 'Extractor authorization failed!'
示例#3
0
    def test_valid_login_replies_with_request(self, testapp):
        right_department = Department.create(name="good2", load_defaults=False)

        Extractor.create(username="******", email="*****@*****.**", password="******", department_id=right_department.id)
        testapp.authorization = ("Basic", ("good4", "valid"))

        res = testapp.post_json("/data/heartbeat", params={"json": "yep"}, expect_errors=True)
        assert res.status_code == 200
示例#4
0
    def test_extractors_are_users(self):
        department = DepartmentFactory()
        department.save()

        extractor = Extractor.create(username='******', email='*****@*****.**', department_id=department.id)

        assert extractor.department_id == department.id
    def test_successful_extractor_post(self, testapp):
        ''' Send a valid heartbeat post, get a valid response.
        '''
        # set up the extractor
        department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
        Extractor.create(username='******', email='*****@*****.**', password="******", department_id=department.id, next_month=10, next_year=2006)

        # set the correct authorization
        testapp.authorization = ('Basic', ('extractor', 'password'))

        # post a sample json object to the heartbeat URL
        response = testapp.post_json("/data/heartbeat", params={"heartbeat": "heartbeat"})
        # assert that we got the expected response
        assert response.status_code == 200
        assert response.json_body['nextMonth'] == 10
        assert response.json_body['nextYear'] == 2006
        assert response.json_body['received'] == {'heartbeat': 'heartbeat'}
    def test_extractors_are_users(self):
        department = DepartmentFactory()
        department.save()

        extractor = Extractor.create(username='******', email='*****@*****.**')
        extractor.departments.append(department)
        extractor.save()

        assert extractor.first_department().id == department.id
示例#7
0
    def test_extractors_are_users(self):
        department = DepartmentFactory()
        department.save()

        extractor = Extractor.create(username='******',
                                     email='*****@*****.**')
        extractor.departments.append(department)
        extractor.save()

        assert extractor.first_department().id == department.id
示例#8
0
 def test_bad_extractor_password_is_a_401(self, testapp):
     Extractor.create(username="******", email="*****@*****.**", password="******")
     testapp.authorization = ("Basic", ("good", "fake"))
     res = testapp.post("/data/heartbeat", expect_errors=True)
     assert res.status_code == 401