Changeset 362

Show
Ignore:
Timestamp:
Sun Jan 6 02:41:50 2008
Author:
Brian
Message:

Improve merge of report columns. Add some more test cases.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • server/trunk/update/client/Run Server Tests.py

    r361 r362  
    424 424         row1 = {'ID': 3, 'AssignmentID': 1, 'Period': '2008-01-03', 'EffortHours': 3}  
    425 425         row2 = {'ID': 4, 'AssignmentID': 1, 'Period': '2008-01-04', 'EffortHours': 4,  
    426                   '__EffortHours': 5}  
      426                 '__zzStatus': 'deleted', '__EffortHours': 5}  
    426 426         row3 = {'ID': 6, 'AssignmentID': 1, 'Period': '2008-01-05', 'EffortHours': 6}  
    427 427         table = Data.Database[tname]  
     
    467 467     AddAssignment()  
    468 468     AddAssignmentDay()  
      469     change = {'Table': tname, 'ID':assigndayIDa, 'zzStatus': 'deleted'}  # should be changed by self  
      470     Data.Update(change)  
      471     change = {'Table': tname, 'ID':assigndayID3, 'zzStatus': 'deleted'}  # should be deleted by self  
      472     Data.Update(change)  
      473     change = {'Table': tname, 'ID':assigndayID4, 'zzStatus': 'deleted'}  # should be changed by second  
      474     Data.Update(change)  
      475  
    469 476     Data.SetUndo('Added Assignment info')  
    470 477     ShareMod.DoCall()  
     
    492 499     Result('')  # end of test  
    493 500  
      501  
      502     Test("Both users change the same field")  
      503     UseDB(copya)  
      504  
      505     print '---- Changed name in first database'  
      506     tname = 'Resource'  
      507     change = {'Table': tname, 'ID':1, 'Name': 'Alice', 'zzStatus': 'deleted'}  
      508     Data.Update(change)  
      509     Data.SetUndo('Changed name')  
      510     ShareMod.DoCall()  
      511  
      512     UseDB(copyb)  
      513  
      514     print '---- Adding assignment data to second database'  
      515     tname = 'Resource'  
      516     change = {'Table': tname, 'ID':1, 'Name': 'Bob'}  
      517     Data.Update(change)  
      518     Data.SetUndo('Changed name')  
      519     ShareMod.DoCall()  
      520  
      521     UseDB(copya)  
      522  
      523     ShareMod.DoCall()  # make sure we have all of the changes  
      524     print '---- Verifing results in first database'  
      525     tname = 'Resource'  
      526     print 'checking %s' % tname  
      527     table = Data.Database[tname]  
      528     row = Data.Database['Resource'][1]  
      529     expected_row = {'ID': 1, 'Name': 'Alice', 'zzStatus': 'deleted'}  
      530     compare_dicts(expected_row, row)  
      531  
      532     UseDB(copyb)  
      533  
      534     ShareMod.DoCall()  # make sure we have all of the changes  
      535     print '---- Verifing results in second database'  
      536     tname = 'Resource'  
      537     print 'checking %s' % tname  
      538     table = Data.Database[tname]  
      539     row = Data.Database['Resource'][1]  
      540     expected_row = {'ID': 1, 'Name': 'Alice', '__Name': 'Bob', 'zzStatus': 'deleted'}  
      541     compare_dicts(expected_row, row)  
      542  
      543     Result('')  # end of test  
      544  
      545  
      546     Test("Both users add the same report type field")  
      547     UseDB(copya)  
      548  
      549     print '---- Add report type in first database'  
      550     rt = { 'Name': 'Widget', 'TableA': 'Widget', 'AllOrEach': 'both',  
      551             'SuggestedColumns': ',ID;,Name;,Date;,Color' }  
      552     ct = [  
      553     { 'Name': 'ID', 'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False  },  
      554     { 'Name': 'Name', 'Label': 'Name', 'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True, 'Width': 140 },  
      555     { 'Name': 'Date', 'Label': 'Date', 'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True, 'Width': 80 },  
      556     { 'Name': 'Color', 'Label': 'Owner', 'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True, 'Width': 140 },  
      557         ]  
      558     Data.AddReportType(rt, ct)  
      559     Data.SetUndo("Install Widget Tracking")  
      560     ShareMod.DoCall()  
      561  
      562     UseDB(copyb)  
      563  
      564     print '---- Adding assignment data to second database'  
      565     rt = { 'Name': 'Widget', 'TableA': 'Widget', 'AllOrEach': 'both',  
      566             'SuggestedColumns': ',ID;,Name;,Date;,Weight' }  
      567     ct = [  
      568     { 'Name': 'ID', 'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False  },  
      569     { 'Name': 'Name', 'Label': 'Name', 'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True, 'Width': 140 },  
      570     { 'Name': 'Date', 'Label': 'Date', 'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True, 'Width': 80 },  
      571     { 'Name': 'Weight', 'Label': 'Owner', 'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True, 'Width': 140 },  
      572         ]  
      573     Data.AddReportType(rt, ct)  
      574     Data.SetUndo("Install Widget Tracking")  
      575     ShareMod.DoCall()  
      576  
      577     UseDB(copya)  
      578  
      579     def VerifyReportType():  
      580         tname = 'ReportType'  
      581         print 'checking %s' % tname  
      582         table = Data.Database[tname]  
      583         results = Data.SearchByColumn(table, {'Name': 'Widget'})  
      584         compare_values('matching widget report type count', 1, len(results))  
      585         report_type_id = results.keys()[0]  
      586         tname = 'ColumnType'  
      587         print 'checking %s' % tname  
      588         table = Data.Database[tname]  
      589         results = Data.SearchByColumn(table, {'ReportTypeID': report_type_id})  
      590         compare_values('matching widget column type count', 5, len(results))  
      591  
      592     ShareMod.DoCall()  # make sure we have all of the changes  
      593     print '---- Verifing results in first database'  
      594     VerifyReportType()  
      595  
      596     UseDB(copyb)  
      597  
      598     ShareMod.DoCall()  # make sure we have all of the changes  
      599     print '---- Verifing results in second database'  
      600     VerifyReportType()  
      601  
      602     Result('')  # end of test  
      603  
      604  
      605     Test("Both users add a column to same report in same place")  
      606     UseDB(copya)  
      607  
      608     def AddColumn(colname):  
      609         table = Data.Database['ReportType']  
      610         results = Data.SearchByColumn(table, {'Name': 'Task'})  
      611         report_type_id = results.keys()[0]  
      612         table = Data.Database['ColumnType']  
      613         results = Data.SearchByColumn(table, {'Name': colname, 'ReportTypeID': report_type_id})  
      614         column_type_id = results.keys()[0]  
      615  
      616         report_row = Data.Database['Report'][4]  
      617         old_first_column = report_row['FirstColumn']  
      618         change = {'Table': 'ReportColumn', 'ReportID': 4, 'ColumnTypeID': column_type_id, 'NextColumn': old_first_column}  
      619         new_column_id = Data.Update(change)['ID']  
      620         change = {'Table': 'Report', 'ID': 4, 'FirstColumn': new_column_id}  
      621         Data.Update(change)  
      622  
      623     def VerifyColumns():  
      624         cols = Data.GetColumnList(4)  
      625         first_col = Data.Database['ReportColumn'][cols[0]]  
      626         first_name = Data.Database['ColumnType'][first_col['ColumnTypeID']]['Name']  
      627         compare_values('matching first column type name', 'Project/Name', first_name)  
      628  
      629         last_col = Data.Database['ReportColumn'][cols[-1]]  
      630         last_name = Data.Database['ColumnType'][last_col['ColumnTypeID']]['Name']  
      631         compare_values('matching last column type name', 'ID', last_name)  
      632  
      633     print '---- Add column in first database'  
      634     AddColumn('ID')  
      635     Data.SetUndo("Add Column")  
      636     ShareMod.DoCall()  
      637  
      638     UseDB(copyb)  
      639  
      640     print '---- Add column in second database'  
      641     AddColumn('Project/Name')  
      642     Data.SetUndo("Add Column")  
      643     ShareMod.DoCall()  
      644  
      645     UseDB(copya)  
      646  
      647  
      648     ShareMod.DoCall()  # make sure we have all of the changes  
      649     print '---- Verifing results in first database'  
      650     VerifyColumns()  
      651  
      652     UseDB(copyb)  
      653  
      654     ShareMod.DoCall()  # make sure we have all of the changes  
      655     print '---- Verifing results in second database'  
      656     VerifyColumns()  
      657  
      658     Result('')  # end of test  
      659  
      660     print "\n----\nOverall Results: passed %d tests out of %d\n----\n" % (pass_count, total_count)  
    494 661     return  
    495 662  
  • server/trunk/update/client/Share Changes with Server.py

    r361 r362  
    242 242             if t[dest].get(k) != v:  # should save varying values even if the old k doesn't exist  
    243 243                 t[dest]['__' + k] = v  # saving all changed prior values in the record??? - is this the right action??  
      244         if t[source].get('zzStatus') != 'deleted' and t[dest].get('zzStatus') == 'deleted':  
      245             change = {'Table': table, 'ID': dest, 'zzStatus': None}  
      246             Data.Update(change,0)  
    244 247         # completely clear out the duplicate  
    245 248         oldnextid = serverids.get('_' + table) or 0 # same format as database['NextID'] table  
     
    587 590         double underscore ever.  
    588 591     '''  
    589       for key, prior in report_save:  
      592     if debug: print '==== Fixing reports ===='  
      593     for key, prior in report_save.iteritems():  
      594         if debug: print 'key %s, prior %s' % (key, prior)  
    590 595         k, which = key  
    591 596         if which == 'column':  
    592 597             cols = Data.GetColumnList(k)  
    593 598             if prior != cols:  
      599                 if debug: print 'adjusting columns: prior %s, current %s' % (prior, cols)  
    594 600                 Data.ReorderReportColumns(k, prior + cols)  # precedence to local view  
    595 601         else:  
    596 602             rows = Data.GetRowList(k)  
    597 603             if prior != rows:  
      604                 if debug: print 'adjusting rows: prior %s, current %s' % (prior, rows)  
    598 605                 Data.ReorderReportRows(k, prior + rows)  
    599 606 #    Data.SetUndo('FixReports')  
     
    630 637     # server_prior_nextid = {} # set in AdjustIDs, used in FindChanges  
    631 638  
    632       save_reports = RememberReports()  
    633        
    634 639     def GetChangesFromServer():  
    635 640         """ Rows added by client need to be assigned new row numbers from the server.  
     
    708 713                 print changes  
    709 714             return 0  
      715          
      716         save_reports = RememberReports()  # must be after any local ids have been adjusted  
      717      
    710 718         # apply updates from server  
    711 719         ApplyChanges(server_changes)  
     
    726 734         # we might need to add report rows based on server data  
    727 735         # or resolve conflicts we and the server both changed the same report  
    728           #  (the server gets precedence - our changes are added at the end of the report)  
      736         #  (the server gets precedence - our changes are added at the end of the report) -- NO  
    728 736         Data.AdjustReportRows()  
    729 737  
     
    845 853  
    846 854 DoCall()  
      855 Menu.doSave('')  
    847 856 ##this script should save the database to disk  <- How to handle ERRORS???  
    848 857 ##try to adjust rowids