def test_incorrect_host_url_sets_error_data(self):
        mock_data = "mock_incorrect_url"
        mock_curate_data_structure_id = ObjectId()
        mock_user = create_mock_user("1")

        self.module._init_prefix_and_record(mock_data,
                                            mock_curate_data_structure_id,
                                            mock_user)

        self.assertEquals(self.module.error_data, mock_data)
    def test_settings_host_url_not_equals_to_record_host_url_sets_error_data(
            self):
        mock_data = str(MockPID(provider="mock_not_default_provider"))
        mock_curate_data_structure_id = ObjectId()
        mock_user = create_mock_user("1")

        self.module._init_prefix_and_record(mock_data,
                                            mock_curate_data_structure_id,
                                            mock_user)
        self.assertIsNotNone(self.module.error_data)
    def test_incorrect_host_url_sets_value_to_none(self):
        mock_data = "mock_incorrect_url"
        mock_curate_data_structure_id = ObjectId()
        mock_user = create_mock_user("1")

        self.module._init_prefix_and_record(mock_data,
                                            mock_curate_data_structure_id,
                                            mock_user)

        self.assertIsNone(self.module.default_value)
Example #4
0
def test_get_experiment(client):
    experiment = new_experiment()
    response = client.get('/api/experiments/%s' % experiment.id)
    assert response.status_code == 200
    assert response.json['doi'] == experiment.doi

    # test bad experiment ID
    response = client.get('/api/experiments/%s' % ObjectId())
    assert response.status_code == 404
    experiment.delete()
def test_get_sample(client, experiment):
    sample = new_sample(experiment.id)
    response = client.get('/api/samples/%s' % sample.id)
    assert response.status_code == 200
    assert response.json['session'] == sample.session
    assert response.json['position'] == sample.position

    # test bad sample ID
    response = client.get('/api/samples/%s' % ObjectId())
    assert response.status_code == 404
    sample.delete()
    def test_settings_host_url_does_not_end_with_slash(self):
        mock_data = str(MockPID())
        mock_data = "%s/" % mock_data if mock_data[-1] != "/" else mock_data

        mock_curate_data_structure_id = ObjectId()
        mock_user = create_mock_user("1")

        self.module._init_prefix_and_record(mock_data,
                                            mock_curate_data_structure_id,
                                            mock_user)
        self.assertEquals(self.module.error_data, mock_data)
    def test_correct_url_sets_correct_value(self,
                                            mock_curate_data_structure_api):
        mock_curate_data_structure_api.return_value = None
        mock_data = MockPID()
        mock_curate_data_structure_id = ObjectId()
        mock_user = create_mock_user("1")

        self.module._init_prefix_and_record(str(mock_data),
                                            mock_curate_data_structure_id,
                                            mock_user)
        self.assertEquals(self.module.default_value, mock_data.value)
Example #8
0
    def test_find_one(self, server_name, port, test_data):
        client = mongomock.MongoClient(server_name, port)

        doc = insert_one(client, test_data)
        assert find_one(client, test_data)["_id"] == doc.inserted_id

        test_data.update({"_id": ObjectId(doc.inserted_id)})
        assert find_one(client, test_data) == test_data
        assert find_one(client, {"_id": doc.inserted_id}) == test_data
        assert find_one(client, {"_id": str(doc.inserted_id)}) is None
        assert find_one(client, {"name": test_data["name"]}) == test_data
Example #9
0
def test_get_training_data(client):
    training_data = new_training_data()
    response = client.get('/api/training/%s' % training_data.id)
    assert response.status_code == 200
    assert response.json[
        'cloud_storage_loc'] == training_data.cloud_storage_loc

    # test bad training_data ID
    response = client.get('/api/training/%s' % ObjectId())
    assert response.status_code == 404
    training_data.delete()
Example #10
0
def test_update_experiment(client):
    experiment = new_experiment()
    new_doi = 'a different DOI value'
    payload = {'doi': new_doi}
    response = client.put('/api/experiments/%s' % experiment.id, json=payload)
    assert response.status_code == 204
    updated = models.Experiments.objects.get(id=experiment.id)
    assert updated.doi == new_doi

    # test bad experiment ID
    response = client.put('/api/experiments/%s' % ObjectId(), json=payload)
    assert response.status_code == 404
    experiment.delete()
Example #11
0
def test_update_sample(client, experiment):
    sample = new_sample(experiment.id)
    new_session = random.randint(1, 1000)
    payload = {'session': new_session}
    response = client.put('/api/samples/%s' % sample.id, json=payload)
    assert response.status_code == 204
    updated = models.Samples.objects.get(id=sample.id)
    assert updated.session == new_session

    # test bad sample ID
    response = client.put('/api/samples/%s' % ObjectId(), json=payload)
    assert response.status_code == 404
    sample.delete()
Example #12
0
    def test_get_or_create_edge(self):
        src_id = ObjectId()
        dst_id = ObjectId()

        test_edge1 = EdgeService.get_or_create_edge(src_id, dst_id,
                                                    "Mock label 1",
                                                    "Mock label 2")
        assert test_edge1.src_node_id == src_id
        assert test_edge1.dst_node_id == dst_id
        assert not test_edge1.exploited
        assert not test_edge1.tunnel
        assert test_edge1.scans == []
        assert test_edge1.exploits == []
        assert test_edge1.src_label == "Mock label 1"
        assert test_edge1.dst_label == "Mock label 2"
        assert test_edge1.group is None
        assert test_edge1.domain_name is None
        assert test_edge1.ip_address is None

        EdgeService.get_or_create_edge(src_id, dst_id, "Mock label 1",
                                       "Mock label 2")
        assert len(Edge.objects()) == 1
    def setUp(self) -> None:
        if "core_linked_records_app" not in test_settings.INSTALLED_APPS:
            test_settings.INSTALLED_APPS.append("core_linked_records_app")

        patch_provider_manager = patch(
            "core_linked_records_app.utils.providers.ProviderManager.get",
            return_value=MockProvider(),
        )
        patch_provider_manager.start()
        self.addCleanup(patch_provider_manager.stop)

        self.module = LocalIdRegistryModule()

        self.request = Mock()
        self.request.method = "POST"
        self.request.POST = {"module_id": ObjectId()}
        self.request.build_absolute_uri = lambda char: ""
Example #14
0
def init(db, gridfs):
    staff1 = {
        "_id":
        ObjectId(),
        "name":
        "Peggy Gibson",
        "title":
        "The Boss",
        "bio":
        "Peggy Gibson is a weird name but I got it from a random name generator, don't judge me. Peggy is the boss for this example and I need to write a bunch of words here because bios are supposed to be sorta long. Like a few sentences or so. Though it doesn't really matter I guess.",
        "picture":
        gridfs.put(get_image_bytes("howard.png"), content_type="image/png"),
        "email":
        "*****@*****.**",
        "phone":
        "555-555-5555",
        "active":
        True,
        "order":
        0
    }

    staff2 = {
        "_id": ObjectId(),
        "name": "Josh Arnold",
        "title": "Vice Boss",
        "bio":
        "Josh Arnold is a weird name but I got it from a random name generator, don't judge me. Josh is the vice boss for this example, and has no picture.",
        "picture": None,
        "email": "*****@*****.**",
        "phone": "555-555-5555",
        "active": True,
        "order": 1
    }

    staff3 = {
        "_id":
        ObjectId(),
        "name":
        "Erik Maxwell",
        "title":
        "Regular Employee",
        "bio":
        "Another random name. Erik's a regular employee so I decided not to give him a phone number, since he's not important enough to get a phone. He's also Peggy's twin.",
        "picture":
        gridfs.put(get_image_bytes("howard.png"), content_type="image/png"),
        "email":
        None,
        "phone":
        None,
        "active":
        True,
        "order":
        2
    }

    staff_inactive = {
        "_id":
        ObjectId(),
        "name":
        "Victoria Lamb",
        "title":
        "Regular Employee",
        "bio":
        "This randomly named person isn't active, and you shouldn't be able to read this. Unless you've made it active, in which case you should. Or if you're in the back-end doing tests or something.",
        "picture":
        gridfs.put(get_image_bytes("howard.png"), content_type="image/png"),
        "email":
        None,
        "phone":
        None,
        "active":
        False,
        "order":
        1
    }

    staff = [staff1, staff2, staff3, staff_inactive]

    ex.add(staff1=staff1,
           staff2=staff2,
           staff3=staff3,
           staff_inactive=staff_inactive)

    db.staff.insert_many(staff)
Example #15
0
def an_object_id():
    return ObjectId()
Example #16
0
 def test__equal_with_same_id(self):
     obj1 = ObjectId()
     obj2 = ObjectId(str(obj1))
     self.assertEqual(obj1, obj2)
Example #17
0
def add_blood_test_for_yesterday(client, mongo):
    add_patient_over_12(client, "Pam", "Beesly")
    patient = mongo.db.patients.find_one({'first_name': "Pam"})
    patient_id = patient['_id']
    mongo.db.blood_tests.insert_one(
        {"patient_id": ObjectId(patient_id), "due_date": datetime.now() - timedelta(days=1)})
Example #18
0
def add_blood_test_for_today(client, mongo):
    add_patient_over_12(client, "John", "Doe")
    patient = mongo.db.patients.find_one({'first_name': "John"})
    patient_id = patient['_id']
    mongo.db.blood_tests.insert_one({"patient_id": ObjectId(patient_id), "due_date": datetime.now()})
Example #19
0
 def get(self, user_id):
     print("hello")
     if not user_id:
         self.handle_get_users()
     else:
         self.handle_get_specific_user(ObjectId(user_id))
Example #20
0
 def test_get_artifacts_item_invalid(self, *args, **kwargs):
     id_to_find = ObjectId()
     with self.assertRaises(ArtifactsServiceError):
         self.artifactsService.find_by_id(PROJECT_ID, ITERATION_ID,
                                          id_to_find)
    def setDefaultTestData(as_string=False):
        mock_data = MockPID() if not as_string else str(MockPID())
        mock_curate_data_structure_id = ObjectId()
        mock_user = create_mock_user("1")

        return [mock_data, mock_curate_data_structure_id, mock_user]
Example #22
0
from mongomock import ObjectId
from pli import datetime_today
from datetime import timedelta


def day(dd):
    return datetime_today() - timedelta(days=dd)


_nq2_id = ObjectId()
_nq1_id = ObjectId()

nq1 = {
    "_id": _nq1_id,
    "question": "What does PLI stand for?",
    "choices": {
        "a": "Please Leave It",
        "b": "Pop Lock I",
        "c": "Peer Leadership Institute"
    },
    "answer": "c",
    # Only nq we have right now, so it loops onto itself
    "_id": _nq1_id,
    "next": _nq2_id,
    "prev": _nq2_id,
    "history": {
        "a": 5,
        "b": 60,
        "c": 0
    },
    "response_count": 65
Example #23
0
    def test_delete_artifacts_item_notfound(self, *args, **kwargs):

        rv = self.test_client.delete(ARTIFACT_URL_WITH_ID.format(
            PROJECT_ID, ITERATION_ID, str(ObjectId())),
                                     headers=self.headers)
        self.assertTrue(rv._status_code == 404)