def test_synchronize(self): existing_rows = [ fixtures.row(id=1), fixtures.row(id=2), fixtures.row(id=3) ] self.db_client.read.return_value = existing_rows self.asana_client.tasks.find_by_project.return_value = [ fixtures.task(id=2), fixtures.task(id=3), fixtures.task(id=4) ] project = Project(self.asana_client, self.db_client, self.workspace, self.config, [SimpleField("id", SqlType.INTEGER)]) project.synchronize() self.asana_client.tasks.find_by_project.assert_called_with(1234, fields="id") self.db_client.read.assert_called_with('SELECT id FROM "test_table";') self.db_client.write.assert_called_with( 'DELETE FROM "test_table" WHERE id = ?;', 1) self.db_client.write.assert_has_calls([ mock.call('INSERT OR REPLACE INTO "test_table" (id) VALUES (?);', 2), mock.call('INSERT OR REPLACE INTO "test_table" (id) VALUES (?);', 3), mock.call('INSERT OR REPLACE INTO "test_table" (id) VALUES (?);', 4) ])
def test_export(self): self.asana_client.tasks.find_by_project.return_value = [ fixtures.task(id=1), fixtures.task(id=2), fixtures.task(id=3) ] project = Project(self.asana_client, self.db_client, self.workspace, self.config, [SimpleField("id", SqlType.INTEGER)]) project.export() self.asana_client.tasks.find_by_project.assert_called_with(1234, fields="id") self.db_client.read.assert_not_called() self.db_client.write.assert_has_calls([ mock.call('INSERT OR REPLACE INTO "test_table" (id) VALUES (?);', 1), mock.call('INSERT OR REPLACE INTO "test_table" (id) VALUES (?);', 2), mock.call('INSERT OR REPLACE INTO "test_table" (id) VALUES (?);', 3) ])
def test_field_definition(self): simple_field = SimpleField("test", SqlType.INTEGER) self.assertEquals(simple_field.field_definition_sql(), '"test" INTEGER')
def test_get_data_from_task(self): task = {"test": 123} simple_field = SimpleField("test", SqlType.INTEGER) self.assertEquals(simple_field.get_data_from_task(task), 123)
def test_required_fields(self): simple_field = SimpleField("test", SqlType.INTEGER) self.assertSetEqual(simple_field.required_fields(), set(["test"]))
def NameField(): return SimpleField("name", SqlType.STRING)
def AssigneeStatus(): return SimpleField("assignee_status", SqlType.STRING)
def NumHearts(): return SimpleField("num_hearts", SqlType.INTEGER, default=0)
def DueOnField(): return SimpleField("due_on", SqlType.DATE)
def TaskIdPrimaryKeyField(): return SimpleField("id", SqlType.INTEGER, primary_key=True)
def CompletedAtField(): return SimpleField("completed_at", SqlType.DATETIME)
def CompletedField(): return SimpleField("completed", SqlType.BOOLEAN, default=False)
def ModifiedAtField(): return SimpleField("modified_at", SqlType.DATETIME)
def CreatedAtField(): return SimpleField("created_at", SqlType.DATETIME)
def NotesField(): return SimpleField("notes", SqlType.TEXT)
def test_primary_key(self): simple_field = SimpleField("test", SqlType.INTEGER, primary_key=True) self.assertEquals(simple_field.field_definition_sql(), '"test" INTEGER NOT NULL PRIMARY KEY')
def test_default_value(self): task = {} simple_field = SimpleField("test", SqlType.INTEGER, default=123) self.assertEquals(simple_field.get_data_from_task(task), 123)
def DueAtField(): return SimpleField("due_at", SqlType.DATETIME)