SlideShare a Scribd company logo
1 of 10
Download to read offline
Fixtures and Fittings...


mark@ekivemark.com                          @ekivemark
        A Newbie voyage in to Django UnitTesting




                                             @ekivemark
New to Django
import django.experts
AUDIENCE = “Technical”

if not(developer)==True
and techie(dangerous):
    bad_idea = give_talk(AUDIENCE)
Why Fixtures?
fixtures =   ['apps/services/fixtures/services_testdata.json',
             #'apps/accounts/fixtures/accounts_test_data.json',
              'apps/coupons/fixtures/accounts_test_data.json',
              'apps/intake/fixtures/intake_inprocess.json']




      • Compare screen data entry to UnitTest
      • Testing pagination
      • Testing Search
                                                     @ekivemark
Make it readable
python manage.py dumpdata accounts --indent=4 >./apps/accounts/
fixtures/testdata.json



[
    {
        "pk": 1,
        "model": "accounts.userprofile",
        "fields": {
            "mobile_phone_number": "7036232789",
            "vid": "820912028666724",
            "pin": 4829,
            "gender": "",
            "fax_number": "",
            "anonymous_patient_id": "76766c7d-25eb-4118-9a4c-b939c80929ce",
            "user": 2,
            "secondary_insurance_or_payer": "",
            "organization": "",
            "primary_insurance_or_payer": ""
        }
    }

]




                                                                              @ekivemark
Localize variables
  • settings_test.py
            a bunch of frequently used test variables
__author__ = 'mark @ekivemark'
"""
Unit Test Framework Standard Variables used across modules

Add
{from ..test.settings_test import * }
to top of {app name}/tests.py in order to be able to use variables without the
{settings_test.} prefix

This avoids setting variable values in multiple locations.
"""

# Edit this number to your cellphone number for testing purposes.
TESTER_CELL_NUMBER = "9999999999"

# User full name = Harvey Ive
USERNAME_FOR_TEST='mark'
PASSWORD_FOR_TEST='123456789'
EMAIL_FOR_TEST="spam1@nospam.org"

SMSCODE_FOR_TEST='9999'

VALID_LASTNAME="First"
VALID_FIRSTNAME="Arthur"


                                                                                 @ekivemark
USERNAME_NOT_TEST='nottester'
PASSWORD_NOT_TEST='password'

SMSCODE_NOT_TEST='9999'
Build a DRY toolset
        • Printing results to the screen
def Test_Start(message=""):
    print "_______________________________________________"
    caller = inspect.getframeinfo(inspect.currentframe().f_back)[2]
    print "Test Harness:" +
inspect.getframeinfo(inspect.currentframe().f_back)[0]
    print term_color.OKGREEN + "Entering:" + caller +
term_color.ENDC
    if message != "":
        print "Notes:"+message
    print "------------------------------------------------"
    return



   Highlighting helps
   when quickly
   scanning output                                                    @ekivemark
Time and Date stamp
                      your tests
# @unittest.skip
class Accounts_Simple_TestCase(TestCase):
    """Background to this test harness
       and prove the test harness works
    """

   # Add your fixtures here
   # fixtures = ['testdata.json']

   def test_basic_addition_Accounts(self):
       """
       Tests that 1 + 1 always equals 2.
       """
       Test_Start("1+1=2")
       answer = self.assertEqual(1 + 1, 2)
       Test_Msg("RESTCat.apps.accounts.tests.py")
       print "     Test Runtime: "+str(datetime.now())
       if answer == None:
           print "     Test Harness ready"
       else:
           print "     This Test Harness has a problem"
       Test_End("RESTCat.apps.accounts.tests.py")

       return

                                                          @ekivemark
User permissions
def check_permission(usr_name="",showprint=False):
    """
    View permissions for a user profile
    """
    if usr_name=="":def give_permission(usr_name="",permit_this="",showprint=False):
        usr_key = 1     """
    else:               Add a permission to a user
        try:            """
            usr_key = User.objects.get(username=usr_name)
        except:         if usr_name=="":     def remove_permission(usr_name="",not_permitted="",showprint=False):
            usr_key = 1     if showprint!=False: """
                                                 remove a permission from a user
                                print "No permission added"
    usr_permission = Permission.objects.filter(user=usr_key)
                            result = ""          """
                        else:
    if showprint!=False:                         if usr_name=="":
                            usr_key = User.objects.get(username=usr_name)
        print "User:" + usr_name
                            if showprint!=False:     if showprint!=False:
        print "key:" + str(usr_key) "got usr_key"
                                print                    print not_permitted+" permission not revoked"
        print "Permissions:"    print usr_key        result = ""
        print usr_permission                     else:
                                print "Now add permission:["+permit_this+"]"
                                                     usr_key = User.objects.get(username=usr_name)
                                                     if showprint!=False:
                            new_permission = Permission(user=usr_key, permission_name=permit_this)
    return usr_permission new_permission.save()          print "revoking ["+not_permitted+"] for "+usr_key
                            result = new_permission
                                                     kill_permission = Permission.objects.filter(user=usr_key,
                        return result        permission_name=not_permitted)
                                                     if showprint!=False:
                                                         print kill_permission

                                                    kill_permission.delete()
                                                    result = "revoked ["+not_permitted+"] for "+str(usr_key)

                                                return result

                                                                                        @ekivemark
?
mark@ekivemark.com       @ekivemark




                         @ekivemark

More Related Content

More from Mark Scrimshire

The Power of Consumer Directed Health Data
The Power of Consumer Directed Health DataThe Power of Consumer Directed Health Data
The Power of Consumer Directed Health DataMark Scrimshire
 
The Power of Beneficiary-Directed Data (CMS BlueButton on FHIR API Update)
The Power of Beneficiary-Directed Data (CMS BlueButton on FHIR API Update)The Power of Beneficiary-Directed Data (CMS BlueButton on FHIR API Update)
The Power of Beneficiary-Directed Data (CMS BlueButton on FHIR API Update)Mark Scrimshire
 
BlueButton on FHIR at HIMSS'17 HL7 API Symposium
BlueButton on FHIR at HIMSS'17 HL7 API SymposiumBlueButton on FHIR at HIMSS'17 HL7 API Symposium
BlueButton on FHIR at HIMSS'17 HL7 API SymposiumMark Scrimshire
 
CMS BlueButton On FHIR - HIMSS17 Update
CMS BlueButton On FHIR - HIMSS17 UpdateCMS BlueButton On FHIR - HIMSS17 Update
CMS BlueButton On FHIR - HIMSS17 UpdateMark Scrimshire
 
CMS BlueButton on FHIR at Cinderblocks3
CMS BlueButton on FHIR at Cinderblocks3 CMS BlueButton on FHIR at Cinderblocks3
CMS BlueButton on FHIR at Cinderblocks3 Mark Scrimshire
 
BlueButton on FHIR - HxRefactored 2016
BlueButton on FHIR - HxRefactored 2016BlueButton on FHIR - HxRefactored 2016
BlueButton on FHIR - HxRefactored 2016Mark Scrimshire
 
Aneesh Chopra - HealthCa.mp/dev Keynote. 2016: the Year to participate in the...
Aneesh Chopra - HealthCa.mp/dev Keynote. 2016: the Year to participate in the...Aneesh Chopra - HealthCa.mp/dev Keynote. 2016: the Year to participate in the...
Aneesh Chopra - HealthCa.mp/dev Keynote. 2016: the Year to participate in the...Mark Scrimshire
 
Entrepreneur attitude or job title?
Entrepreneur attitude or job title?Entrepreneur attitude or job title?
Entrepreneur attitude or job title?Mark Scrimshire
 
CMS BlueButton On FHIR for Researchers - Presentation to NIH and PCORI Resear...
CMS BlueButton On FHIR for Researchers - Presentation to NIH and PCORI Resear...CMS BlueButton On FHIR for Researchers - Presentation to NIH and PCORI Resear...
CMS BlueButton On FHIR for Researchers - Presentation to NIH and PCORI Resear...Mark Scrimshire
 
BlueButton On FHIR Presentation to Attachments Work Group at HL7 Meeting Jan ...
BlueButton On FHIR Presentation to Attachments Work Group at HL7 Meeting Jan ...BlueButton On FHIR Presentation to Attachments Work Group at HL7 Meeting Jan ...
BlueButton On FHIR Presentation to Attachments Work Group at HL7 Meeting Jan ...Mark Scrimshire
 
Tap Your Passion for Opportunity
Tap Your Passion for OpportunityTap Your Passion for Opportunity
Tap Your Passion for OpportunityMark Scrimshire
 
BlueButtonOnFHIR - Payer Briefing
BlueButtonOnFHIR - Payer BriefingBlueButtonOnFHIR - Payer Briefing
BlueButtonOnFHIR - Payer BriefingMark Scrimshire
 
A Baptism of FHIR - The Layman's intro to HL7 FHIR
A Baptism of FHIR - The Layman's intro to HL7 FHIRA Baptism of FHIR - The Layman's intro to HL7 FHIR
A Baptism of FHIR - The Layman's intro to HL7 FHIRMark Scrimshire
 
BlueButton and MyHealth at Connected Health 2015 in San Diego
BlueButton and MyHealth at Connected Health 2015 in San DiegoBlueButton and MyHealth at Connected Health 2015 in San Diego
BlueButton and MyHealth at Connected Health 2015 in San DiegoMark Scrimshire
 
The Patient at the Center of a New Healthcare System - All About You at #Cind...
The Patient at the Center of a New Healthcare System - All About You at #Cind...The Patient at the Center of a New Healthcare System - All About You at #Cind...
The Patient at the Center of a New Healthcare System - All About You at #Cind...Mark Scrimshire
 
HealthCare Heal Thyself - The Patient as the hub of a new health system
HealthCare Heal Thyself - The Patient as the hub of a new health systemHealthCare Heal Thyself - The Patient as the hub of a new health system
HealthCare Heal Thyself - The Patient as the hub of a new health systemMark Scrimshire
 
BlueButton on FHIR @HXRconf
BlueButton on FHIR @HXRconf BlueButton on FHIR @HXRconf
BlueButton on FHIR @HXRconf Mark Scrimshire
 
Mongodb and the Health Care Challenge
Mongodb and the Health Care ChallengeMongodb and the Health Care Challenge
Mongodb and the Health Care ChallengeMark Scrimshire
 

More from Mark Scrimshire (20)

The Power of Consumer Directed Health Data
The Power of Consumer Directed Health DataThe Power of Consumer Directed Health Data
The Power of Consumer Directed Health Data
 
The Power of Beneficiary-Directed Data (CMS BlueButton on FHIR API Update)
The Power of Beneficiary-Directed Data (CMS BlueButton on FHIR API Update)The Power of Beneficiary-Directed Data (CMS BlueButton on FHIR API Update)
The Power of Beneficiary-Directed Data (CMS BlueButton on FHIR API Update)
 
BlueButton on FHIR at HIMSS'17 HL7 API Symposium
BlueButton on FHIR at HIMSS'17 HL7 API SymposiumBlueButton on FHIR at HIMSS'17 HL7 API Symposium
BlueButton on FHIR at HIMSS'17 HL7 API Symposium
 
CMS BlueButton On FHIR - HIMSS17 Update
CMS BlueButton On FHIR - HIMSS17 UpdateCMS BlueButton On FHIR - HIMSS17 Update
CMS BlueButton On FHIR - HIMSS17 Update
 
CMS BlueButton on FHIR at Cinderblocks3
CMS BlueButton on FHIR at Cinderblocks3 CMS BlueButton on FHIR at Cinderblocks3
CMS BlueButton on FHIR at Cinderblocks3
 
BlueButton on FHIR - HxRefactored 2016
BlueButton on FHIR - HxRefactored 2016BlueButton on FHIR - HxRefactored 2016
BlueButton on FHIR - HxRefactored 2016
 
Aneesh Chopra - HealthCa.mp/dev Keynote. 2016: the Year to participate in the...
Aneesh Chopra - HealthCa.mp/dev Keynote. 2016: the Year to participate in the...Aneesh Chopra - HealthCa.mp/dev Keynote. 2016: the Year to participate in the...
Aneesh Chopra - HealthCa.mp/dev Keynote. 2016: the Year to participate in the...
 
Entrepreneur attitude or job title?
Entrepreneur attitude or job title?Entrepreneur attitude or job title?
Entrepreneur attitude or job title?
 
CMS BlueButton On FHIR for Researchers - Presentation to NIH and PCORI Resear...
CMS BlueButton On FHIR for Researchers - Presentation to NIH and PCORI Resear...CMS BlueButton On FHIR for Researchers - Presentation to NIH and PCORI Resear...
CMS BlueButton On FHIR for Researchers - Presentation to NIH and PCORI Resear...
 
BlueButton On FHIR Presentation to Attachments Work Group at HL7 Meeting Jan ...
BlueButton On FHIR Presentation to Attachments Work Group at HL7 Meeting Jan ...BlueButton On FHIR Presentation to Attachments Work Group at HL7 Meeting Jan ...
BlueButton On FHIR Presentation to Attachments Work Group at HL7 Meeting Jan ...
 
Tap Your Passion for Opportunity
Tap Your Passion for OpportunityTap Your Passion for Opportunity
Tap Your Passion for Opportunity
 
BlueButtonOnFHIR - Payer Briefing
BlueButtonOnFHIR - Payer BriefingBlueButtonOnFHIR - Payer Briefing
BlueButtonOnFHIR - Payer Briefing
 
B bon fhir_workshop
B bon fhir_workshopB bon fhir_workshop
B bon fhir_workshop
 
A Baptism of FHIR - The Layman's intro to HL7 FHIR
A Baptism of FHIR - The Layman's intro to HL7 FHIRA Baptism of FHIR - The Layman's intro to HL7 FHIR
A Baptism of FHIR - The Layman's intro to HL7 FHIR
 
Health2 stat 2015-08-20
Health2 stat 2015-08-20Health2 stat 2015-08-20
Health2 stat 2015-08-20
 
BlueButton and MyHealth at Connected Health 2015 in San Diego
BlueButton and MyHealth at Connected Health 2015 in San DiegoBlueButton and MyHealth at Connected Health 2015 in San Diego
BlueButton and MyHealth at Connected Health 2015 in San Diego
 
The Patient at the Center of a New Healthcare System - All About You at #Cind...
The Patient at the Center of a New Healthcare System - All About You at #Cind...The Patient at the Center of a New Healthcare System - All About You at #Cind...
The Patient at the Center of a New Healthcare System - All About You at #Cind...
 
HealthCare Heal Thyself - The Patient as the hub of a new health system
HealthCare Heal Thyself - The Patient as the hub of a new health systemHealthCare Heal Thyself - The Patient as the hub of a new health system
HealthCare Heal Thyself - The Patient as the hub of a new health system
 
BlueButton on FHIR @HXRconf
BlueButton on FHIR @HXRconf BlueButton on FHIR @HXRconf
BlueButton on FHIR @HXRconf
 
Mongodb and the Health Care Challenge
Mongodb and the Health Care ChallengeMongodb and the Health Care Challenge
Mongodb and the Health Care Challenge
 

Recently uploaded

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Django/Python Unit Testing talk for Django District

  • 1. Fixtures and Fittings... mark@ekivemark.com @ekivemark A Newbie voyage in to Django UnitTesting @ekivemark
  • 3. import django.experts AUDIENCE = “Technical” if not(developer)==True and techie(dangerous): bad_idea = give_talk(AUDIENCE)
  • 4. Why Fixtures? fixtures = ['apps/services/fixtures/services_testdata.json', #'apps/accounts/fixtures/accounts_test_data.json', 'apps/coupons/fixtures/accounts_test_data.json', 'apps/intake/fixtures/intake_inprocess.json'] • Compare screen data entry to UnitTest • Testing pagination • Testing Search @ekivemark
  • 5. Make it readable python manage.py dumpdata accounts --indent=4 >./apps/accounts/ fixtures/testdata.json [ { "pk": 1, "model": "accounts.userprofile", "fields": { "mobile_phone_number": "7036232789", "vid": "820912028666724", "pin": 4829, "gender": "", "fax_number": "", "anonymous_patient_id": "76766c7d-25eb-4118-9a4c-b939c80929ce", "user": 2, "secondary_insurance_or_payer": "", "organization": "", "primary_insurance_or_payer": "" } } ] @ekivemark
  • 6. Localize variables • settings_test.py a bunch of frequently used test variables __author__ = 'mark @ekivemark' """ Unit Test Framework Standard Variables used across modules Add {from ..test.settings_test import * } to top of {app name}/tests.py in order to be able to use variables without the {settings_test.} prefix This avoids setting variable values in multiple locations. """ # Edit this number to your cellphone number for testing purposes. TESTER_CELL_NUMBER = "9999999999" # User full name = Harvey Ive USERNAME_FOR_TEST='mark' PASSWORD_FOR_TEST='123456789' EMAIL_FOR_TEST="spam1@nospam.org" SMSCODE_FOR_TEST='9999' VALID_LASTNAME="First" VALID_FIRSTNAME="Arthur" @ekivemark USERNAME_NOT_TEST='nottester' PASSWORD_NOT_TEST='password' SMSCODE_NOT_TEST='9999'
  • 7. Build a DRY toolset • Printing results to the screen def Test_Start(message=""): print "_______________________________________________" caller = inspect.getframeinfo(inspect.currentframe().f_back)[2] print "Test Harness:" + inspect.getframeinfo(inspect.currentframe().f_back)[0] print term_color.OKGREEN + "Entering:" + caller + term_color.ENDC if message != "": print "Notes:"+message print "------------------------------------------------" return Highlighting helps when quickly scanning output @ekivemark
  • 8. Time and Date stamp your tests # @unittest.skip class Accounts_Simple_TestCase(TestCase): """Background to this test harness and prove the test harness works """ # Add your fixtures here # fixtures = ['testdata.json'] def test_basic_addition_Accounts(self): """ Tests that 1 + 1 always equals 2. """ Test_Start("1+1=2") answer = self.assertEqual(1 + 1, 2) Test_Msg("RESTCat.apps.accounts.tests.py") print " Test Runtime: "+str(datetime.now()) if answer == None: print " Test Harness ready" else: print " This Test Harness has a problem" Test_End("RESTCat.apps.accounts.tests.py") return @ekivemark
  • 9. User permissions def check_permission(usr_name="",showprint=False): """ View permissions for a user profile """ if usr_name=="":def give_permission(usr_name="",permit_this="",showprint=False): usr_key = 1 """ else: Add a permission to a user try: """ usr_key = User.objects.get(username=usr_name) except: if usr_name=="": def remove_permission(usr_name="",not_permitted="",showprint=False): usr_key = 1 if showprint!=False: """ remove a permission from a user print "No permission added" usr_permission = Permission.objects.filter(user=usr_key) result = "" """ else: if showprint!=False: if usr_name=="": usr_key = User.objects.get(username=usr_name) print "User:" + usr_name if showprint!=False: if showprint!=False: print "key:" + str(usr_key) "got usr_key" print print not_permitted+" permission not revoked" print "Permissions:" print usr_key result = "" print usr_permission else: print "Now add permission:["+permit_this+"]" usr_key = User.objects.get(username=usr_name) if showprint!=False: new_permission = Permission(user=usr_key, permission_name=permit_this) return usr_permission new_permission.save() print "revoking ["+not_permitted+"] for "+usr_key result = new_permission kill_permission = Permission.objects.filter(user=usr_key, return result permission_name=not_permitted) if showprint!=False: print kill_permission kill_permission.delete() result = "revoked ["+not_permitted+"] for "+str(usr_key) return result @ekivemark
  • 10. ? mark@ekivemark.com @ekivemark @ekivemark