Example #1
0
 def test_group_members_api(self, recipients, groups, users):
     # setup
     grp = groups['empty_group']
     url = '/api/v2/actions/group/update_members/{}/'.format(grp.pk)
     assert grp.all_recipients.count() == 0
     initial_not_in_group = grp.all_recipients_not_in_group.count()
     # add calvin to group
     post_json(users['c_staff'], url, {'member': False, 'contactPk': recipients['calvin'].pk})
     assert grp.all_recipients.count() == 1
     assert initial_not_in_group - 1 == grp.all_recipients_not_in_group.count()
     # remove calvin from group
     post_json(users['c_staff'], url, {'member': True, 'contactPk': recipients['calvin'].pk})
     assert grp.all_recipients.count() == 0
     assert initial_not_in_group == grp.all_recipients_not_in_group.count()
Example #2
0
 def test_api_elvanto_posts(self, users):
     """Test posting to end points behind elvanto buttons."""
     # turn on sync
     config = sc_models.SiteConfiguration.get_solo()
     config.sync_elvanto = True
     config.save()
     r = post_json(users["c_staff"], "/api/v2/actions/elvanto/group_fetch/",
                   {})
     post_json(users["c_staff"], "/api/v2/actions/elvanto/group_pull/", {})
     r = users["c_staff"].get("/api/v2/elvanto/groups/")
     assert len(r.data) == 4
     geneva_pk = elv_models.ElvantoGroup.objects.get(name="Geneva").pk
     geneva_url = "/api/v2/toggle/elvanto/group/sync/{}/".format(geneva_pk)
     r = post_json(users["c_staff"], geneva_url, {"sync": False})
     assert r.data["sync"]
     assert elv_models.ElvantoGroup.objects.get(pk=geneva_pk).sync
     r = post_json(users["c_staff"], geneva_url, {"sync": True})
     assert r.data["sync"] is False
     assert elv_models.ElvantoGroup.objects.get(pk=geneva_pk).sync is False
Example #3
0
    def test_send_test_sms_no_user(self, recipients):
        c = Client()
        resp = c.post('/config/send_test_sms/')
        assert resp.status_code == 400
        data = resp.json()
        assert data['status'] == 'failed'
        assert 'error' in data

        resp = post_json(c, '/config/send_test_sms/', {'to_': str(recipients['calvin'].number), 'body_': 'test'})
        assert resp.status_code == 200
Example #4
0
    def test_send_test_email_no_user(self):
        c = Client()
        resp = c.post('/config/send_test_email/')
        assert resp.status_code == 400
        data = resp.json()
        assert data['status'] == 'failed'
        assert 'error' in data

        resp = post_json(c, '/config/send_test_email/', {'to_': '*****@*****.**', 'body_': 'test message'})
        assert resp.status_code == 200
        assert len(mail.outbox) == 1
Example #5
0
 def test_group_members_api(self, recipients, groups, users):
     # setup
     grp = groups["empty_group"]
     url = "/api/v2/actions/group/update_members/{}/".format(grp.pk)
     assert grp.all_recipients.count() == 0
     initial_not_in_group = grp.all_recipients_not_in_group.count()
     # add calvin to group
     post_json(users["c_staff"], url, {
         "member": False,
         "contactPk": recipients["calvin"].pk
     })
     assert grp.all_recipients.count() == 1
     assert initial_not_in_group - 1 == grp.all_recipients_not_in_group.count(
     )
     # remove calvin from group
     post_json(users["c_staff"], url, {
         "member": True,
         "contactPk": recipients["calvin"].pk
     })
     assert grp.all_recipients.count() == 0
     assert initial_not_in_group == grp.all_recipients_not_in_group.count()
Example #6
0
 def test_group_members_api(self, recipients, groups, users):
     # setup
     grp = groups['empty_group']
     url = '/api/v2/actions/group/update_members/{}/'.format(grp.pk)
     assert grp.all_recipients.count() == 0
     initial_not_in_group = grp.all_recipients_not_in_group.count()
     # add calvin to group
     post_json(users['c_staff'], url, {
         'member': False,
         'contactPk': recipients['calvin'].pk
     })
     assert grp.all_recipients.count() == 1
     assert initial_not_in_group - 1 == grp.all_recipients_not_in_group.count(
     )
     # remove calvin from group
     post_json(users['c_staff'], url, {
         'member': True,
         'contactPk': recipients['calvin'].pk
     })
     assert grp.all_recipients.count() == 0
     assert initial_not_in_group == grp.all_recipients_not_in_group.count()
Example #7
0
    def test_send_test_sms_no_user(self, recipients):
        c = Client()
        resp = c.post('/config/send_test_sms/')
        assert resp.status_code == 400
        data = resp.json()
        assert data['status'] == 'failed'
        assert 'error' in data

        resp = post_json(c, '/config/send_test_sms/', {
            'to_': str(recipients['calvin'].number),
            'body_': 'test'
        })
        assert resp.status_code == 200
Example #8
0
    def test_send_test_sms_no_user(self, recipients):
        c = Client()
        resp = c.post("/config/send_test_sms/")
        assert resp.status_code == 400
        data = resp.json()
        assert data["status"] == "failed"
        assert "error" in data

        resp = post_json(c, "/config/send_test_sms/", {
            "to_": str(recipients["calvin"].number),
            "body_": "test"
        })
        assert resp.status_code == 200
Example #9
0
    def test_send_test_email_no_user(self):
        c = Client()
        resp = c.post('/config/send_test_email/')
        assert resp.status_code == 400
        data = resp.json()
        assert data['status'] == 'failed'
        assert 'error' in data

        resp = post_json(c, '/config/send_test_email/', {
            'to_': '*****@*****.**',
            'body_': 'test message'
        })
        assert resp.status_code == 200
        assert len(mail.outbox) == 1
Example #10
0
    def test_create_su(self):
        c = Client()
        resp = c.post('/config/create_admin_user/')
        assert resp.status_code == 400
        data = resp.json()
        assert data['status'] == 'failed'
        assert 'error' in data

        resp = post_json(c, '/config/create_admin_user/', {'email_': '*****@*****.**', 'pass_': 'testpass'})
        assert resp.status_code == 200

        resp = c.get('/config/first_run/')
        assert resp.status_code == 302
        assert '/' == resp.url
Example #11
0
    def test_send_test_email_no_user(self):
        c = Client()
        resp = c.post("/config/send_test_email/")
        assert resp.status_code == 400
        data = resp.json()
        assert data["status"] == "failed"
        assert "error" in data

        resp = post_json(c, "/config/send_test_email/", {
            "to_": "*****@*****.**",
            "body_": "test message"
        })
        assert resp.status_code == 200
        assert len(mail.outbox) == 1
Example #12
0
 def test_api_elvanto_posts(self, users):
     """Test posting to end points behind elvanto buttons."""
     # turn on sync
     config = sc_models.SiteConfiguration.get_solo()
     config.sync_elvanto = True
     config.save()
     r = post_json(users['c_staff'], '/api/v2/actions/elvanto/group_fetch/',
                   {})
     post_json(users['c_staff'], '/api/v2/actions/elvanto/group_pull/', {})
     r = users['c_staff'].get('/api/v2/elvanto/groups/')
     assert len(r.data) == 4
     geneva_pk = elv_models.ElvantoGroup.objects.get(name='Geneva').pk
     geneva_url = '/api/v2/toggle/elvanto/group/sync/{}/'.format(geneva_pk)
     r = post_json(
         users['c_staff'],
         geneva_url,
         {'sync': False},
     )
     assert r.data['sync']
     assert elv_models.ElvantoGroup.objects.get(pk=geneva_pk).sync
     r = post_json(users['c_staff'], geneva_url, {'sync': True})
     assert r.data['sync'] is False
     assert elv_models.ElvantoGroup.objects.get(pk=geneva_pk).sync is False
Example #13
0
    def test_create_su(self):
        c = Client()
        resp = c.post('/config/create_admin_user/')
        assert resp.status_code == 400
        data = resp.json()
        assert data['status'] == 'failed'
        assert 'error' in data

        resp = post_json(c, '/config/create_admin_user/', {
            'email_': '*****@*****.**',
            'pass_': 'testpass'
        })
        assert resp.status_code == 200

        resp = c.get('/config/first_run/')
        assert resp.status_code == 302
        assert '/' == resp.url
Example #14
0
    def test_create_su(self):
        c = Client()
        resp = c.post("/config/create_admin_user/")
        assert resp.status_code == 400
        data = resp.json()
        assert data["status"] == "failed"
        assert "error" in data

        resp = post_json(c, "/config/create_admin_user/", {
            "email_": "*****@*****.**",
            "pass_": "testpass"
        })
        assert resp.status_code == 200

        resp = c.get("/config/first_run/")
        assert resp.status_code == 302
        assert "/" == resp.url
Example #15
0
 def test_api_posts(self, recipients, groups, smsin, smsout, keywords, users):
     url = '/api/v2/smsin/{}/'.format(smsin['sms1'].pk)
     for param in ['reingest', 'dealt_with', 'archived', 'display_on_wall']:
         for value in [True, False]:
             post_json(users['c_staff'], url, {param: value})
Example #16
0
 def test_api_posts(self, recipients, groups, smsin, smsout, keywords,
                    users):
     url = "/api/v2/smsin/{}/".format(smsin["sms1"].pk)
     for param in ["reingest", "dealt_with", "archived", "display_on_wall"]:
         for value in [True, False]:
             post_json(users["c_staff"], url, {param: value})
Example #17
0
 def test_api_posts(self, recipients, groups, smsin, smsout, keywords,
                    users):
     url = '/api/v2/smsin/{}/'.format(smsin['sms1'].pk)
     for param in ['reingest', 'dealt_with', 'archived', 'display_on_wall']:
         for value in [True, False]:
             post_json(users['c_staff'], url, {param: value})