SlideShare una empresa de Scribd logo
1 de 10
Descargar para leer sin conexión
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

Más contenido relacionado

Más de 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
 

Más de 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
 

Último

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

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