def test_replace_objects_with_pointers(): e1 = Entity(title="e1", a=1, b=2) e2 = Entity(title="e2", a=2, b=3) e1['friend'] = e2 e1.replace_objects_with_pointers() assert e1['friend'] == e2.uuid, e1['friend']
def test_replace_pointers_with_objects(): p = Project() e1 = Entity(p, title="e1", a=1, b=2) e2 = Entity(p, title="e2", a=2, b=3) e1['friend'] = e2.uuid e1.replace_pointers_with_objects() assert e1['friend'] == e2, e1['friend']
def test_required_fields_1(self): """ When loading from yaml, verify we don't overwrite required fields. """ f = Entity(title='foo', description='fibityfoo') f2 = Entity.from_yaml_file(f.to_yaml_file('/tmp')) assert f2['description'] == 'fibityfoo', f2['description']
def test_matches_dict_7(self): """ Test allowed_types['components'] = [Entity] """ e = Entity(self.p, title='Clean cat box', creator='Matt', components=[Entity(self.p, title='bogus component')], tags=['boring', 'chore'], priority=self.important) assert e.matches_dict( components='bogus component') == e, 'OH NOES'
def test_self_destruct_1(): """ Delete an entity. """ p = Project() p.pathname = '/tmp' e1 = Entity(p, title="e1", a=1, b=2) file_written = e1.to_yaml_file(p.pathname) files_deleted = e1.self_destruct(p) assert files_deleted == [file_written] assert not os.path.exists(file_written)
def setUp(self): proj = Project(title='bogus') self.bar = Entity(proj, title='bar') self.e = Entity(proj, title='bogus entity') self.e.allowed_types = { 'foo': Entity, 'i': int, 'foolist': [Entity]}
def test_choose_many(self, m): a = Entity(title="aaa") b = Entity(title="bbb") c = Entity(title="ccc") m.return_value = "1 3" results = Entity.choose_many_from_already_instantiated() assert len(results) == 2
def setUp(self): self.p = Project(title="TestMatchesDict") self.important = Entity(self.p, title='Important!!!') Entity.allowed_types['priority'] = Entity Entity.allowed_types['components'] = [Entity] self.e = Entity(self.p, title='Clean cat box', creator='Matt', pscore=99, tags=['boring', 'chore'], priority=self.important)
def test_2(self): p = Project() est1 = Entity(p, title='4 days') est1_uuid = est1.uuid e1 = Entity(p, title='some task', estimate=est1) e1.replace_objects_with_pointers() est2 = Entity(p, title=est1.title, uuid=uuid.uuid4()) assert est2 is est1 assert est1_uuid != est2.uuid e2 = Entity(p, title='another task', estimate=est2) e2.replace_objects_with_pointers() assert e1['estimate'] != e2['estimate'], est2['estimate'] e1.replace_pointers_with_objects() e2.replace_pointers_with_objects() assert e1['estimate'] == e2['estimate'], est2['estimate']
class TestPicklingEntity(unittest.TestCase): """ Pickle an entity that refers to other entities. """ def setUp(self): self.p = Project() self.c = Entity(self.p, title="c") self.e = Entity(self.p, title="t", c=self.c) def tearDown(self): self.c.self_destruct(self.p) self.e.self_destruct(self.p) def test_pickle(self): s = pickle.dumps(self.e) assert self.e['c'] == self.c, self.e['c'] assert isinstance(self.c, Entity) assert isinstance(self.e['c'], Entity) def test_unpickle(self): assert isinstance(self.e['c'], Entity) assert self.e.project s = pickle.dumps(self.e) e = pickle.loads(s) assert id(e) != id(self.e) assert e.uuid == self.e.uuid assert isinstance(self.c, Entity) assert e['c'] == self.c, e['c'] assert isinstance(self.e['c'], Entity) e.summarized_view e.detailed_view assert e.update_modified_time == True
def test_self_destruct_2(): """ Delete an entity with activities and verify activities are gone too. """ p = Project() p.pathname = '/tmp' p.current_user = Person(p, title="matt") e1 = Entity(p, title="entity for test_self_destruct_2", a=1, b=2) file_written = e1.to_yaml_file(p.pathname) print("file_written is %s" % file_written) c = e1.comment(who_said_it="matt", title="blah", description="") comment_yaml_file = c.to_yaml_file(p.pathname) # Update an attribute (to generate an activity). e1.record_activity_on_changes = True e1['a'] = 11 assert e1.activities.length == 1, e1.activities.length a = e1.activities[0] activity_yaml_file = a.to_yaml_file(p.pathname) files_deleted = sorted(e1.self_destruct(p)) files_created = sorted( [file_written, comment_yaml_file, activity_yaml_file]) print("files_deleted is %s" % files_deleted) print("files_created is %s" % files_created) assert files_deleted == files_created assert not os.path.exists(file_written)
class TestPicklingProject(unittest.TestCase): def setUp(self): self.p = Project() self.c = Entity(self.p, title="c") self.e = Entity(self.p, title="t", c=self.c) def tearDown(self): self.c.self_destruct(self.p) self.e.self_destruct(self.p) if os.path.exists('/tmp/project.pickle'): os.remove('/tmp/project.pickle') def test_to_pickle1(self): self.assertRaises( ValueError, self.p.to_pickle) def test_to_pickle2(self): self.p.to_pickle('/tmp') assert os.path.exists('/tmp/project.pickle') def test_unpickle(self): assert not os.path.exists('/tmp/project.pickle') self.p.to_pickle('/tmp') assert os.path.exists('/tmp/project.pickle') new_p = Project.from_pickle('/tmp/project.pickle') assert self.p.length == new_p.length assert new_p.length for e in new_p: assert e.project
def test_5(self): self.mk_request('/Entity/by_title/c', '', 'text/plain', '200 OK', str(Entity.by_title('c')))
def setUp(self): self.p = Project() self.c = Entity(self.p, title="c") self.e = Entity(self.p, title="t", c=self.c)
class TestWhatTheyReallyMean(unittest.TestCase): def setUp(self): proj = Project(title='bogus') self.bar = Entity(proj, title='bar') self.e = Entity(proj, title='bogus entity') self.e.allowed_types = { 'foo': Entity, 'i': int, 'foolist': [Entity]} def test_1(self): """ Verify we don't alter entities. """ assert self.bar == self.e.what_they_really_mean('foo', self.bar) def test_2(self): """ Verify we don't alter look ups that we can't map to entities. """ assert 'sniz' == self.e.what_they_really_mean('baz', 'sniz') def test_3(self): """ Convert title of an entity to an entity. """ assert self.bar == \ self.e.what_they_really_mean('foo', self.bar.title) def test_5(self): """ Verify we type-cast when appropriate. """ assert 99 == self.e.what_they_really_mean('i', '99') def test_6(self): """ Convert a list of titles to a list of entities. """ assert [self.bar] == self.e.what_they_really_mean('foo', ['bar']) def test_7(self): """ Pass a list of entities through. """ temp = self.e.what_they_really_mean('foo', [self.bar]) assert [self.bar] == temp, \ 'got %s and wanted %s!' % (temp, [self.bar]) def test_list_of_entities_2(self): """ Verify I don't mess up a list of entities. """ temp = self.e.what_they_really_mean('foolist', [self.bar]) assert [self.bar] == temp, \ 'got %s and wanted %s!' % (temp, [self.bar]) def test_list_of_entities_3(self): """ Verify I convert a list of titles. """ temp = self.e.what_they_really_mean('foolist', [self.bar.title]) assert [self.bar] == temp, \ 'got %s and wanted %s!' % (temp, [self.bar]) def test_invalid_title(self): assert 'fizzle' == self.e.what_they_really_mean('foo', 'fizzle') def test_list_of_invalid_titles(self): temp = self.e.what_they_really_mean('foo', ['fizzle']) assert ['fizzle'] == temp, \ 'got %s, expected %s!' % (temp, ['fizzle']) def test_by_uuid_1(self): """ Convert a UUID into an entity. """ temp = self.e.what_they_really_mean('foo', self.bar.uuid) assert self.bar == temp, 'got %r, expected %s!' % (temp, self.bar) def test_list_of_uuids(self): """ Convert a list of UUIDs to a list of entities. """ temp = self.e.what_they_really_mean('foo', [self.bar.uuid]) assert [self.bar] == temp, \ 'got %r, expected %s!' % (temp, [self.bar]) def test_by_frag(self): """ Convert a UUID fragment into an entity. """ assert self.bar == \ self.e.what_they_really_mean('foo', self.bar.frag) def test_list_of_frags(self): """ Convert a list of fragments to a list of entities. """ assert [self.bar] == \ self.e.what_they_really_mean('foo', [self.bar.frag])
class TestMatchesDict(unittest.TestCase): def setUp(self): self.p = Project(title="TestMatchesDict") self.important = Entity(self.p, title='Important!!!') Entity.allowed_types['priority'] = Entity Entity.allowed_types['components'] = [Entity] self.e = Entity(self.p, title='Clean cat box', creator='Matt', pscore=99, tags=['boring', 'chore'], priority=self.important) def test_matches_dict_1(self): """ Verify matches_dict handles scalars and list comparisons. """ assert self.e.matches_dict(creator='Matt') == self.e assert self.e.matches_dict(creator='Nobody') == None assert self.e.matches_dict(tags=['boring', 'chore']) == self.e assert self.e.matches_dict(tags='boring') == self.e assert self.e.matches_dict(tags='chore') == self.e assert self.e.matches_dict(creator=['Matt']) == self.e assert self.e.matches_dict(creator=['Matt', 'Nobody']) == self.e assert self.e.matches_dict(pscore=99) == self.e assert self.e.matches_dict( creator=['Matt', 'Nobody'], tags=['fun']) == None assert self.e.matches_dict( creator=['Matt', 'Nobody'], tags=['fun', 'boring']) == self.e def test_order_independence_of_query(self): """ Test two attributes with lists as values. """ assert not self.e.matches_dict(creator=['Matt'], title=['DO NOT MATCH']) assert not self.e.matches_dict(creator=['DO NOT MATCH'], title=['Clean cat box']) def test_order_independence_of_subquery(self): """ Test two attributes with lists, and one of the lists has a title as an element. """ assert not self.e.matches_dict( priority=[self.important.title], # this one matches tags=['DOES NOT MATCH']) # but not this one. def test_matches_dict_2(self): """ Verify we can match entities by using their UUID """ assert self.e.matches_dict(priority=self.important) == self.e print("got %s" % self.e.matches_dict(priority=self.important.uuid)) assert self.e.matches_dict(priority=self.important.uuid) == self.e frag = self.important.frag assert self.e.matches_dict(priority=frag) == self.e def test_matches_dict_3(self): """ Verify we can match entities by using their title. """ assert 'priority' in self.e.allowed_types print("self.e['priority'] is %(priority)s" % self.e) assert self.e.matches_dict( priority=self.important.title) == self.e, \ "Lookup using title failed" def test_matches_dict_4(self): """ Verify we can match with lists of titles. """ print("self.e['priority'] is %(priority)s" % self.e) assert self.e.matches_dict( priority=[self.important.title]) == self.e, \ "Lookup using list of titles failed" def test_matches_dict_5(self): """ Verify we can match with lists of titles. """ print('priority is %(priority)s' % self.e) print('what they really meant: %s' % self.e.what_they_really_mean('priority', ['bogus'])) temp = self.e.matches_dict(priority=["bogus"]) assert temp is None, "temp (%s) should be None!" % temp def test_matches_dict_6(self): """ Verify we can match with lists of frags. """ print("self.e['priority'] is %(priority)s" % self.e) assert self.e.matches_dict( priority=[self.important.frag]) == self.e, \ "Lookup using list of frags failed" def test_matches_dict_7(self): """ Test allowed_types['components'] = [Entity] """ e = Entity(self.p, title='Clean cat box', creator='Matt', components=[Entity(self.p, title='bogus component')], tags=['boring', 'chore'], priority=self.important) assert e.matches_dict( components='bogus component') == e, 'OH NOES'
def test_no_project(): e = Entity(title="blah123") print(e.project) e.replace_pointers_with_objects()