How to use test_custom_field method in hypothesis

Best Python code snippet using hypothesis

test_customize_form.py

Source:test_customize_form.py Github

copy

Full Screen

1# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors2# MIT License. See license.txt3from __future__ import unicode_literals4import frappe, unittest, json5from frappe.test_runner import make_test_records_for_doctype6from frappe.core.doctype.doctype.doctype import InvalidFieldNameError7test_dependencies = ["Custom Field", "Property Setter"]8class TestCustomizeForm(unittest.TestCase):9 def insert_custom_field(self):10 frappe.delete_doc_if_exists("Custom Field", "User-test_custom_field")11 frappe.get_doc({12 "doctype": "Custom Field",13 "dt": "User",14 "label": "Test Custom Field",15 "description": "A Custom Field for Testing",16 "fieldtype": "Select",17 "in_list_view": 1,18 "options": "\nCustom 1\nCustom 2\nCustom 3",19 "default": "Custom 3",20 "insert_after": frappe.get_meta('User').fields[-1].fieldname21 }).insert()22 def setUp(self):23 self.insert_custom_field()24 frappe.db.commit()25 frappe.clear_cache(doctype="User")26 def tearDown(self):27 frappe.delete_doc("Custom Field", "User-test_custom_field")28 frappe.db.commit()29 frappe.clear_cache(doctype="User")30 def get_customize_form(self, doctype=None):31 d = frappe.get_doc("Customize Form")32 if doctype:33 d.doc_type = doctype34 d.run_method("fetch_to_customize")35 return d36 def test_fetch_to_customize(self):37 d = self.get_customize_form()38 self.assertEquals(d.doc_type, None)39 self.assertEquals(len(d.get("fields")), 0)40 d = self.get_customize_form("Event")41 self.assertEquals(d.doc_type, "Event")42 self.assertEquals(len(d.get("fields")), 28)43 d = self.get_customize_form("User")44 self.assertEquals(d.doc_type, "User")45 self.assertEquals(len(d.get("fields")), len(frappe.get_doc("DocType", d.doc_type).fields) + 1)46 self.assertEquals(d.get("fields")[-1].fieldname, "test_custom_field")47 self.assertEquals(d.get("fields", {"fieldname": "location"})[0].in_list_view, 1)48 return d49 def test_save_customization_property(self):50 d = self.get_customize_form("User")51 self.assertEquals(frappe.db.get_value("Property Setter",52 {"doc_type": "User", "property": "allow_copy"}, "value"), None)53 d.allow_copy = 154 d.run_method("save_customization")55 self.assertEquals(frappe.db.get_value("Property Setter",56 {"doc_type": "User", "property": "allow_copy"}, "value"), '1')57 d.allow_copy = 058 d.run_method("save_customization")59 self.assertEquals(frappe.db.get_value("Property Setter",60 {"doc_type": "User", "property": "allow_copy"}, "value"), None)61 def test_save_customization_field_property(self):62 d = self.get_customize_form("User")63 self.assertEquals(frappe.db.get_value("Property Setter",64 {"doc_type": "User", "property": "reqd", "field_name": "location"}, "value"), None)65 location_field = d.get("fields", {"fieldname": "location"})[0]66 location_field.reqd = 167 d.run_method("save_customization")68 self.assertEquals(frappe.db.get_value("Property Setter",69 {"doc_type": "User", "property": "reqd", "field_name": "location"}, "value"), '1')70 location_field = d.get("fields", {"fieldname": "location"})[0]71 location_field.reqd = 072 d.run_method("save_customization")73 self.assertEquals(frappe.db.get_value("Property Setter",74 {"doc_type": "User", "property": "reqd", "field_name": "location"}, "value"), None)75 def test_save_customization_custom_field_property(self):76 d = self.get_customize_form("User")77 self.assertEquals(frappe.db.get_value("Custom Field", "User-test_custom_field", "reqd"), 0)78 custom_field = d.get("fields", {"fieldname": "test_custom_field"})[0]79 custom_field.reqd = 180 d.run_method("save_customization")81 self.assertEquals(frappe.db.get_value("Custom Field", "User-test_custom_field", "reqd"), 1)82 custom_field = d.get("fields", {"is_custom_field": True})[0]83 custom_field.reqd = 084 d.run_method("save_customization")85 self.assertEquals(frappe.db.get_value("Custom Field", "User-test_custom_field", "reqd"), 0)86 def test_save_customization_new_field(self):87 d = self.get_customize_form("User")88 last_fieldname = d.fields[-1].fieldname89 d.append("fields", {90 "label": "Test Add Custom Field Via Customize Form",91 "fieldtype": "Data",92 "__islocal": 193 })94 d.run_method("save_customization")95 self.assertEquals(frappe.db.get_value("Custom Field",96 "User-test_add_custom_field_via_customize_form", "fieldtype"), "Data")97 self.assertEquals(frappe.db.get_value("Custom Field",98 "User-test_add_custom_field_via_customize_form", 'insert_after'), last_fieldname)99 frappe.delete_doc("Custom Field", "User-test_add_custom_field_via_customize_form")100 self.assertEquals(frappe.db.get_value("Custom Field",101 "User-test_add_custom_field_via_customize_form"), None)102 def test_save_customization_remove_field(self):103 d = self.get_customize_form("User")104 custom_field = d.get("fields", {"fieldname": "test_custom_field"})[0]105 d.get("fields").remove(custom_field)106 d.run_method("save_customization")107 self.assertEquals(frappe.db.get_value("Custom Field", custom_field.name), None)108 frappe.local.test_objects["Custom Field"] = []109 make_test_records_for_doctype("Custom Field")110 def test_reset_to_defaults(self):111 d = frappe.get_doc("Customize Form")112 d.doc_type = "User"113 d.run_method('reset_to_defaults')114 self.assertEquals(d.get("fields", {"fieldname": "location"})[0].in_list_view, 0)115 frappe.local.test_objects["Property Setter"] = []116 make_test_records_for_doctype("Property Setter")117 def test_set_allow_on_submit(self):118 d = self.get_customize_form("User")119 d.get("fields", {"fieldname": "first_name"})[0].allow_on_submit = 1120 d.get("fields", {"fieldname": "test_custom_field"})[0].allow_on_submit = 1121 d.run_method("save_customization")122 d = self.get_customize_form("User")123 # don't allow for standard fields124 self.assertEquals(d.get("fields", {"fieldname": "first_name"})[0].allow_on_submit or 0, 0)125 # allow for custom field126 self.assertEquals(d.get("fields", {"fieldname": "test_custom_field"})[0].allow_on_submit, 1)127 def test_title_field_pattern(self):128 d = self.get_customize_form("Web Form")129 df = d.get("fields", {"fieldname": "title"})[0]130 # invalid fieldname131 df.options = """{doc_type} - {introduction_test}"""132 self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization")133 # space in formatter134 df.options = """{doc_type} - {introduction text}"""135 self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization")136 # valid fieldname137 df.options = """{doc_type} - {introduction_text}"""138 d.run_method("save_customization")139 # valid fieldname with escaped curlies140 df.options = """{{ {doc_type} }} - {introduction_text}"""141 d.run_method("save_customization")142 # undo143 df.options = None...

Full Screen

Full Screen

test_subscribers.py

Source:test_subscribers.py Github

copy

Full Screen

1import os2from functools import partial3from operator import contains4from pytest import mark5pytestmark = mark.skipif(os.getenv('TEST_LIVE') != "True", reason="tests against a real, live Drip account")6def test_create_update_subscriber(live_client):7 check = live_client.session.get('https://api.getdrip.com/v2/5706364/subscribers/ross.hodapp+drip-python@drip.com').json()['subscribers'][0]8 assert 'custom_fields' in check9 assert 'test_custom_field' in check['custom_fields']10 assert check['custom_fields']['test_custom_field'] == 'init'11 response = live_client.create_or_update_subscriber('ross.hodapp+drip-python@drip.com', custom_fields={'test_custom_field': '1'})12 p_contains = partial(contains, response)13 assert type(response) == dict14 assert len(response) == 2115 assert all(map(p_contains, ['id', 'status', 'email', 'eu_consent', 'time_zone', 'utc_offset', 'visitor_uuid', 'custom_fields', 'tags',16 'ip_address', 'user_agent', 'original_referrer', 'landing_url', 'prospect', 'lead_score', 'lifetime_value',17 'created_at', 'href', 'user_id', 'base_lead_score', 'links']))18 confirm = live_client.session.get('https://api.getdrip.com/v2/5706364/subscribers/ross.hodapp+drip-python@drip.com').json()['subscribers'][0]19 assert 'custom_fields' in confirm20 assert 'test_custom_field' in confirm['custom_fields']21 assert confirm['custom_fields']['test_custom_field'] == '1'22 # cleanup23 live_client.session.post(24 'https://api.getdrip.com/v2/5706364/subscribers',25 json={'subscribers': [{'email': 'ross.hodapp+drip-python@drip.com', 'custom_fields': {'test_custom_field': 'init'}}]}26 )27 response = live_client.create_or_update_subscriber('ross.hodapp+drip-python@drip.com', option='option')28def test_subscribers(live_client):29 response = live_client.subscribers()30 assert type(response) == list31 assert len(response) == 132def test_subscriber(live_client):33 response = live_client.subscriber('ross.hodapp+drip-python@drip.com')34 p_contains = partial(contains, response)35 assert type(response) == dict36 assert len(response) == 2137 assert all(map(p_contains, ['id', 'status', 'email', 'eu_consent', 'time_zone', 'utc_offset', 'visitor_uuid', 'custom_fields', 'tags',38 'ip_address', 'user_agent', 'original_referrer', 'landing_url', 'prospect', 'lead_score', 'lifetime_value',39 'created_at', 'href', 'user_id', 'base_lead_score', 'links']))40 assert response['email'] == 'ross.hodapp+drip-python@drip.com'41@mark.skip(reason="no way of currently testing this without manual setup, since the API can't re-subscribe someone")42def test_unsubscribe(live_client):43 response = live_client.unsubscribe('ross.hodapp+unsubscribed@drip.com')44 assert type(response) == dict45@mark.skip(reason="no way of currently testing this without manual setup, since the API can't re-subscribe someone")46def test_unsubscribe_from_all(live_client):47 response = live_client.unsubscribe_from_all('ross.hodapp+unsubscribed@drip.com')48 assert type(response) == dict49@mark.skip(reason="no way of currently testing this without manual setup, since the API can't un-delete someone")50def test_delete_subscriber(live_client):51 response = live_client.delete_subscriber('ross.hodapp+delete@drip.com')52 assert type(response) == bool...

Full Screen

Full Screen

test_batches.py

Source:test_batches.py Github

copy

Full Screen

1import os2from time import sleep3from pytest import mark4pytestmark = mark.skipif(os.getenv('TEST_LIVE') != "True", reason="tests against a real, live Drip account")5def test_create_or_update_subscribers(live_client):6 check = live_client.session.get('https://api.getdrip.com/v2/5706364/subscribers/ross.hodapp+drip-python@drip.com').json()['subscribers'][0]7 assert 'custom_fields' in check8 assert 'test_custom_field' in check['custom_fields']9 assert check['custom_fields']['test_custom_field'] == 'init'10 response = live_client.create_or_update_subscribers(11 [12 {'email': 'ross.hodapp+drip-python@drip.com', 'custom_fields': {'test_custom_field': '1'}}13 ]14 )15 assert type(response) == bool16 assert response17 sleep(2) # (!)18 confirm = live_client.session.get('https://api.getdrip.com/v2/5706364/subscribers/ross.hodapp+drip-python@drip.com').json()['subscribers'][0]19 assert 'custom_fields' in confirm20 assert 'test_custom_field' in confirm['custom_fields']21 assert confirm['custom_fields']['test_custom_field'] == '1'22 # cleanup23 live_client.session.post(24 'https://api.getdrip.com/v2/5706364/subscribers',25 json={'subscribers': [{'email': 'ross.hodapp+drip-python@drip.com', 'custom_fields': {'test_custom_field': 'init'}}]}26 )27@mark.skip(reason="no way of currently testing this without manual setup, since the API can't re-subscribe someone")28def test_unsubscribe_subscribers(live_client):29 response = live_client.unsubscribe_subscribers(30 [31 {'email': 'ross.hodapp+drip-python@drip.com'}32 ]33 )34 assert type(response) == bool35 assert response36def test_track_events(live_client):37 response = live_client.track_events(38 [39 {'email': 'ross.hodapp+drip-python@drip.com', 'action': 'Test custom event', 'properties': {'a': 1}},40 {'email': 'ross.hodapp+drip-python@drip.com', 'action': 'Test custom event', 'properties': {'a': 2}}41 ]42 )43 assert type(response) == bool44 assert response45def test_orders(live_client):46 response = live_client.orders(47 [48 {49 'provider': 'drip-python',50 'email': 'ross.hodapp+drip-python@drip.com',51 'action': 'placed',52 'order_id': '1234'53 }54 ]55 )56 assert type(response) == bool...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful