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()
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
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
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
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()
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()
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
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
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
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
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
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
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
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
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})
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})