def test_add_result_twice(self): "adding a result set twice does updates" fixture = join(FIXTURE_DIR, "bp-post-to-elife.json") fixture = json.load(open(fixture, "r")) logic.add_result(fixture) self.assertEqual(logic.row_count(), 3) # 6 rows, 3 that are protocols self.assertEqual(models.ArticleProtocol.objects.count(), 6) logic.add_result(fixture) self.assertEqual(logic.row_count(), 3) self.assertEqual(models.ArticleProtocol.objects.count(), 6)
def test_add_result_item_twice(self): "adding a result item twice does an update" good_result = { "protocol_sequencing_number": "s4-3", "protocol_title": "Cell culture and transfection", "is_protocol": True, "protocol_status": 0, "uri": "https://en.bio-protocol.org/rap.aspx?eid=24419&item=s4-3", "msid": 12345, } logic.upsert(good_result) self.assertEqual(logic.row_count(), 1) logic.upsert(good_result) self.assertEqual(logic.row_count(), 1)
def test_add_result_bad_item(self): "a result with a bad item is not discarded entirely" fixture = join(FIXTURE_DIR, "bp-post-to-elife.json") result = json.load(open(fixture, "r")) del result["data"][0][ "URI"] # fails validation 'all keys must be present' logic.add_result(result) self.assertEqual(logic.row_count(), 3) # 5 rows, 3 that are protocols self.assertEqual(models.ArticleProtocol.objects.count(), 5)
def test_add_result(self): "an entire result from BP can be processed, validated and inserted" fixture = join(FIXTURE_DIR, "bp-post-to-elife.json") logic.add_result(json.load(open(fixture, "r"))) self.assertEqual(logic.row_count(), 3) # 6 rows, 3 that are protocols self.assertEqual(models.ArticleProtocol.objects.count(), 6)
def test_logic_row_count_non_zero(self): logic._add_result_item(self.fixture) self.assertEqual(logic.row_count(), 1)
def test_logic_row_count(self): self.assertEqual(logic.row_count(), 0)