def test_groups_subscriber(header): groups = Groups(header) n_groups = groups.all() if not len(n_groups): pytest.skip("No groups found") group_ix = random.randint(0, len(n_groups)) try: group_1 = n_groups[group_ix] except IndexError: pytest.skip("Group index not found. Maybe deleted by another thread") subs_in_group_1 = groups.subscribers(group_1.id) if not len(subs_in_group_1): pytest.skip("No subscriber found in this group.") try: sub1 = subs_in_group_1[0] except IndexError: pytest.skip("Subscriber not found. Maybe deleted by another thread") tmp_sub = groups.subscriber(group_1.id, sub1.id) assert sub1.email == tmp_sub.email attempt = itertools.count() while True and next(attempt) < 15: try: num = random.randint(1000, 100000) mail = generate_random_email(length=15, seed=num) data = { 'name': 'John', 'email': mail, 'fields': { 'company': 'MailerLite' } } new_subs = groups.add_subscribers(group_1.id, data) except OSError: time.sleep(3) else: break if new_subs: assert new_subs[0].email == mail groups.delete_subscriber(group_1.id, new_subs[0].id) with pytest.raises(ValueError): data = {'name': 'John', 'fields': {'company': 'MailerLite'}} groups.add_subscribers(group_1.id, data) with pytest.raises(ValueError): groups.add_subscribers(group_1.id, subscribers_data='hey!')
def test_groups_subscriber(header): groups = Groups(header) n_groups = groups.all() assert len(n_groups) > 0 group_1 = n_groups[0] subs_in_group_1 = groups.subscribers(group_1.id) assert len(subs_in_group_1) > 0 sub1 = subs_in_group_1[0] tmp_sub = groups.subscriber(group_1.id, sub1.id) assert sub1.email == tmp_sub.email while True: try: num = random.randint(1000, 100000) mail = generate_random_email(length=15, seed=num) data = {'name': 'John', 'email': mail, 'fields': {'company': 'MailerLite'} } new_subs = groups.add_subscribers(group_1.id, data) except OSError: time.sleep(3) else: break print(new_subs) if new_subs: assert new_subs[0].email == mail groups.delete_subscriber(group_1.id, new_subs[0].id)