SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Kürzlich hochgeladen (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

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