def test_setsizes(self): """ Test that doors can be initialized and later changed to different heights/widths in different formats and that they are always Measurments """ size = "12ft-0/1in" door = classes.Door(size, size) ## Initial initialization test self.assertEqual(door.clearopening_height, 144) self.assertEqual(door.clearopening_width, 144) ## Iterative Tests for (height, width, nheight, nwidth) in [ (120, 120, 120, 120), ("14'", "14'", 168, 168), ("12ft", "12ft0", 144, 144), ("10ft1in", """9'11" """, 121, 119), ]: with self.subTest(door=door, height=height, width=width, nheight=nheight, nwidth=nwidth): newdoor = classes.Door(height, width) self.assertEqual(newdoor.clearopening_height, nheight) self.assertEqual(newdoor.clearopening_width, nwidth) self.assertIsInstance(newdoor.clearopening_height, measurement.Imperial) self.assertIsInstance(newdoor.clearopening_width, measurement.Imperial) door.clearopening_height = height door.clearopening_width = width self.assertEqual(door.clearopening_height, nheight) self.assertEqual(door.clearopening_width, nwidth) self.assertIsInstance(newdoor.clearopening_height, measurement.Imperial) self.assertIsInstance(newdoor.clearopening_width, measurement.Imperial)
def test_compare_curtain(self): """ Simple test for compare_curtain """ ## Curtain requires door (may change in future) d1, d2 = classes.Door(1.0, 1.0), classes.Door(1.0, 1.0) c1, c2 = classes.Curtain(d1), classes.Curtain(d2) self.assertEqual(methods.compare_curtain(c1, c2), []) bbar = classes.BottomBar(classes.Slat("2 1/2 INCH FLAT SLAT")) c1.append(bbar) self.assertEqual(methods.compare_curtain(c1, c2), [ Difference("Curtain", (1, Difference("Second BottomBar is None", (bbar, None)))), ]) c2.append(bbar) self.assertEqual(methods.compare_curtain(c1, c2), []) s1, s2 = classes.SlatSection(slat=2), classes.SlatSection(slat=3) c1.append(s1) c2.append(s2) self.assertEqual(methods.compare_curtain(c1, c2), [ Difference("Curtain", (2, [ Difference("SlatSection.increaseradius", (s1.increaseradius, s2.increaseradius)), Difference("SlatSection.slat", (s1.slat, s2.slat)) ])) ])
def generatetrialdoor(trial): """ Assembles a door based on test data and sets it as the "door" key of the test data """ door = classes.Door(clearopening_width=trial.get("width"), clearopening_height=trial.get('stopheight')) ## Old DadsDoor lumps Stop Size and Upset together, so we need to parse out the default Upset stopsize = float(trial.get('Upset')) - door.upset tracks = dadsmethods.create_tracks(door, stopsize=stopsize) curtainargs = { k: trial.get(k, None) for k in ['slattype', 'slatgauge', 'endlocktype', 'windlocks'] } #curtainargs = {k:v if v else None for k,v in curtainargs.items()} curtainargs['gauge'] = curtainargs.pop("slatgauge") curtainargs['endlocks'] = curtainargs.pop("endlocktype") curtain = dadsmethods.create_curtain(door, **curtainargs) bottombar = trial.get("bottombaredge") if trial.get("Safety Edge", None): bottombar = trial['Safety Edge'] elif trial.get("Astragal Weight", None): bottombar = "ASTRAGAL" curtain.bottombars()[0].edge = bottombar pipeargs = { k: trial.get(k, None) for k in ['pipewidth', 'shell', 'barrelrings'] } door.setpipe(**pipeargs) door.sethood() trial['door'] = door
def basic_torsion_door(width, height, slat=None, endlocks=None, bracketplates=None): """ Constructs a basic Torsion Spring Door from the provided information. width and height are required and are clear opening sizes. slat and endlocks defaults to the defaults for create_curtain, which is used to create the curtain. bracketplates is an optional size for the bracketplates. """ door = classes.Door(height, width) if bracketplates: door.bracketplatesize = bracketplates create_tracks(door) create_curtain(door, slattype=slat, endlocks=None) door.sethood() smallest = get_smallest_pipe(door) if smallest: pipe = door.setpipe(shell=constants.PIPESIZES[smallest]) else: pipe = door.setpipe( shell=constants.PIPESIZES[max(constants.PIPESIZES)]) pipe.width = pipecalculations.setpipewidth(door) return door
def to_doorinstance(doorobj): """ Converts a Django Door Model to a NewDadsDoor Door Instance (as well as all components) """ if not isinstance(doorobj, models.Door): raise ValueError("to_doorinstance only accepts a Door Model instance") doorinstance = classes.Door(**doorobj.to_kwargs()) hood = doorinstance.sethood() tracksobj = models.Tracks.objects.filter(door=doorobj.pk).first() tracks = doorinstance.settracks() if tracksobj: doorinstance.bracketplatesize = float( tracksobj.brackets.bracket_size ) if tracksobj.brackets.bracket_size else tracksobj.brackets.bracket_size if tracksobj.outer_angle_height: tracks.outer = tracksobj.outer_angle_height if tracksobj.inner_angle_height: tracks.inner = tracksobj.inner_angle_height if tracksobj.wall_angle_height: tracks.wall = tracksobj.wall_angle_height pipeobj = models.Pipe.objects.filter(door=doorobj.pk).first() if pipeobj: pipe = doorinstance.setpipe(**pipeobj.to_kwargs()) assembly = pipe.setassembly() springs = models.Spring.objects.filter(pipe=pipeobj.pk) castings = sorted( list( set(spring.casting for spring in springs if spring is not None))) for casting in castings: ## Instead of referencing spring_type to determine order, we're just going to sort the od spngs = sorted(springs.filter(casting=casting), key=lambda spring: spring.outer_diameter, reverse=True) spngs = [classes.Spring(**spring.to_kwargs()) for spring in spngs] socket = classes.Socket(*spngs) assembly.addsocket(socket) else: pipe = doorinstance.setpipe() assembly = pipe.setassembly() curtain = doorinstance.setcurtain() for slatobj in models.Slats.objects.filter(door=doorobj.pk): slats = classes.SlatSection(curtain=curtain, **slatobj.to_kwargs()) curtain.append(slats) bbarobj = models.BottomBar.objects.filter(door=doorobj.pk).first() if bbarobj: bbar = classes.BottomBar(**bbarobj.to_kwargs()) curtain.append(bbar) accessories = [] for accessorytype in models.ACCESSORYLIST: for accessory in accessorytype.objects.filter(door=doorobj.pk): o = {"kind": accessory.kind, "description": accessory.description} ## TODO: expand this accessories.append(o) doorinstance.accessories = accessories return doorinstance